diff --git a/README.md b/README.md
index 169595f6a..d10cd22a7 100755
--- a/README.md
+++ b/README.md
@@ -217,6 +217,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw
* nginx v1.5.0: 139524 lines
## History
+* v1.0, 2014-04-05, support [http api](https://github.com/winlinvip/simple-rtmp-server/wiki/HTTPApi) and [http server](https://github.com/winlinvip/simple-rtmp-server/wiki/HTTPServer).
* v1.0, 2014-04-03, implements http framework and api/v1/version.
* v1.0, 2014-03-30, fix bug for st detecting epoll failed, force st to use epoll.
* v1.0, 2014-03-29, add wiki [Performance for RaspberryPi](https://github.com/winlinvip/simple-rtmp-server/wiki/RaspberryPi).
diff --git a/trunk/auto/depends.sh b/trunk/auto/depends.sh
index 400f71aaf..fa7053124 100755
--- a/trunk/auto/depends.sh
+++ b/trunk/auto/depends.sh
@@ -31,6 +31,7 @@ echo "depends tools are ok"
#####################################################################################
# for Ubuntu, auto install tools by apt-get
#####################################################################################
+OS_IS_UBUNTU=NO
function Ubuntu_prepare()
{
uname -v|grep Ubuntu >/dev/null 2>&1
@@ -38,6 +39,7 @@ function Ubuntu_prepare()
return 0;
fi
+ OS_IS_UBUNTU=YES
echo "Ubuntu detected, install tools if needed"
gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
@@ -113,12 +115,14 @@ Ubuntu_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Ubuntu prepare failed, r
#####################################################################################
# for Centos, auto install tools by yum
#####################################################################################
+OS_IS_CENTOS=NO
function Centos_prepare()
{
if [[ ! -f /etc/redhat-release ]]; then
return 0;
fi
+ OS_IS_CENTOS=YES
echo "Centos detected, install tools if needed"
gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
@@ -315,6 +319,9 @@ function write_nginx_html5()
END
}
+# create the nginx dir, for http-server if not build nginx
+mkdir -p ${SRS_OBJS}/nginx
+# make nginx
__SRS_BUILD_NGINX=NO; if [ $SRS_ARM_UBUNTU12 = NO ]; then if [ $SRS_NGINX = YES ]; then __SRS_BUILD_NGINX=YES; fi fi
if [ $__SRS_BUILD_NGINX = YES ]; then
if [[ -f ${SRS_OBJS}/nginx/sbin/nginx ]]; then
@@ -337,29 +344,29 @@ if [ $__SRS_BUILD_NGINX = YES ]; then
# nginx default use nobody, so cannot read the ts/m3u8 created by srs.
cp ${SRS_OBJS}/nginx/conf/nginx.conf ${SRS_OBJS}/nginx/conf/nginx.conf.bk
sed -i "s/^.user nobody;/user `whoami`;/g" ${SRS_OBJS}/nginx/conf/nginx.conf
-
- # create forward dir
- mkdir -p ${SRS_OBJS}/nginx/html/live &&
- mkdir -p ${SRS_OBJS}/nginx/html/forward/live
-
- # generate default html pages for android.
- html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
- html_file=${SRS_OBJS}/nginx/html/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
- html_file=${SRS_OBJS}/nginx/html/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
- html_file=${SRS_OBJS}/nginx/html/forward/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
- html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
- html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
-
- # copy players to nginx html dir.
- rm -rf ${SRS_OBJS}/nginx/html/players &&
- ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players &&
- rm -f ${SRS_OBJS}/nginx/crossdomain.xml &&
- ln -sf `pwd`/research/players/crossdomain.xml ${SRS_OBJS}/nginx/html/crossdomain.xml
-
- # nginx.html to detect whether nginx is alive
- echo "nginx is ok" > ${SRS_OBJS}/nginx/html/nginx.html
fi
+# create forward dir
+mkdir -p ${SRS_OBJS}/nginx/html/live &&
+mkdir -p ${SRS_OBJS}/nginx/html/forward/live
+
+# generate default html pages for android.
+html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
+html_file=${SRS_OBJS}/nginx/html/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
+html_file=${SRS_OBJS}/nginx/html/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
+html_file=${SRS_OBJS}/nginx/html/forward/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
+html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
+html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
+
+# copy players to nginx html dir.
+rm -rf ${SRS_OBJS}/nginx/html/players &&
+ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players &&
+rm -f ${SRS_OBJS}/nginx/crossdomain.xml &&
+ln -sf `pwd`/research/players/crossdomain.xml ${SRS_OBJS}/nginx/html/crossdomain.xml
+
+# nginx.html to detect whether nginx is alive
+echo "nginx is ok" > ${SRS_OBJS}/nginx/html/nginx.html
+
if [ $SRS_NGINX = YES ]; then
echo "#define SRS_NGINX" >> $SRS_AUTO_HEADERS_H
else
@@ -411,31 +418,23 @@ mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward &&
ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward
ret=$?; if [[ $ret -ne 0 ]]; then echo "link players to cherrypy static-dir failed, ret=$ret"; exit $ret; fi
-# only when the nginx is ok,
-# if api-server not enalbed, use nginx as demo.
+#####################################################################################
+# generate demo index.html
+#####################################################################################
+# if nginx enalbed, generate nginx index file.
if [ $__SRS_BUILD_NGINX = YES ]; then
- if [ $SRS_HTTP_CALLBACK = YES ]; then
- # override the default index.
- rm -f ${SRS_OBJS}/nginx/html/index.html &&
- ln -sf `pwd`/research/players/nginx_index.html ${SRS_OBJS}/nginx/html/index.html
- else
- rm -f ${SRS_OBJS}/nginx/html/index.html &&
- cat< ${SRS_OBJS}/nginx/html/index.html
-
-
-
- SRS
-
-
-
-
-
-END
- fi
+ rm -f ${SRS_OBJS}/nginx/html/index.html &&
+ ln -sf `pwd`/research/players/nginx_index.html ${SRS_OBJS}/nginx/html/index.html
+fi
+# if http-server enalbed, use srs embeded http-server
+if [ $SRS_HTTP_SERVER = YES ]; then
+ rm -f ${SRS_OBJS}/nginx/html/index.html &&
+ ln -sf `pwd`/research/players/srs-http-server_index.html ${SRS_OBJS}/nginx/html/index.html
+fi
+# if api-server enabled, generate for api server.
+if [ $SRS_HTTP_CALLBACK = YES ]; then
+ rm -f ${SRS_OBJS}/nginx/html/index.html &&
+ ln -sf `pwd`/research/players/api-server_index.html ${SRS_OBJS}/nginx/html/index.html
fi
#####################################################################################
@@ -603,7 +602,11 @@ echo "" >> $SRS_AUTO_HEADERS_H
#####################################################################################
# generated the contributors from AUTHORS.txt
#####################################################################################
-SRS_CONSTRIBUTORS=`cat ../AUTHORS.txt|grep "*"|awk -F '\* ' '{print $2}'`
+if [ $OS_IS_CENTOS = YES ]; then
+ SRS_CONSTRIBUTORS=`cat ../AUTHORS.txt|grep "*"|awk -F '* ' '{print $2}'`
+else
+ SRS_CONSTRIBUTORS=`cat ../AUTHORS.txt|grep "*"|awk -F '\* ' '{print $2}'`
+fi
echo "#define SRS_CONSTRIBUTORS \"\\" >> $SRS_AUTO_HEADERS_H
for CONTRIBUTOR in $SRS_CONSTRIBUTORS; do
echo "${CONTRIBUTOR} \\" >> $SRS_AUTO_HEADERS_H
diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh
index 0e54c8563..de61b9333 100755
--- a/trunk/auto/options.sh
+++ b/trunk/auto/options.sh
@@ -168,12 +168,12 @@ if [ $SRS_DEV = YES ]; then
SRS_NGINX=YES
SRS_SSL=YES
SRS_FFMPEG=YES
- SRS_HTTP_CALLBACK=YES
+ if [ $SRS_HTTP_CALLBACK = RESERVED ]; then SRS_HTTP_CALLBACK=YES; fi
SRS_HTTP_SERVER=YES
SRS_HTTP_API=YES
SRS_LIBRTMP=YES
- SRS_BWTC=YES
- SRS_RESEARCH=YES
+ if [ $SRS_BWTC = RESERVED ]; then SRS_BWTC=YES; fi
+ if [ $SRS_RESEARCH = RESERVED ]; then SRS_RESEARCH=YES; fi
SRS_UTEST=YES
if [ $SRS_GPERF = RESERVED ]; then SRS_GPERF=NO; fi
if [ $SRS_GPERF_MC = RESERVED ]; then SRS_GPERF_MC=NO; fi
diff --git a/trunk/research/players/api-server_index.html b/trunk/research/players/api-server_index.html
new file mode 100644
index 000000000..9856a507e
--- /dev/null
+++ b/trunk/research/players/api-server_index.html
@@ -0,0 +1,16 @@
+
+
+
+ SRS
+
+
+
+
+
+
+
+
diff --git a/trunk/research/players/index.html b/trunk/research/players/index.html
old mode 100755
new mode 100644
diff --git a/trunk/research/players/js/srs.page.js b/trunk/research/players/js/srs.page.js
index f01f72d01..2a7a58f31 100755
--- a/trunk/research/players/js/srs.page.js
+++ b/trunk/research/players/js/srs.page.js
@@ -15,6 +15,8 @@ function srs_get_version_code() { return "1.19"; }
function srs_get_player_vhost() { return "players"; }
// the api server port, for chat room.
function srs_get_api_server_port() { return 8085; }
+// the srs http server port
+function srs_get_srs_http_server_port() { return 8080; }
// get the stream published to vhost,
// generally we need to transcode the stream to support HLS and filters.
// for example, src_vhost is "players", we transcode stream to vhost "players_pub".
diff --git a/trunk/research/players/jwplayer6.html b/trunk/research/players/jwplayer6.html
old mode 100755
new mode 100644
diff --git a/trunk/research/players/nginx_index.html b/trunk/research/players/nginx_index.html
old mode 100755
new mode 100644
index ebef63b34..058a639aa
--- a/trunk/research/players/nginx_index.html
+++ b/trunk/research/players/nginx_index.html
@@ -3,19 +3,11 @@
SRS
-
-
-
-
+
\ No newline at end of file
diff --git a/trunk/research/players/osmf.html b/trunk/research/players/osmf.html
old mode 100755
new mode 100644
diff --git a/trunk/research/players/srs-http-server_index.html b/trunk/research/players/srs-http-server_index.html
new file mode 100644
index 000000000..9856a507e
--- /dev/null
+++ b/trunk/research/players/srs-http-server_index.html
@@ -0,0 +1,16 @@
+
+
+
+ SRS
+
+
+
+
+
+
+
+
diff --git a/trunk/research/players/srs_bwt.html b/trunk/research/players/srs_bwt.html
old mode 100755
new mode 100644
diff --git a/trunk/research/players/srs_chat.html b/trunk/research/players/srs_chat.html
old mode 100755
new mode 100644
diff --git a/trunk/research/players/srs_player.html b/trunk/research/players/srs_player.html
old mode 100755
new mode 100644
diff --git a/trunk/research/players/srs_publisher.html b/trunk/research/players/srs_publisher.html
old mode 100755
new mode 100644
diff --git a/trunk/research/players/vlc.html b/trunk/research/players/vlc.html
old mode 100755
new mode 100644
diff --git a/trunk/src/app/srs_app_http.cpp b/trunk/src/app/srs_app_http.cpp
index 513b54776..5d4eb869f 100644
--- a/trunk/src/app/srs_app_http.cpp
+++ b/trunk/src/app/srs_app_http.cpp
@@ -52,6 +52,13 @@ bool srs_path_equals(const char* expect, const char* path, int nb_path)
return equals;
}
+bool srs_path_like(const char* expect, const char* path, int nb_path)
+{
+ int size = strlen(expect);
+ bool equals = !strncmp(expect, path, srs_min(size, nb_path));
+ return equals;
+}
+
SrsHttpHandlerMatch::SrsHttpHandlerMatch()
{
handler = NULL;
@@ -217,6 +224,34 @@ SrsHttpHandler* SrsHttpHandler::res_content_type(std::stringstream& ss)
return this;
}
+SrsHttpHandler* SrsHttpHandler::res_content_type_xml(std::stringstream& ss)
+{
+ ss << "Content-Type: text/xml;charset=utf-8" << __CRLF
+ << "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
+ return this;
+}
+
+SrsHttpHandler* SrsHttpHandler::res_content_type_javascript(std::stringstream& ss)
+{
+ ss << "Content-Type: text/javascript;charset=utf-8" << __CRLF
+ << "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
+ return this;
+}
+
+SrsHttpHandler* SrsHttpHandler::res_content_type_swf(std::stringstream& ss)
+{
+ ss << "Content-Type: application/x-shockwave-flash;charset=utf-8" << __CRLF
+ << "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
+ return this;
+}
+
+SrsHttpHandler* SrsHttpHandler::res_content_type_css(std::stringstream& ss)
+{
+ ss << "Content-Type: text/css;charset=utf-8" << __CRLF
+ << "Allow: DELETE, GET, HEAD, OPTIONS, POST, PUT" << __CRLF;
+ return this;
+}
+
SrsHttpHandler* SrsHttpHandler::res_content_type_json(std::stringstream& ss)
{
ss << "Content-Type: application/json;charset=utf-8" << __CRLF
@@ -299,6 +334,74 @@ int SrsHttpHandler::res_text(SrsSocket* skt, SrsHttpMessage* req, std::string bo
return res_flush(skt, ss);
}
+int SrsHttpHandler::res_xml(SrsSocket* skt, SrsHttpMessage* req, std::string body)
+{
+ std::stringstream ss;
+
+ res_status_line(ss)->res_content_type_xml(ss)
+ ->res_content_length(ss, (int)body.length());
+
+ if (req->requires_crossdomain()) {
+ res_enable_crossdomain(ss);
+ }
+
+ res_header_eof(ss)
+ ->res_body(ss, body);
+
+ return res_flush(skt, ss);
+}
+
+int SrsHttpHandler::res_javascript(SrsSocket* skt, SrsHttpMessage* req, std::string body)
+{
+ std::stringstream ss;
+
+ res_status_line(ss)->res_content_type_javascript(ss)
+ ->res_content_length(ss, (int)body.length());
+
+ if (req->requires_crossdomain()) {
+ res_enable_crossdomain(ss);
+ }
+
+ res_header_eof(ss)
+ ->res_body(ss, body);
+
+ return res_flush(skt, ss);
+}
+
+int SrsHttpHandler::res_swf(SrsSocket* skt, SrsHttpMessage* req, std::string body)
+{
+ std::stringstream ss;
+
+ res_status_line(ss)->res_content_type_swf(ss)
+ ->res_content_length(ss, (int)body.length());
+
+ if (req->requires_crossdomain()) {
+ res_enable_crossdomain(ss);
+ }
+
+ res_header_eof(ss)
+ ->res_body(ss, body);
+
+ return res_flush(skt, ss);
+}
+
+int SrsHttpHandler::res_css(SrsSocket* skt, SrsHttpMessage* req, std::string body)
+{
+ std::stringstream ss;
+
+ res_status_line(ss)->res_content_type_css(ss)
+ ->res_content_length(ss, (int)body.length());
+
+ if (req->requires_crossdomain()) {
+ res_enable_crossdomain(ss);
+ }
+
+ res_header_eof(ss)
+ ->res_body(ss, body);
+
+ return res_flush(skt, ss);
+}
+
int SrsHttpHandler::res_m3u8(SrsSocket* skt, SrsHttpMessage* req, std::string body)
{
std::stringstream ss;
diff --git a/trunk/src/app/srs_app_http.hpp b/trunk/src/app/srs_app_http.hpp
index af0cae24c..47453994d 100644
--- a/trunk/src/app/srs_app_http.hpp
+++ b/trunk/src/app/srs_app_http.hpp
@@ -152,7 +152,12 @@ class SrsHttpHandler;
// compare the path.
// full compare, extractly match.
+// used for api match.
extern bool srs_path_equals(const char* expect, const char* path, int nb_path);
+// compare the path use like,
+// used for http stream to match,
+// if the path like the requires
+extern bool srs_path_like(const char* expect, const char* path, int nb_path);
// state of message
enum SrsHttpParseState {
@@ -228,6 +233,10 @@ public:
virtual SrsHttpHandler* res_status_line(std::stringstream& ss);
virtual SrsHttpHandler* res_status_line_error(std::stringstream& ss, int code, std::string reason_phrase);
virtual SrsHttpHandler* res_content_type(std::stringstream& ss);
+ virtual SrsHttpHandler* res_content_type_xml(std::stringstream& ss);
+ virtual SrsHttpHandler* res_content_type_javascript(std::stringstream& ss);
+ virtual SrsHttpHandler* res_content_type_swf(std::stringstream& ss);
+ virtual SrsHttpHandler* res_content_type_css(std::stringstream& ss);
virtual SrsHttpHandler* res_content_type_json(std::stringstream& ss);
virtual SrsHttpHandler* res_content_type_m3u8(std::stringstream& ss);
virtual SrsHttpHandler* res_content_type_mpegts(std::stringstream& ss);
@@ -239,6 +248,10 @@ public:
public:
virtual int res_options(SrsSocket* skt);
virtual int res_text(SrsSocket* skt, SrsHttpMessage* req, std::string body);
+ virtual int res_xml(SrsSocket* skt, SrsHttpMessage* req, std::string body);
+ virtual int res_javascript(SrsSocket* skt, SrsHttpMessage* req, std::string body);
+ virtual int res_swf(SrsSocket* skt, SrsHttpMessage* req, std::string body);
+ virtual int res_css(SrsSocket* skt, SrsHttpMessage* req, std::string body);
virtual int res_m3u8(SrsSocket* skt, SrsHttpMessage* req, std::string body);
virtual int res_mpegts(SrsSocket* skt, SrsHttpMessage* req, std::string body);
virtual int res_json(SrsSocket* skt, SrsHttpMessage* req, std::string json);
diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp
index 6bacb64b1..a1b0ea71c 100644
--- a/trunk/src/app/srs_app_http_conn.cpp
+++ b/trunk/src/app/srs_app_http_conn.cpp
@@ -40,6 +40,8 @@ using namespace std;
#include
#include
+#define SRS_HTTP_DEFAULT_PAGE "index.html"
+
SrsHttpRoot::SrsHttpRoot()
{
// TODO: FIXME: support reload vhosts.
@@ -88,14 +90,26 @@ int SrsHttpRoot::initialize()
return ret;
}
-bool SrsHttpRoot::can_handle(const char* path, int length, const char** pchild)
+int SrsHttpRoot::best_match(const char* path, int length, SrsHttpHandlerMatch** ppmatch)
{
- // reset the child path to path,
- // for child to reparse the path.
- *pchild = path;
+ int ret = ERROR_SUCCESS;
+
+ // find the best matched child handler.
+ std::vector::iterator it;
+ for (it = handlers.begin(); it != handlers.end(); ++it) {
+ SrsHttpHandler* h = *it;
+
+ // search all child handlers.
+ h->best_match(path, length, ppmatch);
+ }
- // never handle request for root.
- return true;
+ // if already matched by child, return.
+ if (*ppmatch) {
+ return ret;
+ }
+
+ // not matched, error.
+ return ERROR_HTTP_HANDLER_MATCH_URL;
}
bool SrsHttpRoot::is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase)
@@ -125,19 +139,12 @@ SrsHttpVhost::~SrsHttpVhost()
bool SrsHttpVhost::can_handle(const char* path, int length, const char** /*pchild*/)
{
- int min_match = srs_min(length, (int)_mount.length());
- return srs_path_equals(_mount.c_str(), path, min_match);
+ return srs_path_like(_mount.c_str(), path, length);
}
bool SrsHttpVhost::is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase)
{
- std::string fullpath = _dir + "/" + req->match()->unmatched_url;
- if (_mount == "/") {
- fullpath = _dir + "/" + req->match()->matched_url;
- if (!req->match()->unmatched_url.empty()) {
- fullpath += "/" + req->match()->unmatched_url;
- }
- }
+ std::string fullpath = get_request_file(req);
if (::access(fullpath.c_str(), F_OK | R_OK) < 0) {
srs_warn("check file %s does not exists", fullpath.c_str());
@@ -154,17 +161,7 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
{
int ret = ERROR_SUCCESS;
- std::string fullpath = _dir + "/" + req->match()->unmatched_url;
- if (_mount == "/") {
- fullpath = _dir + "/" + req->match()->matched_url;
- if (!req->match()->unmatched_url.empty()) {
- fullpath += "/" + req->match()->unmatched_url;
- }
- }
-
- if (srs_string_ends_with(fullpath, "/")) {
- fullpath += "index.html";
- }
+ std::string fullpath = get_request_file(req);
int fd = ::open(fullpath.c_str(), O_RDONLY);
if (fd < 0) {
@@ -194,6 +191,14 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
return res_mpegts(skt, req, str);
} else if (srs_string_ends_with(fullpath, ".m3u8")) {
return res_m3u8(skt, req, str);
+ } else if (srs_string_ends_with(fullpath, ".xml")) {
+ return res_xml(skt, req, str);
+ } else if (srs_string_ends_with(fullpath, ".js")) {
+ return res_javascript(skt, req, str);
+ } else if (srs_string_ends_with(fullpath, ".swf")) {
+ return res_swf(skt, req, str);
+ } else if (srs_string_ends_with(fullpath, ".css")) {
+ return res_css(skt, req, str);
} else {
return res_text(skt, req, str);
}
@@ -201,6 +206,31 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
return ret;
}
+string SrsHttpVhost::get_request_file(SrsHttpMessage* req)
+{
+ std::string fullpath = _dir + "/";
+
+ // if root, directly use the matched url.
+ if (_mount == "/") {
+ // add the dir
+ fullpath += req->match()->matched_url;
+ // if file speicified, add the file.
+ if (!req->match()->unmatched_url.empty()) {
+ fullpath += "/" + req->match()->unmatched_url;
+ }
+ } else {
+ // virtual path, ignore the virutal path.
+ fullpath += req->match()->unmatched_url;
+ }
+
+ // add default pages.
+ if (srs_string_ends_with(fullpath, "/")) {
+ fullpath += SRS_HTTP_DEFAULT_PAGE;
+ }
+
+ return fullpath;
+}
+
string SrsHttpVhost::vhost()
{
return _vhost;
diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp
index 1bb91fea9..3e4fc69cd 100644
--- a/trunk/src/app/srs_app_http_conn.hpp
+++ b/trunk/src/app/srs_app_http_conn.hpp
@@ -49,7 +49,7 @@ public:
virtual ~SrsHttpRoot();
public:
virtual int initialize();
- virtual bool can_handle(const char* path, int length, const char** pchild);
+ virtual int best_match(const char* path, int length, SrsHttpHandlerMatch** ppmatch);
protected:
virtual bool is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase);
virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req);
@@ -69,6 +69,8 @@ public:
protected:
virtual bool is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase);
virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req);
+private:
+ virtual std::string get_request_file(SrsHttpMessage* req);
public:
virtual std::string vhost();
virtual std::string mount();
diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp
index f2802af2b..147bf2f00 100644
--- a/trunk/src/app/srs_app_rtmp_conn.cpp
+++ b/trunk/src/app/srs_app_rtmp_conn.cpp
@@ -239,6 +239,7 @@ int SrsRtmpConn::stream_service_cycle()
srs_error("identify client failed. ret=%d", ret);
return ret;
}
+ req->strip();
srs_trace("identify client success. type=%s, stream_name=%s",
srs_client_type_string(type).c_str(), req->stream.c_str());
diff --git a/trunk/src/core/srs_core.cpp b/trunk/src/core/srs_core.cpp
index 92918ff7a..237b17f0a 100644
--- a/trunk/src/core/srs_core.cpp
+++ b/trunk/src/core/srs_core.cpp
@@ -63,6 +63,24 @@ string srs_string_trim_end(string str, string trim_chars)
return ret;
}
+string srs_string_trim_start(string str, string trim_chars)
+{
+ std::string ret = str;
+
+ for (int i = 0; i < (int)trim_chars.length(); i++) {
+ char ch = trim_chars.at(i);
+
+ while (!ret.empty() && ret.at(0) == ch) {
+ ret.erase(ret.begin());
+
+ // ok, matched, should reset the search
+ i = 0;
+ }
+ }
+
+ return ret;
+}
+
string srs_string_remove(string str, string remove_chars)
{
std::string ret = str;
diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp
index 85a2679d1..73c80ef44 100644
--- a/trunk/src/core/srs_core.hpp
+++ b/trunk/src/core/srs_core.hpp
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// current release version
#define VERSION_MAJOR "0"
#define VERSION_MINOR "9"
-#define VERSION_REVISION "50"
+#define VERSION_REVISION "51"
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
// server info.
#define RTMP_SIG_SRS_KEY "srs"
@@ -101,6 +101,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str);
// trim char in trim_chars of str
extern std::string srs_string_trim_end(std::string str, std::string trim_chars);
+// trim char in trim_chars of str
+extern std::string srs_string_trim_start(std::string str, std::string trim_chars);
// remove char in remove_chars of str
extern std::string srs_string_remove(std::string str, std::string remove_chars);
// whether string end with
diff --git a/trunk/src/rtmp/srs_protocol_rtmp.cpp b/trunk/src/rtmp/srs_protocol_rtmp.cpp
index 905b88d12..d38cdfcfd 100644
--- a/trunk/src/rtmp/srs_protocol_rtmp.cpp
+++ b/trunk/src/rtmp/srs_protocol_rtmp.cpp
@@ -127,15 +127,8 @@ int SrsRequest::discovery_app()
app = url;
vhost = host;
srs_vhost_resolve(vhost, app);
-
- // remove the unsupported chars in names.
- vhost = srs_string_remove(vhost, "/ \n\r\t");
- app = srs_string_remove(app, " \n\r\t");
- stream = srs_string_remove(stream, " \n\r\t");
- // remove end slash of app
- app = srs_string_trim_end(app, "/");
- stream = srs_string_trim_end(stream, "/");
+ strip();
return ret;
}
@@ -153,6 +146,22 @@ string SrsRequest::get_stream_url()
return url;
}
+void SrsRequest::strip()
+{
+ // remove the unsupported chars in names.
+ vhost = srs_string_remove(vhost, "/ \n\r\t");
+ app = srs_string_remove(app, " \n\r\t");
+ stream = srs_string_remove(stream, " \n\r\t");
+
+ // remove end slash of app/stream
+ app = srs_string_trim_end(app, "/");
+ stream = srs_string_trim_end(stream, "/");
+
+ // remove start slash of app/stream
+ app = srs_string_trim_start(app, "/");
+ stream = srs_string_trim_start(stream, "/");
+}
+
SrsResponse::SrsResponse()
{
stream_id = SRS_DEFAULT_SID;
diff --git a/trunk/src/rtmp/srs_protocol_rtmp.hpp b/trunk/src/rtmp/srs_protocol_rtmp.hpp
index 0e642a7d2..5c7099072 100644
--- a/trunk/src/rtmp/srs_protocol_rtmp.hpp
+++ b/trunk/src/rtmp/srs_protocol_rtmp.hpp
@@ -82,6 +82,9 @@ public:
*/
virtual int discovery_app();
virtual std::string get_stream_url();
+
+ // strip url, user must strip when update the url.
+ virtual void strip();
};
/**