mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine http server, support mount dir for vhost.
This commit is contained in:
parent
bfff8413b6
commit
4513486266
4 changed files with 41 additions and 2 deletions
17
trunk/conf/http.server.conf
Normal file
17
trunk/conf/http.server.conf
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -226,6 +226,7 @@ ISrsGoHttpResponseWriter::~ISrsGoHttpResponseWriter()
|
||||||
|
|
||||||
ISrsGoHttpHandler::ISrsGoHttpHandler()
|
ISrsGoHttpHandler::ISrsGoHttpHandler()
|
||||||
{
|
{
|
||||||
|
entry = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ISrsGoHttpHandler::~ISrsGoHttpHandler()
|
ISrsGoHttpHandler::~ISrsGoHttpHandler()
|
||||||
|
@ -283,7 +284,16 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
||||||
upath += SRS_HTTP_DEFAULT_PAGE;
|
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")) {
|
if (srs_string_ends_with(fullpath, ".flv") || srs_string_ends_with(fullpath, ".fhv")) {
|
||||||
std::string start = r->query_get("start");
|
std::string start = r->query_get("start");
|
||||||
|
@ -437,6 +447,7 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
||||||
entry->explicit_match = true;
|
entry->explicit_match = true;
|
||||||
entry->handler = handler;
|
entry->handler = handler;
|
||||||
entry->pattern = pattern;
|
entry->pattern = pattern;
|
||||||
|
entry->handler->entry = entry;
|
||||||
|
|
||||||
if (entries.find(pattern) != entries.end()) {
|
if (entries.find(pattern) != entries.end()) {
|
||||||
SrsGoHttpMuxEntry* exists = entries[pattern];
|
SrsGoHttpMuxEntry* exists = entries[pattern];
|
||||||
|
@ -448,7 +459,7 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
||||||
// Helpful behavior:
|
// Helpful behavior:
|
||||||
// If pattern is /tree/, insert an implicit permanent redirect for /tree.
|
// If pattern is /tree/, insert an implicit permanent redirect for /tree.
|
||||||
// It can be overridden by an explicit registration.
|
// 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);
|
std::string rpattern = pattern.substr(0, pattern.length() - 1);
|
||||||
SrsGoHttpMuxEntry* entry = NULL;
|
SrsGoHttpMuxEntry* entry = NULL;
|
||||||
|
|
||||||
|
@ -468,6 +479,7 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
||||||
entry->explicit_match = false;
|
entry->explicit_match = false;
|
||||||
entry->handler = new SrsGoHttpRedirectHandler(pattern, SRS_CONSTS_HTTP_MovedPermanently);
|
entry->handler = new SrsGoHttpRedirectHandler(pattern, SRS_CONSTS_HTTP_MovedPermanently);
|
||||||
entry->pattern = pattern;
|
entry->pattern = pattern;
|
||||||
|
entry->handler->entry = entry;
|
||||||
|
|
||||||
entries[rpattern] = entry;
|
entries[rpattern] = entry;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ class SrsHttpUri;
|
||||||
class SrsHttpMessage;
|
class SrsHttpMessage;
|
||||||
class SrsFileReader;
|
class SrsFileReader;
|
||||||
class SrsSimpleBuffer;
|
class SrsSimpleBuffer;
|
||||||
|
class SrsGoHttpMuxEntry;
|
||||||
class ISrsGoHttpResponseWriter;
|
class ISrsGoHttpResponseWriter;
|
||||||
|
|
||||||
// http specification
|
// http specification
|
||||||
|
@ -157,6 +158,8 @@ public:
|
||||||
// the connection.
|
// the connection.
|
||||||
class ISrsGoHttpHandler
|
class ISrsGoHttpHandler
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
SrsGoHttpMuxEntry* entry;
|
||||||
public:
|
public:
|
||||||
ISrsGoHttpHandler();
|
ISrsGoHttpHandler();
|
||||||
virtual ~ISrsGoHttpHandler();
|
virtual ~ISrsGoHttpHandler();
|
||||||
|
|
|
@ -166,6 +166,11 @@ int SrsHttpServer::initialize()
|
||||||
std::string mount = _srs_config->get_vhost_http_mount(vhost);
|
std::string mount = _srs_config->get_vhost_http_mount(vhost);
|
||||||
std::string dir = _srs_config->get_vhost_http_dir(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) {
|
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);
|
srs_error("http: mount dir=%s for vhost=%s failed. ret=%d", dir.c_str(), vhost.c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -173,6 +178,7 @@ int SrsHttpServer::initialize()
|
||||||
|
|
||||||
if (mount == "/") {
|
if (mount == "/") {
|
||||||
default_root_exists = true;
|
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);
|
srs_error("http: mount root dir=%s failed. ret=%d", dir.c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
srs_trace("http: root mount to %s", dir.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue