|
|
|
@ -53,7 +53,7 @@ using namespace std;
|
|
|
|
|
|
|
|
|
|
#define SRS_HTTP_DEFAULT_PAGE "index.html"
|
|
|
|
|
|
|
|
|
|
int srs_go_http_response_json(ISrsGoHttpResponseWriter* w, string data)
|
|
|
|
|
int srs_go_http_response_json(ISrsHttpResponseWriter* w, string data)
|
|
|
|
|
{
|
|
|
|
|
w->header()->set_content_length(data.length());
|
|
|
|
|
w->header()->set_content_type("application/json");
|
|
|
|
@ -147,7 +147,7 @@ string srs_go_http_detect(char* data, int size)
|
|
|
|
|
|
|
|
|
|
// Error replies to the request with the specified error message and HTTP code.
|
|
|
|
|
// The error message should be plain text.
|
|
|
|
|
int srs_go_http_error(ISrsGoHttpResponseWriter* w, int code, string error)
|
|
|
|
|
int srs_go_http_error(ISrsHttpResponseWriter* w, int code, string error)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
@ -159,20 +159,20 @@ int srs_go_http_error(ISrsGoHttpResponseWriter* w, int code, string error)
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpHeader::SrsGoHttpHeader()
|
|
|
|
|
SrsHttpHeader::SrsHttpHeader()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpHeader::~SrsGoHttpHeader()
|
|
|
|
|
SrsHttpHeader::~SrsHttpHeader()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SrsGoHttpHeader::set(string key, string value)
|
|
|
|
|
void SrsHttpHeader::set(string key, string value)
|
|
|
|
|
{
|
|
|
|
|
headers[key] = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string SrsGoHttpHeader::get(string key)
|
|
|
|
|
string SrsHttpHeader::get(string key)
|
|
|
|
|
{
|
|
|
|
|
std::string v;
|
|
|
|
|
|
|
|
|
@ -183,7 +183,7 @@ string SrsGoHttpHeader::get(string key)
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t SrsGoHttpHeader::content_length()
|
|
|
|
|
int64_t SrsHttpHeader::content_length()
|
|
|
|
|
{
|
|
|
|
|
std::string cl = get("Content-Length");
|
|
|
|
|
|
|
|
|
@ -194,24 +194,24 @@ int64_t SrsGoHttpHeader::content_length()
|
|
|
|
|
return (int64_t)::atof(cl.c_str());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SrsGoHttpHeader::set_content_length(int64_t size)
|
|
|
|
|
void SrsHttpHeader::set_content_length(int64_t size)
|
|
|
|
|
{
|
|
|
|
|
char buf[64];
|
|
|
|
|
snprintf(buf, sizeof(buf), "%"PRId64, size);
|
|
|
|
|
set("Content-Length", buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string SrsGoHttpHeader::content_type()
|
|
|
|
|
string SrsHttpHeader::content_type()
|
|
|
|
|
{
|
|
|
|
|
return get("Content-Type");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SrsGoHttpHeader::set_content_type(string ct)
|
|
|
|
|
void SrsHttpHeader::set_content_type(string ct)
|
|
|
|
|
{
|
|
|
|
|
set("Content-Type", ct);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SrsGoHttpHeader::write(stringstream& ss)
|
|
|
|
|
void SrsHttpHeader::write(stringstream& ss)
|
|
|
|
|
{
|
|
|
|
|
std::map<std::string, std::string>::iterator it;
|
|
|
|
|
for (it = headers.begin(); it != headers.end(); ++it) {
|
|
|
|
@ -219,64 +219,64 @@ void SrsGoHttpHeader::write(stringstream& ss)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ISrsGoHttpResponseWriter::ISrsGoHttpResponseWriter()
|
|
|
|
|
ISrsHttpResponseWriter::ISrsHttpResponseWriter()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ISrsGoHttpResponseWriter::~ISrsGoHttpResponseWriter()
|
|
|
|
|
ISrsHttpResponseWriter::~ISrsHttpResponseWriter()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ISrsGoHttpHandler::ISrsGoHttpHandler()
|
|
|
|
|
ISrsHttpHandler::ISrsHttpHandler()
|
|
|
|
|
{
|
|
|
|
|
entry = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ISrsGoHttpHandler::~ISrsGoHttpHandler()
|
|
|
|
|
ISrsHttpHandler::~ISrsHttpHandler()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpRedirectHandler::SrsGoHttpRedirectHandler(string u, int c)
|
|
|
|
|
SrsHttpRedirectHandler::SrsHttpRedirectHandler(string u, int c)
|
|
|
|
|
{
|
|
|
|
|
url = u;
|
|
|
|
|
code = c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpRedirectHandler::~SrsGoHttpRedirectHandler()
|
|
|
|
|
SrsHttpRedirectHandler::~SrsHttpRedirectHandler()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpRedirectHandler::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
|
|
|
|
int SrsHttpRedirectHandler::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
// TODO: FIXME: implements it.
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpNotFoundHandler::SrsGoHttpNotFoundHandler()
|
|
|
|
|
SrsHttpNotFoundHandler::SrsHttpNotFoundHandler()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpNotFoundHandler::~SrsGoHttpNotFoundHandler()
|
|
|
|
|
SrsHttpNotFoundHandler::~SrsHttpNotFoundHandler()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpNotFoundHandler::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
|
|
|
|
int SrsHttpNotFoundHandler::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
|
|
|
|
{
|
|
|
|
|
return srs_go_http_error(w,
|
|
|
|
|
SRS_CONSTS_HTTP_NotFound, SRS_CONSTS_HTTP_NotFound_str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpFileServer::SrsGoHttpFileServer(string root_dir)
|
|
|
|
|
SrsHttpFileServer::SrsHttpFileServer(string root_dir)
|
|
|
|
|
{
|
|
|
|
|
dir = root_dir;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpFileServer::~SrsGoHttpFileServer()
|
|
|
|
|
SrsHttpFileServer::~SrsHttpFileServer()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
|
|
|
|
int SrsHttpFileServer::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
|
|
|
|
{
|
|
|
|
|
string upath = r->path();
|
|
|
|
|
|
|
|
|
@ -300,7 +300,7 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
|
|
|
|
if (!srs_path_exists(fullpath)) {
|
|
|
|
|
srs_warn("http miss file=%s, pattern=%s, upath=%s",
|
|
|
|
|
fullpath.c_str(), entry->pattern.c_str(), upath.c_str());
|
|
|
|
|
return SrsGoHttpNotFoundHandler().serve_http(w, r);
|
|
|
|
|
return SrsHttpNotFoundHandler().serve_http(w, r);
|
|
|
|
|
}
|
|
|
|
|
srs_trace("http match file=%s, pattern=%s, upath=%s",
|
|
|
|
|
fullpath.c_str(), entry->pattern.c_str(), upath.c_str());
|
|
|
|
@ -317,7 +317,7 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
|
|
|
|
return serve_file(w, r, fullpath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath)
|
|
|
|
|
int SrsHttpFileServer::serve_file(ISrsHttpResponseWriter* w, SrsHttpMessage* r, string fullpath)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
@ -391,7 +391,7 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
|
|
|
|
return w->final_request();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpFileServer::serve_flv_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath)
|
|
|
|
|
int SrsHttpFileServer::serve_flv_file(ISrsHttpResponseWriter* w, SrsHttpMessage* r, string fullpath)
|
|
|
|
|
{
|
|
|
|
|
std::string start = r->query_get("start");
|
|
|
|
|
if (start.empty()) {
|
|
|
|
@ -406,7 +406,7 @@ int SrsGoHttpFileServer::serve_flv_file(ISrsGoHttpResponseWriter* w, SrsHttpMess
|
|
|
|
|
return serve_flv_stream(w, r, fullpath, offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpFileServer::serve_mp4_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath)
|
|
|
|
|
int SrsHttpFileServer::serve_mp4_file(ISrsHttpResponseWriter* w, SrsHttpMessage* r, string fullpath)
|
|
|
|
|
{
|
|
|
|
|
// for flash to request mp4 range in query string.
|
|
|
|
|
// for example, http://digitalprimates.net/dash/DashTest.html?url=http://dashdemo.edgesuite.net/digitalprimates/nexus/oops-20120802-manifest.mpd
|
|
|
|
@ -443,17 +443,17 @@ int SrsGoHttpFileServer::serve_mp4_file(ISrsGoHttpResponseWriter* w, SrsHttpMess
|
|
|
|
|
return serve_mp4_stream(w, r, fullpath, start, end);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpFileServer::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int offset)
|
|
|
|
|
int SrsHttpFileServer::serve_flv_stream(ISrsHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int offset)
|
|
|
|
|
{
|
|
|
|
|
return serve_file(w, r, fullpath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpFileServer::serve_mp4_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int start, int end)
|
|
|
|
|
int SrsHttpFileServer::serve_mp4_stream(ISrsHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int start, int end)
|
|
|
|
|
{
|
|
|
|
|
return serve_file(w, r, fullpath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpFileServer::copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, SrsHttpMessage* r, int size)
|
|
|
|
|
int SrsHttpFileServer::copy(ISrsHttpResponseWriter* w, SrsFileReader* fs, SrsHttpMessage* r, int size)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
@ -476,27 +476,27 @@ int SrsGoHttpFileServer::copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, Sr
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpMuxEntry::SrsGoHttpMuxEntry()
|
|
|
|
|
SrsHttpMuxEntry::SrsHttpMuxEntry()
|
|
|
|
|
{
|
|
|
|
|
enabled = true;
|
|
|
|
|
explicit_match = false;
|
|
|
|
|
handler = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpMuxEntry::~SrsGoHttpMuxEntry()
|
|
|
|
|
SrsHttpMuxEntry::~SrsHttpMuxEntry()
|
|
|
|
|
{
|
|
|
|
|
srs_freep(handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpServeMux::SrsGoHttpServeMux()
|
|
|
|
|
SrsHttpServeMux::SrsHttpServeMux()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpServeMux::~SrsGoHttpServeMux()
|
|
|
|
|
SrsHttpServeMux::~SrsHttpServeMux()
|
|
|
|
|
{
|
|
|
|
|
std::map<std::string, SrsGoHttpMuxEntry*>::iterator it;
|
|
|
|
|
std::map<std::string, SrsHttpMuxEntry*>::iterator it;
|
|
|
|
|
for (it = entries.begin(); it != entries.end(); ++it) {
|
|
|
|
|
SrsGoHttpMuxEntry* entry = it->second;
|
|
|
|
|
SrsHttpMuxEntry* entry = it->second;
|
|
|
|
|
srs_freep(entry);
|
|
|
|
|
}
|
|
|
|
|
entries.clear();
|
|
|
|
@ -504,14 +504,14 @@ SrsGoHttpServeMux::~SrsGoHttpServeMux()
|
|
|
|
|
vhosts.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpServeMux::initialize()
|
|
|
|
|
int SrsHttpServeMux::initialize()
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
// TODO: FIXME: implements it.
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
|
|
|
|
int SrsHttpServeMux::handle(std::string pattern, ISrsHttpHandler* handler)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
@ -524,7 +524,7 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (entries.find(pattern) != entries.end()) {
|
|
|
|
|
SrsGoHttpMuxEntry* exists = entries[pattern];
|
|
|
|
|
SrsHttpMuxEntry* exists = entries[pattern];
|
|
|
|
|
if (exists->explicit_match) {
|
|
|
|
|
ret = ERROR_HTTP_PATTERN_DUPLICATED;
|
|
|
|
|
srs_error("http: multiple registrations for %s. ret=%d", pattern.c_str(), ret);
|
|
|
|
@ -541,14 +541,14 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsGoHttpMuxEntry* entry = new SrsGoHttpMuxEntry();
|
|
|
|
|
SrsHttpMuxEntry* entry = new SrsHttpMuxEntry();
|
|
|
|
|
entry->explicit_match = true;
|
|
|
|
|
entry->handler = handler;
|
|
|
|
|
entry->pattern = pattern;
|
|
|
|
|
entry->handler->entry = entry;
|
|
|
|
|
|
|
|
|
|
if (entries.find(pattern) != entries.end()) {
|
|
|
|
|
SrsGoHttpMuxEntry* exists = entries[pattern];
|
|
|
|
|
SrsHttpMuxEntry* exists = entries[pattern];
|
|
|
|
|
srs_freep(exists);
|
|
|
|
|
}
|
|
|
|
|
entries[pattern] = entry;
|
|
|
|
@ -559,11 +559,11 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
|
|
|
|
// It can be overridden by an explicit registration.
|
|
|
|
|
if (pattern != "/" && !pattern.empty() && pattern.at(pattern.length() - 1) == '/') {
|
|
|
|
|
std::string rpattern = pattern.substr(0, pattern.length() - 1);
|
|
|
|
|
SrsGoHttpMuxEntry* entry = NULL;
|
|
|
|
|
SrsHttpMuxEntry* entry = NULL;
|
|
|
|
|
|
|
|
|
|
// free the exists not explicit entry
|
|
|
|
|
if (entries.find(rpattern) != entries.end()) {
|
|
|
|
|
SrsGoHttpMuxEntry* exists = entries[rpattern];
|
|
|
|
|
SrsHttpMuxEntry* exists = entries[rpattern];
|
|
|
|
|
if (!exists->explicit_match) {
|
|
|
|
|
entry = exists;
|
|
|
|
|
}
|
|
|
|
@ -573,9 +573,9 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
|
|
|
|
if (!entry || entry->explicit_match) {
|
|
|
|
|
srs_freep(entry);
|
|
|
|
|
|
|
|
|
|
entry = new SrsGoHttpMuxEntry();
|
|
|
|
|
entry = new SrsHttpMuxEntry();
|
|
|
|
|
entry->explicit_match = false;
|
|
|
|
|
entry->handler = new SrsGoHttpRedirectHandler(pattern, SRS_CONSTS_HTTP_MovedPermanently);
|
|
|
|
|
entry->handler = new SrsHttpRedirectHandler(pattern, SRS_CONSTS_HTTP_MovedPermanently);
|
|
|
|
|
entry->pattern = pattern;
|
|
|
|
|
entry->handler->entry = entry;
|
|
|
|
|
|
|
|
|
@ -586,11 +586,11 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpServeMux::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
|
|
|
|
int SrsHttpServeMux::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
ISrsGoHttpHandler* h = NULL;
|
|
|
|
|
ISrsHttpHandler* h = NULL;
|
|
|
|
|
if ((ret = find_handler(r, &h)) != ERROR_SUCCESS) {
|
|
|
|
|
srs_error("find handler failed. ret=%d", ret);
|
|
|
|
|
return ret;
|
|
|
|
@ -607,7 +607,7 @@ int SrsGoHttpServeMux::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpServeMux::find_handler(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
|
|
|
|
int SrsHttpServeMux::find_handler(SrsHttpMessage* r, ISrsHttpHandler** ph)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
@ -624,13 +624,13 @@ int SrsGoHttpServeMux::find_handler(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*ph == NULL) {
|
|
|
|
|
*ph = new SrsGoHttpNotFoundHandler();
|
|
|
|
|
*ph = new SrsHttpNotFoundHandler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
|
|
|
|
int SrsHttpServeMux::match(SrsHttpMessage* r, ISrsHttpHandler** ph)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
@ -642,12 +642,12 @@ int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int nb_matched = 0;
|
|
|
|
|
ISrsGoHttpHandler* h = NULL;
|
|
|
|
|
ISrsHttpHandler* h = NULL;
|
|
|
|
|
|
|
|
|
|
std::map<std::string, SrsGoHttpMuxEntry*>::iterator it;
|
|
|
|
|
std::map<std::string, SrsHttpMuxEntry*>::iterator it;
|
|
|
|
|
for (it = entries.begin(); it != entries.end(); ++it) {
|
|
|
|
|
std::string pattern = it->first;
|
|
|
|
|
SrsGoHttpMuxEntry* entry = it->second;
|
|
|
|
|
SrsHttpMuxEntry* entry = it->second;
|
|
|
|
|
|
|
|
|
|
if (!entry->enabled) {
|
|
|
|
|
continue;
|
|
|
|
@ -668,7 +668,7 @@ int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool SrsGoHttpServeMux::path_match(string pattern, string path)
|
|
|
|
|
bool SrsHttpServeMux::path_match(string pattern, string path)
|
|
|
|
|
{
|
|
|
|
|
if (pattern.empty()) {
|
|
|
|
|
return false;
|
|
|
|
@ -692,10 +692,10 @@ bool SrsGoHttpServeMux::path_match(string pattern, string path)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpResponseWriter::SrsGoHttpResponseWriter(SrsStSocket* io)
|
|
|
|
|
SrsHttpResponseWriter::SrsHttpResponseWriter(SrsStSocket* io)
|
|
|
|
|
{
|
|
|
|
|
skt = io;
|
|
|
|
|
hdr = new SrsGoHttpHeader();
|
|
|
|
|
hdr = new SrsHttpHeader();
|
|
|
|
|
header_wrote = false;
|
|
|
|
|
status = SRS_CONSTS_HTTP_OK;
|
|
|
|
|
content_length = -1;
|
|
|
|
@ -703,12 +703,12 @@ SrsGoHttpResponseWriter::SrsGoHttpResponseWriter(SrsStSocket* io)
|
|
|
|
|
header_sent = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpResponseWriter::~SrsGoHttpResponseWriter()
|
|
|
|
|
SrsHttpResponseWriter::~SrsHttpResponseWriter()
|
|
|
|
|
{
|
|
|
|
|
srs_freep(hdr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpResponseWriter::final_request()
|
|
|
|
|
int SrsHttpResponseWriter::final_request()
|
|
|
|
|
{
|
|
|
|
|
// complete the chunked encoding.
|
|
|
|
|
if (content_length == -1) {
|
|
|
|
@ -722,12 +722,12 @@ int SrsGoHttpResponseWriter::final_request()
|
|
|
|
|
return write(NULL, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SrsGoHttpHeader* SrsGoHttpResponseWriter::header()
|
|
|
|
|
SrsHttpHeader* SrsHttpResponseWriter::header()
|
|
|
|
|
{
|
|
|
|
|
return hdr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpResponseWriter::write(char* data, int size)
|
|
|
|
|
int SrsHttpResponseWriter::write(char* data, int size)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
@ -774,7 +774,7 @@ int SrsGoHttpResponseWriter::write(char* data, int size)
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SrsGoHttpResponseWriter::write_header(int code)
|
|
|
|
|
void SrsHttpResponseWriter::write_header(int code)
|
|
|
|
|
{
|
|
|
|
|
if (header_wrote) {
|
|
|
|
|
srs_warn("http: multiple write_header calls, code=%d", code);
|
|
|
|
@ -788,7 +788,7 @@ void SrsGoHttpResponseWriter::write_header(int code)
|
|
|
|
|
content_length = hdr->content_length();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int SrsGoHttpResponseWriter::send_header(char* data, int size)
|
|
|
|
|
int SrsHttpResponseWriter::send_header(char* data, int size)
|
|
|
|
|
{
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|