mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
refine http for srs, rename SrsGoHttp to SrsHttp.
This commit is contained in:
parent
983ab8fb89
commit
04dc60ebe1
8 changed files with 197 additions and 197 deletions
|
@ -53,7 +53,7 @@ using namespace std;
|
||||||
|
|
||||||
#define SRS_HTTP_DEFAULT_PAGE "index.html"
|
#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_length(data.length());
|
||||||
w->header()->set_content_type("application/json");
|
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.
|
// Error replies to the request with the specified error message and HTTP code.
|
||||||
// The error message should be plain text.
|
// 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;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -159,20 +159,20 @@ int srs_go_http_error(ISrsGoHttpResponseWriter* w, int code, string error)
|
||||||
return ret;
|
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;
|
headers[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
string SrsGoHttpHeader::get(string key)
|
string SrsHttpHeader::get(string key)
|
||||||
{
|
{
|
||||||
std::string v;
|
std::string v;
|
||||||
|
|
||||||
|
@ -183,7 +183,7 @@ string SrsGoHttpHeader::get(string key)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t SrsGoHttpHeader::content_length()
|
int64_t SrsHttpHeader::content_length()
|
||||||
{
|
{
|
||||||
std::string cl = get("Content-Length");
|
std::string cl = get("Content-Length");
|
||||||
|
|
||||||
|
@ -194,24 +194,24 @@ int64_t SrsGoHttpHeader::content_length()
|
||||||
return (int64_t)::atof(cl.c_str());
|
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];
|
char buf[64];
|
||||||
snprintf(buf, sizeof(buf), "%"PRId64, size);
|
snprintf(buf, sizeof(buf), "%"PRId64, size);
|
||||||
set("Content-Length", buf);
|
set("Content-Length", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
string SrsGoHttpHeader::content_type()
|
string SrsHttpHeader::content_type()
|
||||||
{
|
{
|
||||||
return get("Content-Type");
|
return get("Content-Type");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsGoHttpHeader::set_content_type(string ct)
|
void SrsHttpHeader::set_content_type(string ct)
|
||||||
{
|
{
|
||||||
set("Content-Type", ct);
|
set("Content-Type", ct);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsGoHttpHeader::write(stringstream& ss)
|
void SrsHttpHeader::write(stringstream& ss)
|
||||||
{
|
{
|
||||||
std::map<std::string, std::string>::iterator it;
|
std::map<std::string, std::string>::iterator it;
|
||||||
for (it = headers.begin(); it != headers.end(); ++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;
|
entry = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ISrsGoHttpHandler::~ISrsGoHttpHandler()
|
ISrsHttpHandler::~ISrsHttpHandler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsGoHttpRedirectHandler::SrsGoHttpRedirectHandler(string u, int c)
|
SrsHttpRedirectHandler::SrsHttpRedirectHandler(string u, int c)
|
||||||
{
|
{
|
||||||
url = u;
|
url = u;
|
||||||
code = c;
|
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;
|
int ret = ERROR_SUCCESS;
|
||||||
// TODO: FIXME: implements it.
|
// TODO: FIXME: implements it.
|
||||||
return ret;
|
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,
|
return srs_go_http_error(w,
|
||||||
SRS_CONSTS_HTTP_NotFound, SRS_CONSTS_HTTP_NotFound_str);
|
SRS_CONSTS_HTTP_NotFound, SRS_CONSTS_HTTP_NotFound_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsGoHttpFileServer::SrsGoHttpFileServer(string root_dir)
|
SrsHttpFileServer::SrsHttpFileServer(string root_dir)
|
||||||
{
|
{
|
||||||
dir = 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();
|
string upath = r->path();
|
||||||
|
|
||||||
|
@ -300,7 +300,7 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
||||||
if (!srs_path_exists(fullpath)) {
|
if (!srs_path_exists(fullpath)) {
|
||||||
srs_warn("http miss file=%s, pattern=%s, upath=%s",
|
srs_warn("http miss file=%s, pattern=%s, upath=%s",
|
||||||
fullpath.c_str(), entry->pattern.c_str(), upath.c_str());
|
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",
|
srs_trace("http match file=%s, pattern=%s, upath=%s",
|
||||||
fullpath.c_str(), entry->pattern.c_str(), upath.c_str());
|
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);
|
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;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
||||||
return w->final_request();
|
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");
|
std::string start = r->query_get("start");
|
||||||
if (start.empty()) {
|
if (start.empty()) {
|
||||||
|
@ -406,7 +406,7 @@ int SrsGoHttpFileServer::serve_flv_file(ISrsGoHttpResponseWriter* w, SrsHttpMess
|
||||||
return serve_flv_stream(w, r, fullpath, offset);
|
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 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
|
// 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);
|
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);
|
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);
|
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;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -476,27 +476,27 @@ int SrsGoHttpFileServer::copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, Sr
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsGoHttpMuxEntry::SrsGoHttpMuxEntry()
|
SrsHttpMuxEntry::SrsHttpMuxEntry()
|
||||||
{
|
{
|
||||||
enabled = true;
|
enabled = true;
|
||||||
explicit_match = false;
|
explicit_match = false;
|
||||||
handler = NULL;
|
handler = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsGoHttpMuxEntry::~SrsGoHttpMuxEntry()
|
SrsHttpMuxEntry::~SrsHttpMuxEntry()
|
||||||
{
|
{
|
||||||
srs_freep(handler);
|
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) {
|
for (it = entries.begin(); it != entries.end(); ++it) {
|
||||||
SrsGoHttpMuxEntry* entry = it->second;
|
SrsHttpMuxEntry* entry = it->second;
|
||||||
srs_freep(entry);
|
srs_freep(entry);
|
||||||
}
|
}
|
||||||
entries.clear();
|
entries.clear();
|
||||||
|
@ -504,14 +504,14 @@ SrsGoHttpServeMux::~SrsGoHttpServeMux()
|
||||||
vhosts.clear();
|
vhosts.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoHttpServeMux::initialize()
|
int SrsHttpServeMux::initialize()
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
// TODO: FIXME: implements it.
|
// TODO: FIXME: implements it.
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
int SrsHttpServeMux::handle(std::string pattern, ISrsHttpHandler* handler)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -524,7 +524,7 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entries.find(pattern) != entries.end()) {
|
if (entries.find(pattern) != entries.end()) {
|
||||||
SrsGoHttpMuxEntry* exists = entries[pattern];
|
SrsHttpMuxEntry* exists = entries[pattern];
|
||||||
if (exists->explicit_match) {
|
if (exists->explicit_match) {
|
||||||
ret = ERROR_HTTP_PATTERN_DUPLICATED;
|
ret = ERROR_HTTP_PATTERN_DUPLICATED;
|
||||||
srs_error("http: multiple registrations for %s. ret=%d", pattern.c_str(), ret);
|
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) {
|
if (true) {
|
||||||
SrsGoHttpMuxEntry* entry = new SrsGoHttpMuxEntry();
|
SrsHttpMuxEntry* entry = new SrsHttpMuxEntry();
|
||||||
entry->explicit_match = true;
|
entry->explicit_match = true;
|
||||||
entry->handler = handler;
|
entry->handler = handler;
|
||||||
entry->pattern = pattern;
|
entry->pattern = pattern;
|
||||||
entry->handler->entry = entry;
|
entry->handler->entry = entry;
|
||||||
|
|
||||||
if (entries.find(pattern) != entries.end()) {
|
if (entries.find(pattern) != entries.end()) {
|
||||||
SrsGoHttpMuxEntry* exists = entries[pattern];
|
SrsHttpMuxEntry* exists = entries[pattern];
|
||||||
srs_freep(exists);
|
srs_freep(exists);
|
||||||
}
|
}
|
||||||
entries[pattern] = entry;
|
entries[pattern] = entry;
|
||||||
|
@ -559,11 +559,11 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
||||||
// It can be overridden by an explicit registration.
|
// It can be overridden by an explicit registration.
|
||||||
if (pattern != "/" && !pattern.empty() && pattern.at(pattern.length() - 1) == '/') {
|
if (pattern != "/" && !pattern.empty() && pattern.at(pattern.length() - 1) == '/') {
|
||||||
std::string rpattern = pattern.substr(0, pattern.length() - 1);
|
std::string rpattern = pattern.substr(0, pattern.length() - 1);
|
||||||
SrsGoHttpMuxEntry* entry = NULL;
|
SrsHttpMuxEntry* entry = NULL;
|
||||||
|
|
||||||
// free the exists not explicit entry
|
// free the exists not explicit entry
|
||||||
if (entries.find(rpattern) != entries.end()) {
|
if (entries.find(rpattern) != entries.end()) {
|
||||||
SrsGoHttpMuxEntry* exists = entries[rpattern];
|
SrsHttpMuxEntry* exists = entries[rpattern];
|
||||||
if (!exists->explicit_match) {
|
if (!exists->explicit_match) {
|
||||||
entry = exists;
|
entry = exists;
|
||||||
}
|
}
|
||||||
|
@ -573,9 +573,9 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
||||||
if (!entry || entry->explicit_match) {
|
if (!entry || entry->explicit_match) {
|
||||||
srs_freep(entry);
|
srs_freep(entry);
|
||||||
|
|
||||||
entry = new SrsGoHttpMuxEntry();
|
entry = new SrsHttpMuxEntry();
|
||||||
entry->explicit_match = false;
|
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->pattern = pattern;
|
||||||
entry->handler->entry = entry;
|
entry->handler->entry = entry;
|
||||||
|
|
||||||
|
@ -586,11 +586,11 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoHttpServeMux::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsHttpServeMux::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
ISrsGoHttpHandler* h = NULL;
|
ISrsHttpHandler* h = NULL;
|
||||||
if ((ret = find_handler(r, &h)) != ERROR_SUCCESS) {
|
if ((ret = find_handler(r, &h)) != ERROR_SUCCESS) {
|
||||||
srs_error("find handler failed. ret=%d", ret);
|
srs_error("find handler failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -607,7 +607,7 @@ int SrsGoHttpServeMux::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoHttpServeMux::find_handler(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
int SrsHttpServeMux::find_handler(SrsHttpMessage* r, ISrsHttpHandler** ph)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -624,13 +624,13 @@ int SrsGoHttpServeMux::find_handler(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*ph == NULL) {
|
if (*ph == NULL) {
|
||||||
*ph = new SrsGoHttpNotFoundHandler();
|
*ph = new SrsHttpNotFoundHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
int SrsHttpServeMux::match(SrsHttpMessage* r, ISrsHttpHandler** ph)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -642,12 +642,12 @@ int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
||||||
}
|
}
|
||||||
|
|
||||||
int nb_matched = 0;
|
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) {
|
for (it = entries.begin(); it != entries.end(); ++it) {
|
||||||
std::string pattern = it->first;
|
std::string pattern = it->first;
|
||||||
SrsGoHttpMuxEntry* entry = it->second;
|
SrsHttpMuxEntry* entry = it->second;
|
||||||
|
|
||||||
if (!entry->enabled) {
|
if (!entry->enabled) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -668,7 +668,7 @@ int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsGoHttpServeMux::path_match(string pattern, string path)
|
bool SrsHttpServeMux::path_match(string pattern, string path)
|
||||||
{
|
{
|
||||||
if (pattern.empty()) {
|
if (pattern.empty()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -692,10 +692,10 @@ bool SrsGoHttpServeMux::path_match(string pattern, string path)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsGoHttpResponseWriter::SrsGoHttpResponseWriter(SrsStSocket* io)
|
SrsHttpResponseWriter::SrsHttpResponseWriter(SrsStSocket* io)
|
||||||
{
|
{
|
||||||
skt = io;
|
skt = io;
|
||||||
hdr = new SrsGoHttpHeader();
|
hdr = new SrsHttpHeader();
|
||||||
header_wrote = false;
|
header_wrote = false;
|
||||||
status = SRS_CONSTS_HTTP_OK;
|
status = SRS_CONSTS_HTTP_OK;
|
||||||
content_length = -1;
|
content_length = -1;
|
||||||
|
@ -703,12 +703,12 @@ SrsGoHttpResponseWriter::SrsGoHttpResponseWriter(SrsStSocket* io)
|
||||||
header_sent = false;
|
header_sent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsGoHttpResponseWriter::~SrsGoHttpResponseWriter()
|
SrsHttpResponseWriter::~SrsHttpResponseWriter()
|
||||||
{
|
{
|
||||||
srs_freep(hdr);
|
srs_freep(hdr);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoHttpResponseWriter::final_request()
|
int SrsHttpResponseWriter::final_request()
|
||||||
{
|
{
|
||||||
// complete the chunked encoding.
|
// complete the chunked encoding.
|
||||||
if (content_length == -1) {
|
if (content_length == -1) {
|
||||||
|
@ -722,12 +722,12 @@ int SrsGoHttpResponseWriter::final_request()
|
||||||
return write(NULL, 0);
|
return write(NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsGoHttpHeader* SrsGoHttpResponseWriter::header()
|
SrsHttpHeader* SrsHttpResponseWriter::header()
|
||||||
{
|
{
|
||||||
return hdr;
|
return hdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoHttpResponseWriter::write(char* data, int size)
|
int SrsHttpResponseWriter::write(char* data, int size)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -774,7 +774,7 @@ int SrsGoHttpResponseWriter::write(char* data, int size)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsGoHttpResponseWriter::write_header(int code)
|
void SrsHttpResponseWriter::write_header(int code)
|
||||||
{
|
{
|
||||||
if (header_wrote) {
|
if (header_wrote) {
|
||||||
srs_warn("http: multiple write_header calls, code=%d", code);
|
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();
|
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;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -47,8 +47,8 @@ class SrsHttpUri;
|
||||||
class SrsHttpMessage;
|
class SrsHttpMessage;
|
||||||
class SrsFileReader;
|
class SrsFileReader;
|
||||||
class SrsSimpleBuffer;
|
class SrsSimpleBuffer;
|
||||||
class SrsGoHttpMuxEntry;
|
class SrsHttpMuxEntry;
|
||||||
class ISrsGoHttpResponseWriter;
|
class ISrsHttpResponseWriter;
|
||||||
|
|
||||||
// http specification
|
// http specification
|
||||||
// CR = <US-ASCII CR, carriage return (13)>
|
// CR = <US-ASCII CR, carriage return (13)>
|
||||||
|
@ -70,7 +70,7 @@ class ISrsGoHttpResponseWriter;
|
||||||
#define __SRS_HTTP_TS_SEND_BUFFER_SIZE 4096
|
#define __SRS_HTTP_TS_SEND_BUFFER_SIZE 4096
|
||||||
|
|
||||||
// helper function: response in json format.
|
// helper function: response in json format.
|
||||||
extern int srs_go_http_response_json(ISrsGoHttpResponseWriter* w, std::string data);
|
extern int srs_go_http_response_json(ISrsHttpResponseWriter* w, std::string data);
|
||||||
|
|
||||||
// state of message
|
// state of message
|
||||||
enum SrsHttpParseState {
|
enum SrsHttpParseState {
|
||||||
|
@ -80,13 +80,13 @@ enum SrsHttpParseState {
|
||||||
};
|
};
|
||||||
|
|
||||||
// A Header represents the key-value pairs in an HTTP header.
|
// A Header represents the key-value pairs in an HTTP header.
|
||||||
class SrsGoHttpHeader
|
class SrsHttpHeader
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::map<std::string, std::string> headers;
|
std::map<std::string, std::string> headers;
|
||||||
public:
|
public:
|
||||||
SrsGoHttpHeader();
|
SrsHttpHeader();
|
||||||
virtual ~SrsGoHttpHeader();
|
virtual ~SrsHttpHeader();
|
||||||
public:
|
public:
|
||||||
// Add adds the key, value pair to the header.
|
// Add adds the key, value pair to the header.
|
||||||
// It appends to any existing values associated with key.
|
// It appends to any existing values associated with key.
|
||||||
|
@ -124,7 +124,7 @@ public:
|
||||||
// A ResponseWriter interface is used by an HTTP handler to
|
// A ResponseWriter interface is used by an HTTP handler to
|
||||||
// construct an HTTP response.
|
// construct an HTTP response.
|
||||||
// Usage 1, response with specified length content:
|
// Usage 1, response with specified length content:
|
||||||
// ISrsGoHttpResponseWriter* w; // create or get response.
|
// ISrsHttpResponseWriter* w; // create or get response.
|
||||||
// std::string msg = "Hello, HTTP!";
|
// std::string msg = "Hello, HTTP!";
|
||||||
// w->header()->set_content_type("text/plain; charset=utf-8");
|
// w->header()->set_content_type("text/plain; charset=utf-8");
|
||||||
// w->header()->set_content_length(msg.length());
|
// w->header()->set_content_length(msg.length());
|
||||||
|
@ -132,12 +132,12 @@ public:
|
||||||
// w->write((char*)msg.data(), (int)msg.length());
|
// w->write((char*)msg.data(), (int)msg.length());
|
||||||
// w->final_request(); // optional flush.
|
// w->final_request(); // optional flush.
|
||||||
// Usage 2, response with HTTP code only, zero content length.
|
// Usage 2, response with HTTP code only, zero content length.
|
||||||
// ISrsGoHttpResponseWriter* w; // create or get response.
|
// ISrsHttpResponseWriter* w; // create or get response.
|
||||||
// w->header()->set_content_length(0);
|
// w->header()->set_content_length(0);
|
||||||
// w->write_header(SRS_CONSTS_HTTP_OK);
|
// w->write_header(SRS_CONSTS_HTTP_OK);
|
||||||
// w->final_request();
|
// w->final_request();
|
||||||
// Usage 3, response in chunked encoding.
|
// Usage 3, response in chunked encoding.
|
||||||
// ISrsGoHttpResponseWriter* w; // create or get response.
|
// ISrsHttpResponseWriter* w; // create or get response.
|
||||||
// std::string msg = "Hello, HTTP!";
|
// std::string msg = "Hello, HTTP!";
|
||||||
// w->header()->set_content_type("application/octet-stream");
|
// w->header()->set_content_type("application/octet-stream");
|
||||||
// w->write_header(SRS_CONSTS_HTTP_OK);
|
// w->write_header(SRS_CONSTS_HTTP_OK);
|
||||||
|
@ -146,11 +146,11 @@ public:
|
||||||
// w->write((char*)msg.data(), (int)msg.length());
|
// w->write((char*)msg.data(), (int)msg.length());
|
||||||
// w->write((char*)msg.data(), (int)msg.length());
|
// w->write((char*)msg.data(), (int)msg.length());
|
||||||
// w->final_request(); // required to end the chunked and flush.
|
// w->final_request(); // required to end the chunked and flush.
|
||||||
class ISrsGoHttpResponseWriter
|
class ISrsHttpResponseWriter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ISrsGoHttpResponseWriter();
|
ISrsHttpResponseWriter();
|
||||||
virtual ~ISrsGoHttpResponseWriter();
|
virtual ~ISrsHttpResponseWriter();
|
||||||
public:
|
public:
|
||||||
// when chunked mode,
|
// when chunked mode,
|
||||||
// final the request to complete the chunked encoding.
|
// final the request to complete the chunked encoding.
|
||||||
|
@ -159,7 +159,7 @@ public:
|
||||||
// Header returns the header map that will be sent by WriteHeader.
|
// Header returns the header map that will be sent by WriteHeader.
|
||||||
// Changing the header after a call to WriteHeader (or Write) has
|
// Changing the header after a call to WriteHeader (or Write) has
|
||||||
// no effect.
|
// no effect.
|
||||||
virtual SrsGoHttpHeader* header() = 0;
|
virtual SrsHttpHeader* header() = 0;
|
||||||
|
|
||||||
// Write writes the data to the connection as part of an HTTP reply.
|
// Write writes the data to the connection as part of an HTTP reply.
|
||||||
// If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK)
|
// If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK)
|
||||||
|
@ -186,38 +186,38 @@ public:
|
||||||
// and then return. Returning signals that the request is finished
|
// and then return. Returning signals that the request is finished
|
||||||
// and that the HTTP server can move on to the next request on
|
// and that the HTTP server can move on to the next request on
|
||||||
// the connection.
|
// the connection.
|
||||||
class ISrsGoHttpHandler
|
class ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoHttpMuxEntry* entry;
|
SrsHttpMuxEntry* entry;
|
||||||
public:
|
public:
|
||||||
ISrsGoHttpHandler();
|
ISrsHttpHandler();
|
||||||
virtual ~ISrsGoHttpHandler();
|
virtual ~ISrsHttpHandler();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) = 0;
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Redirect to a fixed URL
|
// Redirect to a fixed URL
|
||||||
class SrsGoHttpRedirectHandler : public ISrsGoHttpHandler
|
class SrsHttpRedirectHandler : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string url;
|
std::string url;
|
||||||
int code;
|
int code;
|
||||||
public:
|
public:
|
||||||
SrsGoHttpRedirectHandler(std::string u, int c);
|
SrsHttpRedirectHandler(std::string u, int c);
|
||||||
virtual ~SrsGoHttpRedirectHandler();
|
virtual ~SrsHttpRedirectHandler();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
// NotFound replies to the request with an HTTP 404 not found error.
|
// NotFound replies to the request with an HTTP 404 not found error.
|
||||||
class SrsGoHttpNotFoundHandler : public ISrsGoHttpHandler
|
class SrsHttpNotFoundHandler : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoHttpNotFoundHandler();
|
SrsHttpNotFoundHandler();
|
||||||
virtual ~SrsGoHttpNotFoundHandler();
|
virtual ~SrsHttpNotFoundHandler();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
// FileServer returns a handler that serves HTTP requests
|
// FileServer returns a handler that serves HTTP requests
|
||||||
|
@ -226,54 +226,54 @@ public:
|
||||||
// To use the operating system's file system implementation,
|
// To use the operating system's file system implementation,
|
||||||
// use http.Dir:
|
// use http.Dir:
|
||||||
//
|
//
|
||||||
// http.Handle("/", SrsGoHttpFileServer("/tmp"))
|
// http.Handle("/", SrsHttpFileServer("/tmp"))
|
||||||
// http.Handle("/", SrsGoHttpFileServer("static-dir"))
|
// http.Handle("/", SrsHttpFileServer("static-dir"))
|
||||||
class SrsGoHttpFileServer : public ISrsGoHttpHandler
|
class SrsHttpFileServer : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
std::string dir;
|
std::string dir;
|
||||||
public:
|
public:
|
||||||
SrsGoHttpFileServer(std::string root_dir);
|
SrsHttpFileServer(std::string root_dir);
|
||||||
virtual ~SrsGoHttpFileServer();
|
virtual ~SrsHttpFileServer();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* serve the file by specified path
|
* serve the file by specified path
|
||||||
*/
|
*/
|
||||||
virtual int serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
|
virtual int serve_file(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
|
||||||
virtual int serve_flv_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
|
virtual int serve_flv_file(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
|
||||||
virtual int serve_mp4_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
|
virtual int serve_mp4_file(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* when access flv file with x.flv?start=xxx
|
* when access flv file with x.flv?start=xxx
|
||||||
*/
|
*/
|
||||||
virtual int serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int offset);
|
virtual int serve_flv_stream(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int offset);
|
||||||
/**
|
/**
|
||||||
* when access mp4 file with x.mp4?range=start-end
|
* when access mp4 file with x.mp4?range=start-end
|
||||||
* @param start the start offset in bytes.
|
* @param start the start offset in bytes.
|
||||||
* @param end the end offset in bytes. -1 to end of file.
|
* @param end the end offset in bytes. -1 to end of file.
|
||||||
* @remark response data in [start, end].
|
* @remark response data in [start, end].
|
||||||
*/
|
*/
|
||||||
virtual int serve_mp4_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int start, int end);
|
virtual int serve_mp4_stream(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int start, int end);
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* copy the fs to response writer in size bytes.
|
* copy the fs to response writer in size bytes.
|
||||||
*/
|
*/
|
||||||
virtual int copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, SrsHttpMessage* r, int size);
|
virtual int copy(ISrsHttpResponseWriter* w, SrsFileReader* fs, SrsHttpMessage* r, int size);
|
||||||
};
|
};
|
||||||
|
|
||||||
// the mux entry for server mux.
|
// the mux entry for server mux.
|
||||||
class SrsGoHttpMuxEntry
|
class SrsHttpMuxEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool explicit_match;
|
bool explicit_match;
|
||||||
ISrsGoHttpHandler* handler;
|
ISrsHttpHandler* handler;
|
||||||
std::string pattern;
|
std::string pattern;
|
||||||
bool enabled;
|
bool enabled;
|
||||||
public:
|
public:
|
||||||
SrsGoHttpMuxEntry();
|
SrsHttpMuxEntry();
|
||||||
virtual ~SrsGoHttpMuxEntry();
|
virtual ~SrsHttpMuxEntry();
|
||||||
};
|
};
|
||||||
|
|
||||||
// ServeMux is an HTTP request multiplexer.
|
// ServeMux is an HTTP request multiplexer.
|
||||||
|
@ -303,16 +303,16 @@ public:
|
||||||
// ServeMux also takes care of sanitizing the URL request path,
|
// ServeMux also takes care of sanitizing the URL request path,
|
||||||
// redirecting any request containing . or .. elements to an
|
// redirecting any request containing . or .. elements to an
|
||||||
// equivalent .- and ..-free URL.
|
// equivalent .- and ..-free URL.
|
||||||
class SrsGoHttpServeMux
|
class SrsHttpServeMux
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// the pattern handler.
|
// the pattern handler.
|
||||||
std::map<std::string, SrsGoHttpMuxEntry*> entries;
|
std::map<std::string, SrsHttpMuxEntry*> entries;
|
||||||
// the vhost handler.
|
// the vhost handler.
|
||||||
std::map<std::string, ISrsGoHttpHandler*> vhosts;
|
std::map<std::string, ISrsHttpHandler*> vhosts;
|
||||||
public:
|
public:
|
||||||
SrsGoHttpServeMux();
|
SrsHttpServeMux();
|
||||||
virtual ~SrsGoHttpServeMux();
|
virtual ~SrsHttpServeMux();
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* initialize the http serve mux.
|
* initialize the http serve mux.
|
||||||
|
@ -321,24 +321,24 @@ public:
|
||||||
public:
|
public:
|
||||||
// Handle registers the handler for the given pattern.
|
// Handle registers the handler for the given pattern.
|
||||||
// If a handler already exists for pattern, Handle panics.
|
// If a handler already exists for pattern, Handle panics.
|
||||||
virtual int handle(std::string pattern, ISrsGoHttpHandler* handler);
|
virtual int handle(std::string pattern, ISrsHttpHandler* handler);
|
||||||
// interface ISrsGoHttpHandler
|
// interface ISrsHttpHandler
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
private:
|
private:
|
||||||
virtual int find_handler(SrsHttpMessage* r, ISrsGoHttpHandler** ph);
|
virtual int find_handler(SrsHttpMessage* r, ISrsHttpHandler** ph);
|
||||||
virtual int match(SrsHttpMessage* r, ISrsGoHttpHandler** ph);
|
virtual int match(SrsHttpMessage* r, ISrsHttpHandler** ph);
|
||||||
virtual bool path_match(std::string pattern, std::string path);
|
virtual bool path_match(std::string pattern, std::string path);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* response writer use st socket
|
* response writer use st socket
|
||||||
*/
|
*/
|
||||||
class SrsGoHttpResponseWriter : public ISrsGoHttpResponseWriter
|
class SrsHttpResponseWriter : public ISrsHttpResponseWriter
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsStSocket* skt;
|
SrsStSocket* skt;
|
||||||
SrsGoHttpHeader* hdr;
|
SrsHttpHeader* hdr;
|
||||||
private:
|
private:
|
||||||
// reply header has been (logically) written
|
// reply header has been (logically) written
|
||||||
bool header_wrote;
|
bool header_wrote;
|
||||||
|
@ -356,11 +356,11 @@ private:
|
||||||
// logically written.
|
// logically written.
|
||||||
bool header_sent;
|
bool header_sent;
|
||||||
public:
|
public:
|
||||||
SrsGoHttpResponseWriter(SrsStSocket* io);
|
SrsHttpResponseWriter(SrsStSocket* io);
|
||||||
virtual ~SrsGoHttpResponseWriter();
|
virtual ~SrsHttpResponseWriter();
|
||||||
public:
|
public:
|
||||||
virtual int final_request();
|
virtual int final_request();
|
||||||
virtual SrsGoHttpHeader* header();
|
virtual SrsHttpHeader* header();
|
||||||
virtual int write(char* data, int size);
|
virtual int write(char* data, int size);
|
||||||
virtual void write_header(int code);
|
virtual void write_header(int code);
|
||||||
virtual int send_header(char* data, int size);
|
virtual int send_header(char* data, int size);
|
||||||
|
|
|
@ -48,7 +48,7 @@ SrsGoApiRoot::~SrsGoApiRoot()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiRoot::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiRoot::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ SrsGoApiApi::~SrsGoApiApi()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiApi::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiApi::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ SrsGoApiV1::~SrsGoApiV1()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiV1::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiV1::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ SrsGoApiVersion::~SrsGoApiVersion()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiVersion::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiVersion::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ SrsGoApiSummaries::~SrsGoApiSummaries()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiSummaries::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiSummaries::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
srs_api_dump_summaries(ss);
|
srs_api_dump_summaries(ss);
|
||||||
|
@ -163,7 +163,7 @@ SrsGoApiRusages::~SrsGoApiRusages()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiRusages::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* req)
|
int SrsGoApiRusages::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* req)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
@ -204,7 +204,7 @@ SrsGoApiSelfProcStats::~SrsGoApiSelfProcStats()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiSelfProcStats::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiSelfProcStats::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ SrsGoApiSystemProcStats::~SrsGoApiSystemProcStats()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiSystemProcStats::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiSystemProcStats::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ SrsGoApiMemInfos::~SrsGoApiMemInfos()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiMemInfos::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiMemInfos::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
@ -345,7 +345,7 @@ SrsGoApiAuthors::~SrsGoApiAuthors()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiAuthors::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiAuthors::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
||||||
|
@ -370,7 +370,7 @@ SrsGoApiRequests::~SrsGoApiRequests()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiRequests::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiRequests::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
SrsHttpMessage* req = r;
|
SrsHttpMessage* req = r;
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ SrsGoApiVhosts::~SrsGoApiVhosts()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiVhosts::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiVhosts::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream data;
|
std::stringstream data;
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
@ -456,7 +456,7 @@ SrsGoApiStreams::~SrsGoApiStreams()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsGoApiStreams::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream data;
|
std::stringstream data;
|
||||||
SrsStatistic* stat = SrsStatistic::instance();
|
SrsStatistic* stat = SrsStatistic::instance();
|
||||||
|
@ -473,7 +473,7 @@ int SrsGoApiStreams::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
return srs_go_http_response_json(w, ss.str());
|
return srs_go_http_response_json(w, ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHttpApi::SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsGoHttpServeMux* m)
|
SrsHttpApi::SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsHttpServeMux* m)
|
||||||
: SrsConnection(svr, fd)
|
: SrsConnection(svr, fd)
|
||||||
{
|
{
|
||||||
mux = m;
|
mux = m;
|
||||||
|
@ -535,7 +535,7 @@ int SrsHttpApi::do_cycle()
|
||||||
SrsAutoFree(SrsHttpMessage, req);
|
SrsAutoFree(SrsHttpMessage, req);
|
||||||
|
|
||||||
// ok, handle http request.
|
// ok, handle http request.
|
||||||
SrsGoHttpResponseWriter writer(&skt);
|
SrsHttpResponseWriter writer(&skt);
|
||||||
if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
|
if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -544,7 +544,7 @@ int SrsHttpApi::do_cycle()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHttpApi::process_request(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsHttpApi::process_request(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -42,131 +42,131 @@ class SrsHttpHandler;
|
||||||
#include <srs_app_http.hpp>
|
#include <srs_app_http.hpp>
|
||||||
|
|
||||||
// for http root.
|
// for http root.
|
||||||
class SrsGoApiRoot : public ISrsGoHttpHandler
|
class SrsGoApiRoot : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiRoot();
|
SrsGoApiRoot();
|
||||||
virtual ~SrsGoApiRoot();
|
virtual ~SrsGoApiRoot();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiApi : public ISrsGoHttpHandler
|
class SrsGoApiApi : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiApi();
|
SrsGoApiApi();
|
||||||
virtual ~SrsGoApiApi();
|
virtual ~SrsGoApiApi();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiV1 : public ISrsGoHttpHandler
|
class SrsGoApiV1 : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiV1();
|
SrsGoApiV1();
|
||||||
virtual ~SrsGoApiV1();
|
virtual ~SrsGoApiV1();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiVersion : public ISrsGoHttpHandler
|
class SrsGoApiVersion : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiVersion();
|
SrsGoApiVersion();
|
||||||
virtual ~SrsGoApiVersion();
|
virtual ~SrsGoApiVersion();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiSummaries : public ISrsGoHttpHandler
|
class SrsGoApiSummaries : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiSummaries();
|
SrsGoApiSummaries();
|
||||||
virtual ~SrsGoApiSummaries();
|
virtual ~SrsGoApiSummaries();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiRusages : public ISrsGoHttpHandler
|
class SrsGoApiRusages : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiRusages();
|
SrsGoApiRusages();
|
||||||
virtual ~SrsGoApiRusages();
|
virtual ~SrsGoApiRusages();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiSelfProcStats : public ISrsGoHttpHandler
|
class SrsGoApiSelfProcStats : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiSelfProcStats();
|
SrsGoApiSelfProcStats();
|
||||||
virtual ~SrsGoApiSelfProcStats();
|
virtual ~SrsGoApiSelfProcStats();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiSystemProcStats : public ISrsGoHttpHandler
|
class SrsGoApiSystemProcStats : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiSystemProcStats();
|
SrsGoApiSystemProcStats();
|
||||||
virtual ~SrsGoApiSystemProcStats();
|
virtual ~SrsGoApiSystemProcStats();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiMemInfos : public ISrsGoHttpHandler
|
class SrsGoApiMemInfos : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiMemInfos();
|
SrsGoApiMemInfos();
|
||||||
virtual ~SrsGoApiMemInfos();
|
virtual ~SrsGoApiMemInfos();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiAuthors : public ISrsGoHttpHandler
|
class SrsGoApiAuthors : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiAuthors();
|
SrsGoApiAuthors();
|
||||||
virtual ~SrsGoApiAuthors();
|
virtual ~SrsGoApiAuthors();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiRequests : public ISrsGoHttpHandler
|
class SrsGoApiRequests : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiRequests();
|
SrsGoApiRequests();
|
||||||
virtual ~SrsGoApiRequests();
|
virtual ~SrsGoApiRequests();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiVhosts : public ISrsGoHttpHandler
|
class SrsGoApiVhosts : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiVhosts();
|
SrsGoApiVhosts();
|
||||||
virtual ~SrsGoApiVhosts();
|
virtual ~SrsGoApiVhosts();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsGoApiStreams : public ISrsGoHttpHandler
|
class SrsGoApiStreams : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoApiStreams();
|
SrsGoApiStreams();
|
||||||
virtual ~SrsGoApiStreams();
|
virtual ~SrsGoApiStreams();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsHttpApi : public SrsConnection
|
class SrsHttpApi : public SrsConnection
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsHttpParser* parser;
|
SrsHttpParser* parser;
|
||||||
SrsGoHttpServeMux* mux;
|
SrsHttpServeMux* mux;
|
||||||
bool crossdomain_required;
|
bool crossdomain_required;
|
||||||
public:
|
public:
|
||||||
SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsGoHttpServeMux* m);
|
SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsHttpServeMux* m);
|
||||||
virtual ~SrsHttpApi();
|
virtual ~SrsHttpApi();
|
||||||
public:
|
public:
|
||||||
virtual void kbps_resample();
|
virtual void kbps_resample();
|
||||||
|
@ -177,7 +177,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual int do_cycle();
|
virtual int do_cycle();
|
||||||
private:
|
private:
|
||||||
virtual int process_request(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int process_request(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -50,7 +50,7 @@ using namespace std;
|
||||||
#include <srs_app_pithy_print.hpp>
|
#include <srs_app_pithy_print.hpp>
|
||||||
|
|
||||||
SrsVodStream::SrsVodStream(string root_dir)
|
SrsVodStream::SrsVodStream(string root_dir)
|
||||||
: SrsGoHttpFileServer(root_dir)
|
: SrsHttpFileServer(root_dir)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ SrsVodStream::~SrsVodStream()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int offset)
|
int SrsVodStream::serve_flv_stream(ISrsHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int offset)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsVodStream::serve_mp4_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int start, int end)
|
int SrsVodStream::serve_mp4_stream(ISrsHttpResponseWriter* w, SrsHttpMessage* r, string fullpath, int start, int end)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -517,7 +517,7 @@ int SrsMp3StreamEncoder::dump_cache(SrsConsumer* consumer)
|
||||||
return cache->dump_cache(consumer);
|
return cache->dump_cache(consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsStreamWriter::SrsStreamWriter(ISrsGoHttpResponseWriter* w)
|
SrsStreamWriter::SrsStreamWriter(ISrsHttpResponseWriter* w)
|
||||||
{
|
{
|
||||||
writer = w;
|
writer = w;
|
||||||
}
|
}
|
||||||
|
@ -565,7 +565,7 @@ SrsLiveStream::~SrsLiveStream()
|
||||||
srs_freep(req);
|
srs_freep(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -708,7 +708,7 @@ void SrsHlsM3u8Stream::set_m3u8(std::string v)
|
||||||
m3u8 = v;
|
m3u8 = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHlsM3u8Stream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsHlsM3u8Stream::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -740,7 +740,7 @@ void SrsHlsTsStream::set_ts(std::string v)
|
||||||
ts = v;
|
ts = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHlsTsStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsHlsTsStream::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -879,9 +879,9 @@ int SrsHttpServer::mount_hls(SrsRequest* r)
|
||||||
SrsHlsEntry* entry = hls[r->vhost];
|
SrsHlsEntry* entry = hls[r->vhost];
|
||||||
|
|
||||||
// TODO: FIXME: supports reload.
|
// TODO: FIXME: supports reload.
|
||||||
std::map<std::string, ISrsGoHttpHandler*>::iterator it;
|
std::map<std::string, ISrsHttpHandler*>::iterator it;
|
||||||
for (it = entry->streams.begin(); it != entry->streams.end(); ++it) {
|
for (it = entry->streams.begin(); it != entry->streams.end(); ++it) {
|
||||||
ISrsGoHttpHandler* stream = it->second;
|
ISrsHttpHandler* stream = it->second;
|
||||||
stream->entry->enabled = true;
|
stream->entry->enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -911,7 +911,7 @@ int SrsHttpServer::hls_update_m3u8(SrsRequest* r, string m3u8)
|
||||||
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
|
mount = srs_string_replace(mount, SRS_CONSTS_RTMP_DEFAULT_VHOST"/", "/");
|
||||||
|
|
||||||
if (entry->streams.find(mount) == entry->streams.end()) {
|
if (entry->streams.find(mount) == entry->streams.end()) {
|
||||||
ISrsGoHttpHandler* he = new SrsHlsM3u8Stream();
|
ISrsHttpHandler* he = new SrsHlsM3u8Stream();
|
||||||
entry->streams[mount] = he;
|
entry->streams[mount] = he;
|
||||||
|
|
||||||
if ((ret = mux.handle(mount, he)) != ERROR_SUCCESS) {
|
if ((ret = mux.handle(mount, he)) != ERROR_SUCCESS) {
|
||||||
|
@ -962,7 +962,7 @@ int SrsHttpServer::hls_update_ts(SrsRequest* r, string uri, string ts)
|
||||||
mount += uri;
|
mount += uri;
|
||||||
|
|
||||||
if (entry->streams.find(mount) == entry->streams.end()) {
|
if (entry->streams.find(mount) == entry->streams.end()) {
|
||||||
ISrsGoHttpHandler* he = new SrsHlsTsStream();
|
ISrsHttpHandler* he = new SrsHlsTsStream();
|
||||||
entry->streams[mount] = he;
|
entry->streams[mount] = he;
|
||||||
|
|
||||||
if ((ret = mux.handle(mount, he)) != ERROR_SUCCESS) {
|
if ((ret = mux.handle(mount, he)) != ERROR_SUCCESS) {
|
||||||
|
@ -990,9 +990,9 @@ void SrsHttpServer::unmount_hls(SrsRequest* r)
|
||||||
|
|
||||||
SrsHlsEntry* entry = hls[r->vhost];
|
SrsHlsEntry* entry = hls[r->vhost];
|
||||||
|
|
||||||
std::map<std::string, ISrsGoHttpHandler*>::iterator it;
|
std::map<std::string, ISrsHttpHandler*>::iterator it;
|
||||||
for (it = entry->streams.begin(); it != entry->streams.end(); ++it) {
|
for (it = entry->streams.begin(); it != entry->streams.end(); ++it) {
|
||||||
ISrsGoHttpHandler* stream = it->second;
|
ISrsHttpHandler* stream = it->second;
|
||||||
stream->entry->enabled = false;
|
stream->entry->enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1202,7 +1202,7 @@ int SrsHttpConn::do_cycle()
|
||||||
SrsAutoFree(SrsHttpMessage, req);
|
SrsAutoFree(SrsHttpMessage, req);
|
||||||
|
|
||||||
// ok, handle http request.
|
// ok, handle http request.
|
||||||
SrsGoHttpResponseWriter writer(&skt);
|
SrsHttpResponseWriter writer(&skt);
|
||||||
if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
|
if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1211,7 +1211,7 @@ int SrsHttpConn::do_cycle()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHttpConn::process_request(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
|
int SrsHttpConn::process_request(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -59,14 +59,14 @@ class SrsSharedPtrMessage;
|
||||||
* server will write flv header and sequence header,
|
* server will write flv header and sequence header,
|
||||||
* then seek(10240) and response flv tag data.
|
* then seek(10240) and response flv tag data.
|
||||||
*/
|
*/
|
||||||
class SrsVodStream : public SrsGoHttpFileServer
|
class SrsVodStream : public SrsHttpFileServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsVodStream(std::string root_dir);
|
SrsVodStream(std::string root_dir);
|
||||||
virtual ~SrsVodStream();
|
virtual ~SrsVodStream();
|
||||||
protected:
|
protected:
|
||||||
virtual int serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int offset);
|
virtual int serve_flv_stream(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int offset);
|
||||||
virtual int serve_mp4_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int start, int end);
|
virtual int serve_mp4_stream(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int start, int end);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,9 +214,9 @@ public:
|
||||||
class SrsStreamWriter : public SrsFileWriter
|
class SrsStreamWriter : public SrsFileWriter
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
ISrsGoHttpResponseWriter* writer;
|
ISrsHttpResponseWriter* writer;
|
||||||
public:
|
public:
|
||||||
SrsStreamWriter(ISrsGoHttpResponseWriter* w);
|
SrsStreamWriter(ISrsHttpResponseWriter* w);
|
||||||
virtual ~SrsStreamWriter();
|
virtual ~SrsStreamWriter();
|
||||||
public:
|
public:
|
||||||
virtual int open(std::string file);
|
virtual int open(std::string file);
|
||||||
|
@ -232,7 +232,7 @@ public:
|
||||||
* the flv live stream supports access rtmp in flv over http.
|
* the flv live stream supports access rtmp in flv over http.
|
||||||
* srs will remux rtmp to flv streaming.
|
* srs will remux rtmp to flv streaming.
|
||||||
*/
|
*/
|
||||||
class SrsLiveStream : public ISrsGoHttpHandler
|
class SrsLiveStream : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsRequest* req;
|
SrsRequest* req;
|
||||||
|
@ -242,7 +242,7 @@ public:
|
||||||
SrsLiveStream(SrsSource* s, SrsRequest* r, SrsStreamCache* c);
|
SrsLiveStream(SrsSource* s, SrsRequest* r, SrsStreamCache* c);
|
||||||
virtual ~SrsLiveStream();
|
virtual ~SrsLiveStream();
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
private:
|
private:
|
||||||
virtual int streaming_send_messages(ISrsStreamEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs);
|
virtual int streaming_send_messages(ISrsStreamEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs);
|
||||||
};
|
};
|
||||||
|
@ -263,7 +263,7 @@ struct SrsLiveEntry
|
||||||
/**
|
/**
|
||||||
* the m3u8 stream handler.
|
* the m3u8 stream handler.
|
||||||
*/
|
*/
|
||||||
class SrsHlsM3u8Stream : public ISrsGoHttpHandler
|
class SrsHlsM3u8Stream : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string m3u8;
|
std::string m3u8;
|
||||||
|
@ -273,13 +273,13 @@ public:
|
||||||
public:
|
public:
|
||||||
virtual void set_m3u8(std::string v);
|
virtual void set_m3u8(std::string v);
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the ts stream handler.
|
* the ts stream handler.
|
||||||
*/
|
*/
|
||||||
class SrsHlsTsStream : public ISrsGoHttpHandler
|
class SrsHlsTsStream : public ISrsHttpHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::string ts;
|
std::string ts;
|
||||||
|
@ -289,7 +289,7 @@ public:
|
||||||
public:
|
public:
|
||||||
virtual void set_ts(std::string v);
|
virtual void set_ts(std::string v);
|
||||||
public:
|
public:
|
||||||
virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -302,7 +302,7 @@ struct SrsHlsEntry
|
||||||
|
|
||||||
// key: the m3u8/ts file path.
|
// key: the m3u8/ts file path.
|
||||||
// value: the http handler.
|
// value: the http handler.
|
||||||
std::map<std::string, ISrsGoHttpHandler*> streams;
|
std::map<std::string, ISrsHttpHandler*> streams;
|
||||||
|
|
||||||
SrsHlsEntry();
|
SrsHlsEntry();
|
||||||
};
|
};
|
||||||
|
@ -314,7 +314,7 @@ struct SrsHlsEntry
|
||||||
class SrsHttpServer : public ISrsReloadHandler
|
class SrsHttpServer : public ISrsReloadHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SrsGoHttpServeMux mux;
|
SrsHttpServeMux mux;
|
||||||
// the flv live streaming template.
|
// the flv live streaming template.
|
||||||
std::map<std::string, SrsLiveEntry*> flvs;
|
std::map<std::string, SrsLiveEntry*> flvs;
|
||||||
// the hls live streaming template.
|
// the hls live streaming template.
|
||||||
|
@ -362,7 +362,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual int do_cycle();
|
virtual int do_cycle();
|
||||||
private:
|
private:
|
||||||
virtual int process_request(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
|
virtual int process_request(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -398,7 +398,7 @@ SrsServer::SrsServer()
|
||||||
// for some global instance is not ready now,
|
// for some global instance is not ready now,
|
||||||
// new these objects in initialize instead.
|
// new these objects in initialize instead.
|
||||||
#ifdef SRS_AUTO_HTTP_API
|
#ifdef SRS_AUTO_HTTP_API
|
||||||
http_api_mux = new SrsGoHttpServeMux();
|
http_api_mux = new SrsHttpServeMux();
|
||||||
#endif
|
#endif
|
||||||
#ifdef SRS_AUTO_HTTP_SERVER
|
#ifdef SRS_AUTO_HTTP_SERVER
|
||||||
http_stream_mux = new SrsHttpServer();
|
http_stream_mux = new SrsHttpServer();
|
||||||
|
|
|
@ -41,7 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
class SrsServer;
|
class SrsServer;
|
||||||
class SrsConnection;
|
class SrsConnection;
|
||||||
class SrsGoHttpServeMux;
|
class SrsHttpServeMux;
|
||||||
class SrsHttpServer;
|
class SrsHttpServer;
|
||||||
class SrsIngester;
|
class SrsIngester;
|
||||||
class SrsHttpHeartbeat;
|
class SrsHttpHeartbeat;
|
||||||
|
@ -178,7 +178,7 @@ class SrsServer : virtual public ISrsReloadHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
#ifdef SRS_AUTO_HTTP_API
|
#ifdef SRS_AUTO_HTTP_API
|
||||||
SrsGoHttpServeMux* http_api_mux;
|
SrsHttpServeMux* http_api_mux;
|
||||||
#endif
|
#endif
|
||||||
#ifdef SRS_AUTO_HTTP_SERVER
|
#ifdef SRS_AUTO_HTTP_SERVER
|
||||||
SrsHttpServer* http_stream_mux;
|
SrsHttpServer* http_stream_mux;
|
||||||
|
|
Loading…
Reference in a new issue