diff --git a/trunk/conf/http.server.conf b/trunk/conf/http.server.conf new file mode 100644 index 000000000..a56d88b00 --- /dev/null +++ b/trunk/conf/http.server.conf @@ -0,0 +1,17 @@ +# the config for srs to serve as http server +# @see full.conf for detail config. + +listen 1935; +max_connections 1000; +http_stream { + enabled on; + listen 8080; + dir ./objs/nginx/html; +} +vhost __defaultVhost__ { + http { + enabled on; + mount /default; + dir ./objs/nginx/html; + } +} diff --git a/trunk/src/app/srs_app_http.cpp b/trunk/src/app/srs_app_http.cpp index 696198b97..a91c536aa 100644 --- a/trunk/src/app/srs_app_http.cpp +++ b/trunk/src/app/srs_app_http.cpp @@ -226,6 +226,7 @@ ISrsGoHttpResponseWriter::~ISrsGoHttpResponseWriter() ISrsGoHttpHandler::ISrsGoHttpHandler() { + entry = NULL; } ISrsGoHttpHandler::~ISrsGoHttpHandler() @@ -283,7 +284,16 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* upath += SRS_HTTP_DEFAULT_PAGE; } - string fullpath = dir + "/" + upath; + string fullpath = dir + "/"; + + srs_assert(entry); + if (upath.length() > entry->pattern.length()) { + fullpath += upath.substr(entry->pattern.length()); + } else { + fullpath += upath; + } + srs_trace("http match file=%s, pattern=%s, upath=%s", + fullpath.c_str(), entry->pattern.c_str(), upath.c_str()); if (srs_string_ends_with(fullpath, ".flv") || srs_string_ends_with(fullpath, ".fhv")) { std::string start = r->query_get("start"); @@ -437,6 +447,7 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler) entry->explicit_match = true; entry->handler = handler; entry->pattern = pattern; + entry->handler->entry = entry; if (entries.find(pattern) != entries.end()) { SrsGoHttpMuxEntry* exists = entries[pattern]; @@ -448,7 +459,7 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler) // Helpful behavior: // If pattern is /tree/, insert an implicit permanent redirect for /tree. // It can be overridden by an explicit registration. - if (!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); SrsGoHttpMuxEntry* entry = NULL; @@ -468,6 +479,7 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler) entry->explicit_match = false; entry->handler = new SrsGoHttpRedirectHandler(pattern, SRS_CONSTS_HTTP_MovedPermanently); entry->pattern = pattern; + entry->handler->entry = entry; entries[rpattern] = entry; } diff --git a/trunk/src/app/srs_app_http.hpp b/trunk/src/app/srs_app_http.hpp index 952097f20..271f7d35e 100644 --- a/trunk/src/app/srs_app_http.hpp +++ b/trunk/src/app/srs_app_http.hpp @@ -46,6 +46,7 @@ class SrsHttpUri; class SrsHttpMessage; class SrsFileReader; class SrsSimpleBuffer; +class SrsGoHttpMuxEntry; class ISrsGoHttpResponseWriter; // http specification @@ -157,6 +158,8 @@ public: // the connection. class ISrsGoHttpHandler { +public: + SrsGoHttpMuxEntry* entry; public: ISrsGoHttpHandler(); virtual ~ISrsGoHttpHandler(); diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index c60e6badb..7ed8bc7fd 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -166,6 +166,11 @@ int SrsHttpServer::initialize() std::string mount = _srs_config->get_vhost_http_mount(vhost); std::string dir = _srs_config->get_vhost_http_dir(vhost); + // the dir mount must always ends with "/" + if (mount != "/" && mount.rfind("/") != mount.length() - 1) { + mount += "/"; + } + if ((ret = mux.handle(mount, new SrsVodStream(dir))) != ERROR_SUCCESS) { srs_error("http: mount dir=%s for vhost=%s failed. ret=%d", dir.c_str(), vhost.c_str(), ret); return ret; @@ -173,6 +178,7 @@ int SrsHttpServer::initialize() if (mount == "/") { default_root_exists = true; + srs_warn("http: root mount to %s", dir.c_str()); } } @@ -183,6 +189,7 @@ int SrsHttpServer::initialize() srs_error("http: mount root dir=%s failed. ret=%d", dir.c_str(), ret); return ret; } + srs_trace("http: root mount to %s", dir.c_str()); } return ret;