mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
parent
664844b5f5
commit
f6661989af
4 changed files with 15 additions and 15 deletions
|
@ -1312,7 +1312,7 @@ SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m
|
||||||
: SrsConnection(cm, fd, cip)
|
: SrsConnection(cm, fd, cip)
|
||||||
{
|
{
|
||||||
mux = m;
|
mux = m;
|
||||||
cros = new SrsHttpCrosMux();
|
cors = new SrsHttpCorsMux();
|
||||||
parser = new SrsHttpParser();
|
parser = new SrsHttpParser();
|
||||||
|
|
||||||
_srs_config->subscribe(this);
|
_srs_config->subscribe(this);
|
||||||
|
@ -1321,7 +1321,7 @@ SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m
|
||||||
SrsHttpApi::~SrsHttpApi()
|
SrsHttpApi::~SrsHttpApi()
|
||||||
{
|
{
|
||||||
srs_freep(parser);
|
srs_freep(parser);
|
||||||
srs_freep(cros);
|
srs_freep(cors);
|
||||||
|
|
||||||
_srs_config->unsubscribe(this);
|
_srs_config->unsubscribe(this);
|
||||||
}
|
}
|
||||||
|
@ -1367,9 +1367,9 @@ int SrsHttpApi::do_cycle()
|
||||||
// @see https://github.com/ossrs/srs/issues/398
|
// @see https://github.com/ossrs/srs/issues/398
|
||||||
skt.set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US);
|
skt.set_recv_timeout(SRS_HTTP_RECV_TIMEOUT_US);
|
||||||
|
|
||||||
// initialize the cros, which will proxy to mux.
|
// initialize the cors, which will proxy to mux.
|
||||||
bool crossdomain_enabled = _srs_config->get_http_api_crossdomain();
|
bool crossdomain_enabled = _srs_config->get_http_api_crossdomain();
|
||||||
if ((ret = cros->initialize(mux, crossdomain_enabled)) != ERROR_SUCCESS) {
|
if ((ret = cors->initialize(mux, crossdomain_enabled)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1425,7 +1425,7 @@ int SrsHttpApi::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
hm->is_chunked(), hm->is_infinite_chunked());
|
hm->is_chunked(), hm->is_infinite_chunked());
|
||||||
|
|
||||||
// use default server mux to serve http request.
|
// use default server mux to serve http request.
|
||||||
if ((ret = cros->serve_http(w, r)) != ERROR_SUCCESS) {
|
if ((ret = cors->serve_http(w, r)) != ERROR_SUCCESS) {
|
||||||
if (!srs_is_client_gracefully_close(ret)) {
|
if (!srs_is_client_gracefully_close(ret)) {
|
||||||
srs_error("serve http msg failed. ret=%d", ret);
|
srs_error("serve http msg failed. ret=%d", ret);
|
||||||
}
|
}
|
||||||
|
@ -1440,7 +1440,7 @@ int SrsHttpApi::on_reload_http_api_crossdomain()
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
bool crossdomain_enabled = _srs_config->get_http_api_crossdomain();
|
bool crossdomain_enabled = _srs_config->get_http_api_crossdomain();
|
||||||
if ((ret = cros->initialize(mux, crossdomain_enabled)) != ERROR_SUCCESS) {
|
if ((ret = cors->initialize(mux, crossdomain_enabled)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,7 @@ class SrsHttpApi : virtual public SrsConnection, virtual public ISrsReloadHandle
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsHttpParser* parser;
|
SrsHttpParser* parser;
|
||||||
SrsHttpCrosMux* cros;
|
SrsHttpCorsMux* cors;
|
||||||
SrsHttpServeMux* mux;
|
SrsHttpServeMux* mux;
|
||||||
public:
|
public:
|
||||||
SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m, std::string cip);
|
SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m, std::string cip);
|
||||||
|
|
|
@ -761,18 +761,18 @@ bool SrsHttpServeMux::path_match(string pattern, string path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHttpCrosMux::SrsHttpCrosMux()
|
SrsHttpCorsMux::SrsHttpCorsMux()
|
||||||
{
|
{
|
||||||
next = NULL;
|
next = NULL;
|
||||||
enabled = false;
|
enabled = false;
|
||||||
required = false;
|
required = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHttpCrosMux::~SrsHttpCrosMux()
|
SrsHttpCorsMux::~SrsHttpCorsMux()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHttpCrosMux::initialize(ISrsHttpServeMux* worker, bool cros_enabled)
|
int SrsHttpCorsMux::initialize(ISrsHttpServeMux* worker, bool cros_enabled)
|
||||||
{
|
{
|
||||||
next = worker;
|
next = worker;
|
||||||
enabled = cros_enabled;
|
enabled = cros_enabled;
|
||||||
|
@ -780,7 +780,7 @@ int SrsHttpCrosMux::initialize(ISrsHttpServeMux* worker, bool cros_enabled)
|
||||||
return ERROR_SUCCESS;
|
return ERROR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHttpCrosMux::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
int SrsHttpCorsMux::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
// method is OPTIONS and enable crossdomain, required crossdomain header.
|
// method is OPTIONS and enable crossdomain, required crossdomain header.
|
||||||
if (r->is_http_options() && enabled) {
|
if (r->is_http_options() && enabled) {
|
||||||
|
|
|
@ -443,18 +443,18 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The filter http mux, directly serve the http CROS requests,
|
* The filter http mux, directly serve the http CORS requests,
|
||||||
* while proxy to the worker mux for services.
|
* while proxy to the worker mux for services.
|
||||||
*/
|
*/
|
||||||
class SrsHttpCrosMux : public ISrsHttpServeMux
|
class SrsHttpCorsMux : public ISrsHttpServeMux
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
bool required;
|
bool required;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
ISrsHttpServeMux* next;
|
ISrsHttpServeMux* next;
|
||||||
public:
|
public:
|
||||||
SrsHttpCrosMux();
|
SrsHttpCorsMux();
|
||||||
virtual ~SrsHttpCrosMux();
|
virtual ~SrsHttpCorsMux();
|
||||||
public:
|
public:
|
||||||
virtual int initialize(ISrsHttpServeMux* worker, bool cros_enabled);
|
virtual int initialize(ISrsHttpServeMux* worker, bool cros_enabled);
|
||||||
// interface ISrsHttpServeMux
|
// interface ISrsHttpServeMux
|
||||||
|
|
Loading…
Reference in a new issue