mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +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"
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,8 +47,8 @@ class SrsHttpUri;
 | 
			
		|||
class SrsHttpMessage;
 | 
			
		||||
class SrsFileReader;
 | 
			
		||||
class SrsSimpleBuffer;
 | 
			
		||||
class SrsGoHttpMuxEntry;
 | 
			
		||||
class ISrsGoHttpResponseWriter;
 | 
			
		||||
class SrsHttpMuxEntry;
 | 
			
		||||
class ISrsHttpResponseWriter;
 | 
			
		||||
 | 
			
		||||
// http specification
 | 
			
		||||
// CR             = <US-ASCII CR, carriage return (13)>
 | 
			
		||||
| 
						 | 
				
			
			@ -70,7 +70,7 @@ class ISrsGoHttpResponseWriter;
 | 
			
		|||
#define __SRS_HTTP_TS_SEND_BUFFER_SIZE 4096
 | 
			
		||||
 | 
			
		||||
// 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
 | 
			
		||||
enum SrsHttpParseState {
 | 
			
		||||
| 
						 | 
				
			
			@ -80,13 +80,13 @@ enum SrsHttpParseState {
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
// A Header represents the key-value pairs in an HTTP header.
 | 
			
		||||
class SrsGoHttpHeader
 | 
			
		||||
class SrsHttpHeader
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    std::map<std::string, std::string> headers;
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoHttpHeader();
 | 
			
		||||
    virtual ~SrsGoHttpHeader();
 | 
			
		||||
    SrsHttpHeader();
 | 
			
		||||
    virtual ~SrsHttpHeader();
 | 
			
		||||
public:
 | 
			
		||||
    // Add adds the key, value pair to the header.
 | 
			
		||||
    // It appends to any existing values associated with key.
 | 
			
		||||
| 
						 | 
				
			
			@ -124,7 +124,7 @@ public:
 | 
			
		|||
// A ResponseWriter interface is used by an HTTP handler to
 | 
			
		||||
// construct an HTTP response.
 | 
			
		||||
// Usage 1, response with specified length content:
 | 
			
		||||
//      ISrsGoHttpResponseWriter* w; // create or get response.
 | 
			
		||||
//      ISrsHttpResponseWriter* w; // create or get response.
 | 
			
		||||
//      std::string msg = "Hello, HTTP!";
 | 
			
		||||
//      w->header()->set_content_type("text/plain; charset=utf-8");
 | 
			
		||||
//      w->header()->set_content_length(msg.length());
 | 
			
		||||
| 
						 | 
				
			
			@ -132,12 +132,12 @@ public:
 | 
			
		|||
//      w->write((char*)msg.data(), (int)msg.length());
 | 
			
		||||
//      w->final_request(); // optional flush.
 | 
			
		||||
// 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->write_header(SRS_CONSTS_HTTP_OK);
 | 
			
		||||
//      w->final_request();
 | 
			
		||||
// Usage 3, response in chunked encoding.
 | 
			
		||||
//      ISrsGoHttpResponseWriter* w; // create or get response.
 | 
			
		||||
//      ISrsHttpResponseWriter* w; // create or get response.
 | 
			
		||||
//      std::string msg = "Hello, HTTP!";
 | 
			
		||||
//      w->header()->set_content_type("application/octet-stream");
 | 
			
		||||
//      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->final_request(); // required to end the chunked and flush.
 | 
			
		||||
class ISrsGoHttpResponseWriter
 | 
			
		||||
class ISrsHttpResponseWriter
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    ISrsGoHttpResponseWriter();
 | 
			
		||||
    virtual ~ISrsGoHttpResponseWriter();
 | 
			
		||||
    ISrsHttpResponseWriter();
 | 
			
		||||
    virtual ~ISrsHttpResponseWriter();
 | 
			
		||||
public:
 | 
			
		||||
    // when chunked mode, 
 | 
			
		||||
    // final the request to complete the chunked encoding.
 | 
			
		||||
| 
						 | 
				
			
			@ -159,7 +159,7 @@ public:
 | 
			
		|||
    // Header returns the header map that will be sent by WriteHeader.
 | 
			
		||||
    // Changing the header after a call to WriteHeader (or Write) has
 | 
			
		||||
    // no effect.
 | 
			
		||||
    virtual SrsGoHttpHeader* header() = 0;
 | 
			
		||||
    virtual SrsHttpHeader* header() = 0;
 | 
			
		||||
    
 | 
			
		||||
    // 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)
 | 
			
		||||
| 
						 | 
				
			
			@ -186,38 +186,38 @@ public:
 | 
			
		|||
// and then return.  Returning signals that the request is finished
 | 
			
		||||
// and that the HTTP server can move on to the next request on
 | 
			
		||||
// the connection.
 | 
			
		||||
class ISrsGoHttpHandler
 | 
			
		||||
class ISrsHttpHandler
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoHttpMuxEntry* entry;
 | 
			
		||||
    SrsHttpMuxEntry* entry;
 | 
			
		||||
public:
 | 
			
		||||
    ISrsGoHttpHandler();
 | 
			
		||||
    virtual ~ISrsGoHttpHandler();
 | 
			
		||||
    ISrsHttpHandler();
 | 
			
		||||
    virtual ~ISrsHttpHandler();
 | 
			
		||||
public:
 | 
			
		||||
    virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) = 0;
 | 
			
		||||
    virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r) = 0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// Redirect to a fixed URL
 | 
			
		||||
class SrsGoHttpRedirectHandler : public ISrsGoHttpHandler
 | 
			
		||||
class SrsHttpRedirectHandler : public ISrsHttpHandler
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    std::string url;
 | 
			
		||||
    int code;
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoHttpRedirectHandler(std::string u, int c);
 | 
			
		||||
    virtual ~SrsGoHttpRedirectHandler();
 | 
			
		||||
    SrsHttpRedirectHandler(std::string u, int c);
 | 
			
		||||
    virtual ~SrsHttpRedirectHandler();
 | 
			
		||||
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.
 | 
			
		||||
class SrsGoHttpNotFoundHandler : public ISrsGoHttpHandler
 | 
			
		||||
class SrsHttpNotFoundHandler : public ISrsHttpHandler
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoHttpNotFoundHandler();
 | 
			
		||||
    virtual ~SrsGoHttpNotFoundHandler();
 | 
			
		||||
    SrsHttpNotFoundHandler();
 | 
			
		||||
    virtual ~SrsHttpNotFoundHandler();
 | 
			
		||||
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
 | 
			
		||||
| 
						 | 
				
			
			@ -226,54 +226,54 @@ public:
 | 
			
		|||
// To use the operating system's file system implementation,
 | 
			
		||||
// use http.Dir:
 | 
			
		||||
//
 | 
			
		||||
//     http.Handle("/", SrsGoHttpFileServer("/tmp"))
 | 
			
		||||
//     http.Handle("/", SrsGoHttpFileServer("static-dir"))
 | 
			
		||||
class SrsGoHttpFileServer : public ISrsGoHttpHandler
 | 
			
		||||
//     http.Handle("/", SrsHttpFileServer("/tmp"))
 | 
			
		||||
//     http.Handle("/", SrsHttpFileServer("static-dir"))
 | 
			
		||||
class SrsHttpFileServer : public ISrsHttpHandler
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
    std::string dir;
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoHttpFileServer(std::string root_dir);
 | 
			
		||||
    virtual ~SrsGoHttpFileServer();
 | 
			
		||||
    SrsHttpFileServer(std::string root_dir);
 | 
			
		||||
    virtual ~SrsHttpFileServer();
 | 
			
		||||
public:
 | 
			
		||||
    virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
    virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
private:
 | 
			
		||||
    /**
 | 
			
		||||
    * serve the file by specified path
 | 
			
		||||
    */
 | 
			
		||||
    virtual int serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
 | 
			
		||||
    virtual int serve_flv_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
 | 
			
		||||
    virtual int serve_mp4_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
 | 
			
		||||
    virtual int serve_file(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
 | 
			
		||||
    virtual int serve_flv_file(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
 | 
			
		||||
    virtual int serve_mp4_file(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath);
 | 
			
		||||
protected:
 | 
			
		||||
    /**
 | 
			
		||||
    * 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
 | 
			
		||||
    * @param start the start offset in bytes.
 | 
			
		||||
    * @param end the end offset in bytes. -1 to end of file.
 | 
			
		||||
    * @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:
 | 
			
		||||
    /**
 | 
			
		||||
    * 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.
 | 
			
		||||
class SrsGoHttpMuxEntry
 | 
			
		||||
class SrsHttpMuxEntry
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    bool explicit_match;
 | 
			
		||||
    ISrsGoHttpHandler* handler;
 | 
			
		||||
    ISrsHttpHandler* handler;
 | 
			
		||||
    std::string pattern;
 | 
			
		||||
    bool enabled;
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoHttpMuxEntry();
 | 
			
		||||
    virtual ~SrsGoHttpMuxEntry();
 | 
			
		||||
    SrsHttpMuxEntry();
 | 
			
		||||
    virtual ~SrsHttpMuxEntry();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
// ServeMux is an HTTP request multiplexer.
 | 
			
		||||
| 
						 | 
				
			
			@ -303,16 +303,16 @@ public:
 | 
			
		|||
// ServeMux also takes care of sanitizing the URL request path,
 | 
			
		||||
// redirecting any request containing . or .. elements to an
 | 
			
		||||
// equivalent .- and ..-free URL.
 | 
			
		||||
class SrsGoHttpServeMux
 | 
			
		||||
class SrsHttpServeMux
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    // the pattern handler.
 | 
			
		||||
    std::map<std::string, SrsGoHttpMuxEntry*> entries;
 | 
			
		||||
    std::map<std::string, SrsHttpMuxEntry*> entries;
 | 
			
		||||
    // the vhost handler.
 | 
			
		||||
    std::map<std::string, ISrsGoHttpHandler*> vhosts;
 | 
			
		||||
    std::map<std::string, ISrsHttpHandler*> vhosts;
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoHttpServeMux();
 | 
			
		||||
    virtual ~SrsGoHttpServeMux();
 | 
			
		||||
    SrsHttpServeMux();
 | 
			
		||||
    virtual ~SrsHttpServeMux();
 | 
			
		||||
public:
 | 
			
		||||
    /**
 | 
			
		||||
    * initialize the http serve mux.
 | 
			
		||||
| 
						 | 
				
			
			@ -321,24 +321,24 @@ public:
 | 
			
		|||
public:
 | 
			
		||||
    // Handle registers the handler for the given pattern.
 | 
			
		||||
    // If a handler already exists for pattern, Handle panics.
 | 
			
		||||
    virtual int handle(std::string pattern, ISrsGoHttpHandler* handler);
 | 
			
		||||
// interface ISrsGoHttpHandler
 | 
			
		||||
    virtual int handle(std::string pattern, ISrsHttpHandler* handler);
 | 
			
		||||
// interface ISrsHttpHandler
 | 
			
		||||
public:
 | 
			
		||||
    virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
    virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
private:
 | 
			
		||||
    virtual int find_handler(SrsHttpMessage* r, ISrsGoHttpHandler** ph);
 | 
			
		||||
    virtual int match(SrsHttpMessage* r, ISrsGoHttpHandler** ph);
 | 
			
		||||
    virtual int find_handler(SrsHttpMessage* r, ISrsHttpHandler** ph);
 | 
			
		||||
    virtual int match(SrsHttpMessage* r, ISrsHttpHandler** ph);
 | 
			
		||||
    virtual bool path_match(std::string pattern, std::string path);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* response writer use st socket
 | 
			
		||||
*/
 | 
			
		||||
class SrsGoHttpResponseWriter : public ISrsGoHttpResponseWriter
 | 
			
		||||
class SrsHttpResponseWriter : public ISrsHttpResponseWriter
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    SrsStSocket* skt;
 | 
			
		||||
    SrsGoHttpHeader* hdr;
 | 
			
		||||
    SrsHttpHeader* hdr;
 | 
			
		||||
private:
 | 
			
		||||
    // reply header has been (logically) written
 | 
			
		||||
    bool header_wrote;
 | 
			
		||||
| 
						 | 
				
			
			@ -356,11 +356,11 @@ private:
 | 
			
		|||
    // logically written.
 | 
			
		||||
    bool header_sent;
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoHttpResponseWriter(SrsStSocket* io);
 | 
			
		||||
    virtual ~SrsGoHttpResponseWriter();
 | 
			
		||||
    SrsHttpResponseWriter(SrsStSocket* io);
 | 
			
		||||
    virtual ~SrsHttpResponseWriter();
 | 
			
		||||
public:
 | 
			
		||||
    virtual int final_request();
 | 
			
		||||
    virtual SrsGoHttpHeader* header();
 | 
			
		||||
    virtual SrsHttpHeader* header();
 | 
			
		||||
    virtual int write(char* data, int size);
 | 
			
		||||
    virtual void write_header(int code);
 | 
			
		||||
    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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
    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;
 | 
			
		||||
    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());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SrsHttpApi::SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsGoHttpServeMux* m) 
 | 
			
		||||
SrsHttpApi::SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsHttpServeMux* m) 
 | 
			
		||||
    : SrsConnection(svr, fd)
 | 
			
		||||
{
 | 
			
		||||
    mux = m;
 | 
			
		||||
| 
						 | 
				
			
			@ -535,7 +535,7 @@ int SrsHttpApi::do_cycle()
 | 
			
		|||
        SrsAutoFree(SrsHttpMessage, req);
 | 
			
		||||
        
 | 
			
		||||
        // ok, handle http request.
 | 
			
		||||
        SrsGoHttpResponseWriter writer(&skt);
 | 
			
		||||
        SrsHttpResponseWriter writer(&skt);
 | 
			
		||||
        if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -544,7 +544,7 @@ int SrsHttpApi::do_cycle()
 | 
			
		|||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SrsHttpApi::process_request(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) 
 | 
			
		||||
int SrsHttpApi::process_request(ISrsHttpResponseWriter* w, SrsHttpMessage* r) 
 | 
			
		||||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,131 +42,131 @@ class SrsHttpHandler;
 | 
			
		|||
#include <srs_app_http.hpp>
 | 
			
		||||
 | 
			
		||||
// for http root.
 | 
			
		||||
class SrsGoApiRoot : public ISrsGoHttpHandler
 | 
			
		||||
class SrsGoApiRoot : public ISrsHttpHandler
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoApiRoot();
 | 
			
		||||
    virtual ~SrsGoApiRoot();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiApi();
 | 
			
		||||
    virtual ~SrsGoApiApi();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiV1();
 | 
			
		||||
    virtual ~SrsGoApiV1();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiVersion();
 | 
			
		||||
    virtual ~SrsGoApiVersion();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiSummaries();
 | 
			
		||||
    virtual ~SrsGoApiSummaries();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiRusages();
 | 
			
		||||
    virtual ~SrsGoApiRusages();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiSelfProcStats();
 | 
			
		||||
    virtual ~SrsGoApiSelfProcStats();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiSystemProcStats();
 | 
			
		||||
    virtual ~SrsGoApiSystemProcStats();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiMemInfos();
 | 
			
		||||
    virtual ~SrsGoApiMemInfos();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiAuthors();
 | 
			
		||||
    virtual ~SrsGoApiAuthors();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiRequests();
 | 
			
		||||
    virtual ~SrsGoApiRequests();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiVhosts();
 | 
			
		||||
    virtual ~SrsGoApiVhosts();
 | 
			
		||||
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:
 | 
			
		||||
    SrsGoApiStreams();
 | 
			
		||||
    virtual ~SrsGoApiStreams();
 | 
			
		||||
public:
 | 
			
		||||
    virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
    virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SrsHttpApi : public SrsConnection
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    SrsHttpParser* parser;
 | 
			
		||||
    SrsGoHttpServeMux* mux;
 | 
			
		||||
    SrsHttpServeMux* mux;
 | 
			
		||||
    bool crossdomain_required;
 | 
			
		||||
public:
 | 
			
		||||
    SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsGoHttpServeMux* m);
 | 
			
		||||
    SrsHttpApi(SrsServer* svr, st_netfd_t fd, SrsHttpServeMux* m);
 | 
			
		||||
    virtual ~SrsHttpApi();
 | 
			
		||||
public:
 | 
			
		||||
    virtual void kbps_resample();
 | 
			
		||||
| 
						 | 
				
			
			@ -177,7 +177,7 @@ public:
 | 
			
		|||
protected:
 | 
			
		||||
    virtual int do_cycle();
 | 
			
		||||
private:
 | 
			
		||||
    virtual int process_request(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
    virtual int process_request(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,7 +50,7 @@ using namespace std;
 | 
			
		|||
#include <srs_app_pithy_print.hpp>
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -142,7 +142,7 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
 | 
			
		|||
    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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -517,7 +517,7 @@ int SrsMp3StreamEncoder::dump_cache(SrsConsumer* consumer)
 | 
			
		|||
    return cache->dump_cache(consumer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SrsStreamWriter::SrsStreamWriter(ISrsGoHttpResponseWriter* w)
 | 
			
		||||
SrsStreamWriter::SrsStreamWriter(ISrsHttpResponseWriter* w)
 | 
			
		||||
{
 | 
			
		||||
    writer = w;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -565,7 +565,7 @@ SrsLiveStream::~SrsLiveStream()
 | 
			
		|||
    srs_freep(req);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SrsLiveStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
 | 
			
		||||
int SrsLiveStream::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
 | 
			
		||||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -708,7 +708,7 @@ void SrsHlsM3u8Stream::set_m3u8(std::string v)
 | 
			
		|||
    m3u8 = v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SrsHlsM3u8Stream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
 | 
			
		||||
int SrsHlsM3u8Stream::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
 | 
			
		||||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -740,7 +740,7 @@ void SrsHlsTsStream::set_ts(std::string v)
 | 
			
		|||
    ts = v;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SrsHlsTsStream::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
 | 
			
		||||
int SrsHlsTsStream::serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r)
 | 
			
		||||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			@ -879,9 +879,9 @@ int SrsHttpServer::mount_hls(SrsRequest* r)
 | 
			
		|||
    SrsHlsEntry* entry = hls[r->vhost];
 | 
			
		||||
    
 | 
			
		||||
    // 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) {
 | 
			
		||||
        ISrsGoHttpHandler* stream = it->second;
 | 
			
		||||
        ISrsHttpHandler* stream = it->second;
 | 
			
		||||
        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"/", "/");
 | 
			
		||||
 | 
			
		||||
    if (entry->streams.find(mount) == entry->streams.end()) {
 | 
			
		||||
        ISrsGoHttpHandler* he = new SrsHlsM3u8Stream();
 | 
			
		||||
        ISrsHttpHandler* he = new SrsHlsM3u8Stream();
 | 
			
		||||
        entry->streams[mount] = he;
 | 
			
		||||
 | 
			
		||||
        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;
 | 
			
		||||
 | 
			
		||||
    if (entry->streams.find(mount) == entry->streams.end()) {
 | 
			
		||||
        ISrsGoHttpHandler* he = new SrsHlsTsStream();
 | 
			
		||||
        ISrsHttpHandler* he = new SrsHlsTsStream();
 | 
			
		||||
        entry->streams[mount] = he;
 | 
			
		||||
 | 
			
		||||
        if ((ret = mux.handle(mount, he)) != ERROR_SUCCESS) {
 | 
			
		||||
| 
						 | 
				
			
			@ -990,9 +990,9 @@ void SrsHttpServer::unmount_hls(SrsRequest* r)
 | 
			
		|||
 | 
			
		||||
    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) {
 | 
			
		||||
        ISrsGoHttpHandler* stream = it->second;
 | 
			
		||||
        ISrsHttpHandler* stream = it->second;
 | 
			
		||||
        stream->entry->enabled = false;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1202,7 +1202,7 @@ int SrsHttpConn::do_cycle()
 | 
			
		|||
        SrsAutoFree(SrsHttpMessage, req);
 | 
			
		||||
        
 | 
			
		||||
        // ok, handle http request.
 | 
			
		||||
        SrsGoHttpResponseWriter writer(&skt);
 | 
			
		||||
        SrsHttpResponseWriter writer(&skt);
 | 
			
		||||
        if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1211,7 +1211,7 @@ int SrsHttpConn::do_cycle()
 | 
			
		|||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int SrsHttpConn::process_request(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r) 
 | 
			
		||||
int SrsHttpConn::process_request(ISrsHttpResponseWriter* w, SrsHttpMessage* r) 
 | 
			
		||||
{
 | 
			
		||||
    int ret = ERROR_SUCCESS;
 | 
			
		||||
    
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,14 +59,14 @@ class SrsSharedPtrMessage;
 | 
			
		|||
* server will write flv header and sequence header, 
 | 
			
		||||
* then seek(10240) and response flv tag data.
 | 
			
		||||
*/
 | 
			
		||||
class SrsVodStream : public SrsGoHttpFileServer
 | 
			
		||||
class SrsVodStream : public SrsHttpFileServer
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SrsVodStream(std::string root_dir);
 | 
			
		||||
    virtual ~SrsVodStream();
 | 
			
		||||
protected:
 | 
			
		||||
    virtual int serve_flv_stream(ISrsGoHttpResponseWriter* 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_flv_stream(ISrsHttpResponseWriter* w, SrsHttpMessage* r, std::string fullpath, int offset);
 | 
			
		||||
    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
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    ISrsGoHttpResponseWriter* writer;
 | 
			
		||||
    ISrsHttpResponseWriter* writer;
 | 
			
		||||
public:
 | 
			
		||||
    SrsStreamWriter(ISrsGoHttpResponseWriter* w);
 | 
			
		||||
    SrsStreamWriter(ISrsHttpResponseWriter* w);
 | 
			
		||||
    virtual ~SrsStreamWriter();
 | 
			
		||||
public:
 | 
			
		||||
    virtual int open(std::string file);
 | 
			
		||||
| 
						 | 
				
			
			@ -232,7 +232,7 @@ public:
 | 
			
		|||
* the flv live stream supports access rtmp in flv over http.
 | 
			
		||||
* srs will remux rtmp to flv streaming.
 | 
			
		||||
*/
 | 
			
		||||
class SrsLiveStream : public ISrsGoHttpHandler
 | 
			
		||||
class SrsLiveStream : public ISrsHttpHandler
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    SrsRequest* req;
 | 
			
		||||
| 
						 | 
				
			
			@ -242,7 +242,7 @@ public:
 | 
			
		|||
    SrsLiveStream(SrsSource* s, SrsRequest* r, SrsStreamCache* c);
 | 
			
		||||
    virtual ~SrsLiveStream();
 | 
			
		||||
public:
 | 
			
		||||
    virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
    virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
private:
 | 
			
		||||
    virtual int streaming_send_messages(ISrsStreamEncoder* enc, SrsSharedPtrMessage** msgs, int nb_msgs);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -263,7 +263,7 @@ struct SrsLiveEntry
 | 
			
		|||
/**
 | 
			
		||||
* the m3u8 stream handler.
 | 
			
		||||
*/
 | 
			
		||||
class SrsHlsM3u8Stream : public ISrsGoHttpHandler
 | 
			
		||||
class SrsHlsM3u8Stream : public ISrsHttpHandler
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    std::string m3u8;
 | 
			
		||||
| 
						 | 
				
			
			@ -273,13 +273,13 @@ public:
 | 
			
		|||
public:
 | 
			
		||||
    virtual void set_m3u8(std::string v);
 | 
			
		||||
public:
 | 
			
		||||
    virtual int serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
    virtual int serve_http(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
* the ts stream handler.
 | 
			
		||||
*/
 | 
			
		||||
class SrsHlsTsStream : public ISrsGoHttpHandler
 | 
			
		||||
class SrsHlsTsStream : public ISrsHttpHandler
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    std::string ts;
 | 
			
		||||
| 
						 | 
				
			
			@ -289,7 +289,7 @@ public:
 | 
			
		|||
public:
 | 
			
		||||
    virtual void set_ts(std::string v);
 | 
			
		||||
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.
 | 
			
		||||
    // value: the http handler.
 | 
			
		||||
    std::map<std::string, ISrsGoHttpHandler*> streams;
 | 
			
		||||
    std::map<std::string, ISrsHttpHandler*> streams;
 | 
			
		||||
    
 | 
			
		||||
    SrsHlsEntry();
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -314,7 +314,7 @@ struct SrsHlsEntry
 | 
			
		|||
class SrsHttpServer : public ISrsReloadHandler
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SrsGoHttpServeMux mux;
 | 
			
		||||
    SrsHttpServeMux mux;
 | 
			
		||||
    // the flv live streaming template.
 | 
			
		||||
    std::map<std::string, SrsLiveEntry*> flvs;
 | 
			
		||||
    // the hls live streaming template.
 | 
			
		||||
| 
						 | 
				
			
			@ -362,7 +362,7 @@ public:
 | 
			
		|||
protected:
 | 
			
		||||
    virtual int do_cycle();
 | 
			
		||||
private:
 | 
			
		||||
    virtual int process_request(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
    virtual int process_request(ISrsHttpResponseWriter* w, SrsHttpMessage* r);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -398,7 +398,7 @@ SrsServer::SrsServer()
 | 
			
		|||
    // for some global instance is not ready now,
 | 
			
		||||
    // new these objects in initialize instead.
 | 
			
		||||
#ifdef SRS_AUTO_HTTP_API
 | 
			
		||||
    http_api_mux = new SrsGoHttpServeMux();
 | 
			
		||||
    http_api_mux = new SrsHttpServeMux();
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef SRS_AUTO_HTTP_SERVER
 | 
			
		||||
    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 SrsConnection;
 | 
			
		||||
class SrsGoHttpServeMux;
 | 
			
		||||
class SrsHttpServeMux;
 | 
			
		||||
class SrsHttpServer;
 | 
			
		||||
class SrsIngester;
 | 
			
		||||
class SrsHttpHeartbeat;
 | 
			
		||||
| 
						 | 
				
			
			@ -178,7 +178,7 @@ class SrsServer : virtual public ISrsReloadHandler
 | 
			
		|||
{
 | 
			
		||||
private:
 | 
			
		||||
#ifdef SRS_AUTO_HTTP_API
 | 
			
		||||
    SrsGoHttpServeMux* http_api_mux;
 | 
			
		||||
    SrsHttpServeMux* http_api_mux;
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef SRS_AUTO_HTTP_SERVER
 | 
			
		||||
    SrsHttpServer* http_stream_mux;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue