1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

refine the cros of api for flv

This commit is contained in:
winlin 2016-12-15 14:10:02 +08:00
parent 3df8f11884
commit f30b3073a2
4 changed files with 83 additions and 30 deletions

View file

@ -761,6 +761,54 @@ bool SrsHttpServeMux::path_match(string pattern, string path)
return false;
}
SrsHttpCrosMux::SrsHttpCrosMux()
{
next = NULL;
enabled = false;
required = false;
}
SrsHttpCrosMux::~SrsHttpCrosMux()
{
}
int SrsHttpCrosMux::initialize(ISrsHttpServeMux* worker, bool cros_enabled)
{
next = worker;
enabled = cros_enabled;
return ERROR_SUCCESS;
}
int SrsHttpCrosMux::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
// method is OPTIONS and enable crossdomain, required crossdomain header.
if (r->is_http_options() && enabled) {
required = true;
}
// whenever crossdomain required, set crossdomain header.
if (required) {
w->header()->set("Access-Control-Allow-Origin", "*");
w->header()->set("Access-Control-Allow-Methods", "GET, POST, HEAD, PUT, DELETE");
w->header()->set("Access-Control-Allow-Headers", "Cache-Control,X-Proxy-Authorization,X-Requested-With,Content-Type");
}
// handle the http options.
if (r->is_http_options()) {
w->header()->set_content_length(0);
if (enabled) {
w->write_header(SRS_CONSTS_HTTP_OK);
} else {
w->write_header(SRS_CONSTS_HTTP_MethodNotAllowed);
}
return w->final_request();
}
srs_assert(next);
return next->serve_http(w, r);
}
ISrsHttpMessage::ISrsHttpMessage()
{
_http_ts_send_buffer = new char[SRS_HTTP_TS_SEND_BUFFER_SIZE];

View file

@ -442,6 +442,26 @@ private:
virtual bool path_match(std::string pattern, std::string path);
};
/**
* The filter http mux, directly serve the http CROS requests,
* while proxy to the worker mux for services.
*/
class SrsHttpCrosMux : public ISrsHttpServeMux
{
private:
bool required;
bool enabled;
ISrsHttpServeMux* next;
public:
SrsHttpCrosMux();
virtual ~SrsHttpCrosMux();
public:
virtual int initialize(ISrsHttpServeMux* worker, bool cros_enabled);
// interface ISrsHttpServeMux
public:
virtual int serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
};
// for http header.
typedef std::pair<std::string, std::string> SrsHttpHeaderField;