Skip to content

Commit

Permalink
fix #717, #691, http api/static/stream support cors. 3.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Dec 15, 2016
1 parent f666198 commit b231550
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
console.conf
console*.conf
doc/frozen.2Mbps.1644x1028.flv
doc/frozen.500Kbps.766x480.flv
doc/kungfupanda3-tlr1_h1080p.200kbps.flv
Expand Down
4 changes: 4 additions & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

#############################################################################################
Expand Down
30 changes: 29 additions & 1 deletion trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,10 @@ class SrsConfig
* 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
Expand Down
3 changes: 2 additions & 1 deletion trunk/src/app/srs_app_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -58,7 +59,7 @@ class IConnectionManager
* 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:
/**
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 23 additions & 2 deletions trunk/src/app/srs_app_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -1139,6 +1141,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) {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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)
{
Expand Down
7 changes: 7 additions & 0 deletions trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,15 @@ class SrsHttpParser
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();
Expand All @@ -382,6 +386,9 @@ class SrsHttpConn : public SrsConnection
* @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();
};

/**
Expand Down
5 changes: 5 additions & 0 deletions trunk/src/app/srs_app_reload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_reload.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ISrsReloadHandler
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();
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit b231550

Please sign in to comment.