mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #277, support http vhost mount.
This commit is contained in:
parent
4513486266
commit
2742c0d3c2
5 changed files with 32 additions and 11 deletions
|
@ -336,8 +336,8 @@ vhost ingest.srs.com {
|
||||||
# default: off.
|
# default: off.
|
||||||
enabled off;
|
enabled off;
|
||||||
# output stream. variables:
|
# output stream. variables:
|
||||||
# [vhost] current vhost which start the ingest.
|
# [vhost] current vhost which start the ingest.
|
||||||
# [port] system RTMP stream port.
|
# [port] system RTMP stream port.
|
||||||
output rtmp://127.0.0.1:[port]/live?vhost=[vhost]/livestream;
|
output rtmp://127.0.0.1:[port]/live?vhost=[vhost]/livestream;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -351,9 +351,12 @@ vhost http.srs.com {
|
||||||
# default: off
|
# default: off
|
||||||
enabled on;
|
enabled on;
|
||||||
# the virtual directory root for this vhost to mount at
|
# the virtual directory root for this vhost to mount at
|
||||||
# for example, if mount to /hls, user access by http://server/hls
|
# for example, if mount to [vhost]/hls, user access by http://[vhost]/hls
|
||||||
# default: /
|
# the variables:
|
||||||
mount /hls;
|
# [vhost] current vhost for http server.
|
||||||
|
# @remark the http of __defaultVhost__ will override the http_stream section.
|
||||||
|
# default: [vhost]/
|
||||||
|
mount [vhost]/hls;
|
||||||
# main dir of vhost,
|
# main dir of vhost,
|
||||||
# to delivery HTTP stream of this vhost.
|
# to delivery HTTP stream of this vhost.
|
||||||
# default: ./objs/nginx/html
|
# default: ./objs/nginx/html
|
||||||
|
|
|
@ -8,10 +8,10 @@ http_stream {
|
||||||
listen 8080;
|
listen 8080;
|
||||||
dir ./objs/nginx/html;
|
dir ./objs/nginx/html;
|
||||||
}
|
}
|
||||||
vhost __defaultVhost__ {
|
vhost ossrs.net {
|
||||||
http {
|
http {
|
||||||
enabled on;
|
enabled on;
|
||||||
mount /default;
|
mount [vhost]/;
|
||||||
dir ./objs/nginx/html;
|
dir ./objs/nginx/html;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,8 +287,9 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
|
||||||
string fullpath = dir + "/";
|
string fullpath = dir + "/";
|
||||||
|
|
||||||
srs_assert(entry);
|
srs_assert(entry);
|
||||||
if (upath.length() > entry->pattern.length()) {
|
size_t pos = entry->pattern.find("/");
|
||||||
fullpath += upath.substr(entry->pattern.length());
|
if (upath.length() > entry->pattern.length() && pos != string::npos) {
|
||||||
|
fullpath += upath.substr(entry->pattern.length() - pos);
|
||||||
} else {
|
} else {
|
||||||
fullpath += upath;
|
fullpath += upath;
|
||||||
}
|
}
|
||||||
|
@ -402,6 +403,7 @@ SrsGoHttpMuxEntry::~SrsGoHttpMuxEntry()
|
||||||
|
|
||||||
SrsGoHttpServeMux::SrsGoHttpServeMux()
|
SrsGoHttpServeMux::SrsGoHttpServeMux()
|
||||||
{
|
{
|
||||||
|
hosts = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsGoHttpServeMux::~SrsGoHttpServeMux()
|
SrsGoHttpServeMux::~SrsGoHttpServeMux()
|
||||||
|
@ -442,6 +444,10 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pattern.at(0) != '/') {
|
||||||
|
hosts = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
SrsGoHttpMuxEntry* entry = new SrsGoHttpMuxEntry();
|
SrsGoHttpMuxEntry* entry = new SrsGoHttpMuxEntry();
|
||||||
entry->explicit_match = true;
|
entry->explicit_match = true;
|
||||||
|
@ -538,6 +544,11 @@ int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
|
||||||
|
|
||||||
std::string path = r->path();
|
std::string path = r->path();
|
||||||
|
|
||||||
|
// Host-specific pattern takes precedence over generic ones
|
||||||
|
if (hosts) {
|
||||||
|
path = r->host() + path;
|
||||||
|
}
|
||||||
|
|
||||||
int nb_matched = 0;
|
int nb_matched = 0;
|
||||||
ISrsGoHttpHandler* h = NULL;
|
ISrsGoHttpHandler* h = NULL;
|
||||||
|
|
||||||
|
@ -700,7 +711,8 @@ int SrsHttpMessage::initialize()
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
// parse uri to schema/server:port/path?query
|
// parse uri to schema/server:port/path?query
|
||||||
if ((ret = _uri->initialize(_url)) != ERROR_SUCCESS) {
|
std::string uri = "http://" + get_request_header("Host") + _url;
|
||||||
|
if ((ret = _uri->initialize(uri)) != ERROR_SUCCESS) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -822,7 +834,7 @@ string SrsHttpMessage::url()
|
||||||
|
|
||||||
string SrsHttpMessage::host()
|
string SrsHttpMessage::host()
|
||||||
{
|
{
|
||||||
return get_request_header("Host");
|
return _uri->get_host();
|
||||||
}
|
}
|
||||||
|
|
||||||
string SrsHttpMessage::path()
|
string SrsHttpMessage::path()
|
||||||
|
|
|
@ -266,6 +266,8 @@ class SrsGoHttpServeMux
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::map<std::string, SrsGoHttpMuxEntry*> entries;
|
std::map<std::string, SrsGoHttpMuxEntry*> entries;
|
||||||
|
// whether any patterns contain hostnames
|
||||||
|
bool hosts;
|
||||||
public:
|
public:
|
||||||
SrsGoHttpServeMux();
|
SrsGoHttpServeMux();
|
||||||
virtual ~SrsGoHttpServeMux();
|
virtual ~SrsGoHttpServeMux();
|
||||||
|
|
|
@ -165,12 +165,16 @@ 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);
|
||||||
|
|
||||||
|
// replace the vhost variable
|
||||||
|
mount = srs_string_replace(mount, "[vhost]", vhost);
|
||||||
|
|
||||||
// the dir mount must always ends with "/"
|
// the dir mount must always ends with "/"
|
||||||
if (mount != "/" && mount.rfind("/") != mount.length() - 1) {
|
if (mount != "/" && mount.rfind("/") != mount.length() - 1) {
|
||||||
mount += "/";
|
mount += "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mount the http of vhost.
|
||||||
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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue