mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
parent
f6661989af
commit
b231550c32
12 changed files with 79 additions and 7 deletions
|
@ -379,6 +379,7 @@ Remark:
|
|||
|
||||
### History
|
||||
|
||||
* v3.0, 2016-12-15, fix #717, #691, http api/static/stream support cors. 3.0.9
|
||||
* v3.0, 2016-12-08, support log rotate signal SIGUSR1. 3.0.8
|
||||
* v3.0, 2016-12-07, fix typo and refine grammar. 3.0.7
|
||||
* v3.0, 2015-10-23, fix [#467][bug #467], support write log to kafka. 3.0.6
|
||||
|
|
2
trunk/.gitignore
vendored
2
trunk/.gitignore
vendored
|
@ -1,4 +1,4 @@
|
|||
console.conf
|
||||
console*.conf
|
||||
doc/frozen.2Mbps.1644x1028.flv
|
||||
doc/frozen.500Kbps.766x480.flv
|
||||
doc/kungfupanda3-tlr1_h1080p.200kbps.flv
|
||||
|
|
|
@ -178,6 +178,10 @@ http_server {
|
|||
# the default dir for http root.
|
||||
# default: ./objs/nginx/html
|
||||
dir ./objs/nginx/html;
|
||||
# whether enable crossdomain request.
|
||||
# for both http static and stream server and apply on all vhosts.
|
||||
# default: on
|
||||
crossdomain on;
|
||||
}
|
||||
|
||||
#############################################################################################
|
||||
|
|
|
@ -1704,6 +1704,17 @@ int SrsConfig::reload_http_stream(SrsConfDirective* old_root)
|
|||
}
|
||||
srs_trace("reload enabled modified http_stream success.");
|
||||
|
||||
if (!srs_directive_equals(old_http_stream->get("crossdomain"), new_http_stream->get("crossdomain"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_crossdomain()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream crossdomain modified failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
srs_trace("reload crossdomain modified http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -3570,7 +3581,7 @@ int SrsConfig::check_config()
|
|||
SrsConfDirective* conf = root->get("http_server");
|
||||
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
|
||||
string n = conf->at(i)->name;
|
||||
if (n != "enabled" && n != "listen" && n != "dir") {
|
||||
if (n != "enabled" && n != "listen" && n != "dir" && n != "crossdomain") {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("unsupported http_stream directive %s, ret=%d", n.c_str(), ret);
|
||||
return ret;
|
||||
|
@ -6591,6 +6602,23 @@ string SrsConfig::get_http_stream_dir()
|
|||
return conf->arg0();
|
||||
}
|
||||
|
||||
bool SrsConfig::get_http_stream_crossdomain()
|
||||
{
|
||||
static bool DEFAULT = true;
|
||||
|
||||
SrsConfDirective* conf = root->get("http_server");
|
||||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("crossdomain");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
return SRS_CONF_PERFER_TRUE(conf->arg0());
|
||||
}
|
||||
|
||||
bool SrsConfig::get_vhost_http_enabled(string vhost)
|
||||
{
|
||||
static bool DEFAULT = false;
|
||||
|
|
|
@ -1324,6 +1324,10 @@ public:
|
|||
* get the http stream root dir.
|
||||
*/
|
||||
virtual std::string get_http_stream_dir();
|
||||
/**
|
||||
* whether enable crossdomain for http static and stream server.
|
||||
*/
|
||||
virtual bool get_http_stream_crossdomain();
|
||||
public:
|
||||
/**
|
||||
* get whether vhost enabled http stream
|
||||
|
|
|
@ -35,6 +35,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
#include <srs_app_st.hpp>
|
||||
#include <srs_app_thread.hpp>
|
||||
#include <srs_protocol_kbps.hpp>
|
||||
#include <srs_app_reload.hpp>
|
||||
|
||||
class SrsConnection;
|
||||
|
||||
|
@ -58,7 +59,7 @@ public:
|
|||
* all connections accept from listener must extends from this base class,
|
||||
* server will add the connection to manager, and delete it when remove.
|
||||
*/
|
||||
class SrsConnection : public virtual ISrsOneCycleThreadHandler, public virtual IKbpsDelta
|
||||
class SrsConnection : virtual public ISrsOneCycleThreadHandler, virtual public IKbpsDelta, virtual public ISrsReloadHandler
|
||||
{
|
||||
private:
|
||||
/**
|
||||
|
|
|
@ -1424,7 +1424,7 @@ int SrsHttpApi::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
|||
r->method_str().c_str(), r->url().c_str(), r->content_length(),
|
||||
hm->is_chunked(), hm->is_infinite_chunked());
|
||||
|
||||
// use default server mux to serve http request.
|
||||
// use cors server mux to serve http request, which will proxy to mux.
|
||||
if ((ret = cors->serve_http(w, r)) != ERROR_SUCCESS) {
|
||||
if (!srs_is_client_gracefully_close(ret)) {
|
||||
srs_error("serve http msg failed. ret=%d", ret);
|
||||
|
|
|
@ -1091,12 +1091,14 @@ SrsHttpConn::SrsHttpConn(IConnectionManager* cm, st_netfd_t fd, ISrsHttpServeMux
|
|||
: SrsConnection(cm, fd, cip)
|
||||
{
|
||||
parser = new SrsHttpParser();
|
||||
cors = new SrsHttpCorsMux();
|
||||
http_mux = m;
|
||||
}
|
||||
|
||||
SrsHttpConn::~SrsHttpConn()
|
||||
{
|
||||
srs_freep(parser);
|
||||
srs_freep(cors);
|
||||
}
|
||||
|
||||
void SrsHttpConn::resample()
|
||||
|
@ -1140,6 +1142,12 @@ int SrsHttpConn::do_cycle()
|
|||
SrsRequest* last_req = NULL;
|
||||
SrsAutoFree(SrsRequest, last_req);
|
||||
|
||||
// initialize the cors, which will proxy to mux.
|
||||
bool crossdomain_enabled = _srs_config->get_http_stream_crossdomain();
|
||||
if ((ret = cors->initialize(http_mux, crossdomain_enabled)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// process http messages.
|
||||
while (!disposed) {
|
||||
ISrsHttpMessage* req = NULL;
|
||||
|
@ -1193,8 +1201,8 @@ int SrsHttpConn::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
|||
srs_trace("HTTP %s %s, content-length=%"PRId64"",
|
||||
r->method_str().c_str(), r->url().c_str(), r->content_length());
|
||||
|
||||
// use default server mux to serve http request.
|
||||
if ((ret = http_mux->serve_http(w, r)) != ERROR_SUCCESS) {
|
||||
// use cors server mux to serve http request, which will proxy to http_remux.
|
||||
if ((ret = cors->serve_http(w, r)) != ERROR_SUCCESS) {
|
||||
if (!srs_is_client_gracefully_close(ret)) {
|
||||
srs_error("serve http msg failed. ret=%d", ret);
|
||||
}
|
||||
|
@ -1211,6 +1219,19 @@ int SrsHttpConn::on_disconnect(SrsRequest* req)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsHttpConn::on_reload_http_stream_crossdomain()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// initialize the cors, which will proxy to mux.
|
||||
bool crossdomain_enabled = _srs_config->get_http_stream_crossdomain();
|
||||
if ((ret = cors->initialize(http_mux, crossdomain_enabled)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SrsResponseOnlyHttpConn::SrsResponseOnlyHttpConn(IConnectionManager* cm, st_netfd_t fd, ISrsHttpServeMux* m, string cip)
|
||||
: SrsHttpConn(cm, fd, m, cip)
|
||||
{
|
||||
|
|
|
@ -353,11 +353,15 @@ private:
|
|||
static int on_body(http_parser* parser, const char* at, size_t length);
|
||||
};
|
||||
|
||||
/**
|
||||
* The http connection which request the static or stream content.
|
||||
*/
|
||||
class SrsHttpConn : public SrsConnection
|
||||
{
|
||||
private:
|
||||
SrsHttpParser* parser;
|
||||
ISrsHttpServeMux* http_mux;
|
||||
SrsHttpCorsMux* cors;
|
||||
public:
|
||||
SrsHttpConn(IConnectionManager* cm, st_netfd_t fd, ISrsHttpServeMux* m, std::string cip);
|
||||
virtual ~SrsHttpConn();
|
||||
|
@ -382,6 +386,9 @@ private:
|
|||
* @param request: request which is converted by the last http message.
|
||||
*/
|
||||
virtual int on_disconnect(SrsRequest* req);
|
||||
// interface ISrsReloadHandler
|
||||
public:
|
||||
virtual int on_reload_http_stream_crossdomain();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -110,6 +110,11 @@ int ISrsReloadHandler::on_reload_http_stream_updated()
|
|||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_http_stream_crossdomain()
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_vhost_http_updated()
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
|
|
|
@ -59,6 +59,7 @@ public:
|
|||
virtual int on_reload_http_stream_enabled();
|
||||
virtual int on_reload_http_stream_disabled();
|
||||
virtual int on_reload_http_stream_updated();
|
||||
virtual int on_reload_http_stream_crossdomain();
|
||||
public:
|
||||
// TODO: FIXME: should rename to http_static
|
||||
virtual int on_reload_vhost_http_updated();
|
||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
// current release version
|
||||
#define VERSION_MAJOR 3
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 8
|
||||
#define VERSION_REVISION 9
|
||||
|
||||
// generated by configure, only macros.
|
||||
#include <srs_auto_headers.hpp>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue