mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine http server pages. change to 0.9.51
This commit is contained in:
parent
1c02f4551c
commit
4e3fe36ae2
24 changed files with 307 additions and 96 deletions
|
@ -217,6 +217,7 @@ usr sys idl wai hiq siq| read writ| recv send| in out | int csw
|
||||||
* nginx v1.5.0: 139524 lines <br/>
|
* nginx v1.5.0: 139524 lines <br/>
|
||||||
|
|
||||||
## History
|
## 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-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-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).
|
* v1.0, 2014-03-29, add wiki [Performance for RaspberryPi](https://github.com/winlinvip/simple-rtmp-server/wiki/RaspberryPi).
|
||||||
|
|
|
@ -31,6 +31,7 @@ echo "depends tools are ok"
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
# for Ubuntu, auto install tools by apt-get
|
# for Ubuntu, auto install tools by apt-get
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
|
OS_IS_UBUNTU=NO
|
||||||
function Ubuntu_prepare()
|
function Ubuntu_prepare()
|
||||||
{
|
{
|
||||||
uname -v|grep Ubuntu >/dev/null 2>&1
|
uname -v|grep Ubuntu >/dev/null 2>&1
|
||||||
|
@ -38,6 +39,7 @@ function Ubuntu_prepare()
|
||||||
return 0;
|
return 0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
OS_IS_UBUNTU=YES
|
||||||
echo "Ubuntu detected, install tools if needed"
|
echo "Ubuntu detected, install tools if needed"
|
||||||
|
|
||||||
gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
|
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
|
# for Centos, auto install tools by yum
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
|
OS_IS_CENTOS=NO
|
||||||
function Centos_prepare()
|
function Centos_prepare()
|
||||||
{
|
{
|
||||||
if [[ ! -f /etc/redhat-release ]]; then
|
if [[ ! -f /etc/redhat-release ]]; then
|
||||||
return 0;
|
return 0;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
OS_IS_CENTOS=YES
|
||||||
echo "Centos detected, install tools if needed"
|
echo "Centos detected, install tools if needed"
|
||||||
|
|
||||||
gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
|
gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
|
||||||
|
@ -315,6 +319,9 @@ function write_nginx_html5()
|
||||||
</video>
|
</video>
|
||||||
END
|
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
|
__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 [ $__SRS_BUILD_NGINX = YES ]; then
|
||||||
if [[ -f ${SRS_OBJS}/nginx/sbin/nginx ]]; 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.
|
# 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
|
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
|
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
|
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
|
if [ $SRS_NGINX = YES ]; then
|
||||||
echo "#define SRS_NGINX" >> $SRS_AUTO_HEADERS_H
|
echo "#define SRS_NGINX" >> $SRS_AUTO_HEADERS_H
|
||||||
else
|
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
|
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
|
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_BUILD_NGINX = YES ]; then
|
||||||
if [ $SRS_HTTP_CALLBACK = YES ]; then
|
rm -f ${SRS_OBJS}/nginx/html/index.html &&
|
||||||
# override the default index.
|
ln -sf `pwd`/research/players/nginx_index.html ${SRS_OBJS}/nginx/html/index.html
|
||||||
rm -f ${SRS_OBJS}/nginx/html/index.html &&
|
fi
|
||||||
ln -sf `pwd`/research/players/nginx_index.html ${SRS_OBJS}/nginx/html/index.html
|
# if http-server enalbed, use srs embeded http-server
|
||||||
else
|
if [ $SRS_HTTP_SERVER = YES ]; then
|
||||||
rm -f ${SRS_OBJS}/nginx/html/index.html &&
|
rm -f ${SRS_OBJS}/nginx/html/index.html &&
|
||||||
cat<<END > ${SRS_OBJS}/nginx/html/index.html
|
ln -sf `pwd`/research/players/srs-http-server_index.html ${SRS_OBJS}/nginx/html/index.html
|
||||||
<!DOCTYPE html>
|
fi
|
||||||
<html>
|
# if api-server enabled, generate for api server.
|
||||||
<head>
|
if [ $SRS_HTTP_CALLBACK = YES ]; then
|
||||||
<title>SRS</title>
|
rm -f ${SRS_OBJS}/nginx/html/index.html &&
|
||||||
<meta charset="utf-8">
|
ln -sf `pwd`/research/players/api-server_index.html ${SRS_OBJS}/nginx/html/index.html
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<script type="text/javascript">
|
|
||||||
setTimeout(function(){
|
|
||||||
window.location.href = "players/index.html" + window.location.search;
|
|
||||||
}, 500);
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
END
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
|
@ -603,7 +602,11 @@ echo "" >> $SRS_AUTO_HEADERS_H
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
# generated the contributors from AUTHORS.txt
|
# 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
|
echo "#define SRS_CONSTRIBUTORS \"\\" >> $SRS_AUTO_HEADERS_H
|
||||||
for CONTRIBUTOR in $SRS_CONSTRIBUTORS; do
|
for CONTRIBUTOR in $SRS_CONSTRIBUTORS; do
|
||||||
echo "${CONTRIBUTOR} \\" >> $SRS_AUTO_HEADERS_H
|
echo "${CONTRIBUTOR} \\" >> $SRS_AUTO_HEADERS_H
|
||||||
|
|
|
@ -168,12 +168,12 @@ if [ $SRS_DEV = YES ]; then
|
||||||
SRS_NGINX=YES
|
SRS_NGINX=YES
|
||||||
SRS_SSL=YES
|
SRS_SSL=YES
|
||||||
SRS_FFMPEG=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_SERVER=YES
|
||||||
SRS_HTTP_API=YES
|
SRS_HTTP_API=YES
|
||||||
SRS_LIBRTMP=YES
|
SRS_LIBRTMP=YES
|
||||||
SRS_BWTC=YES
|
if [ $SRS_BWTC = RESERVED ]; then SRS_BWTC=YES; fi
|
||||||
SRS_RESEARCH=YES
|
if [ $SRS_RESEARCH = RESERVED ]; then SRS_RESEARCH=YES; fi
|
||||||
SRS_UTEST=YES
|
SRS_UTEST=YES
|
||||||
if [ $SRS_GPERF = RESERVED ]; then SRS_GPERF=NO; fi
|
if [ $SRS_GPERF = RESERVED ]; then SRS_GPERF=NO; fi
|
||||||
if [ $SRS_GPERF_MC = RESERVED ]; then SRS_GPERF_MC=NO; fi
|
if [ $SRS_GPERF_MC = RESERVED ]; then SRS_GPERF_MC=NO; fi
|
||||||
|
|
16
trunk/research/players/api-server_index.html
Normal file
16
trunk/research/players/api-server_index.html
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>SRS</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script type="text/javascript" src="players/js/jquery-1.10.2.min.js"></script>
|
||||||
|
<script type="text/javascript" src="players/js/srs.page.js"></script>
|
||||||
|
<script type="text/javascript" src="players/js/srs.utility.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript">
|
||||||
|
setTimeout(function(){
|
||||||
|
window.location.href = "players/index.html" + window.location.search;
|
||||||
|
}, 500);
|
||||||
|
</script>
|
||||||
|
</body>
|
0
trunk/research/players/index.html
Executable file → Normal file
0
trunk/research/players/index.html
Executable file → Normal file
|
@ -15,6 +15,8 @@ function srs_get_version_code() { return "1.19"; }
|
||||||
function srs_get_player_vhost() { return "players"; }
|
function srs_get_player_vhost() { return "players"; }
|
||||||
// the api server port, for chat room.
|
// the api server port, for chat room.
|
||||||
function srs_get_api_server_port() { return 8085; }
|
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,
|
// get the stream published to vhost,
|
||||||
// generally we need to transcode the stream to support HLS and filters.
|
// 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".
|
// for example, src_vhost is "players", we transcode stream to vhost "players_pub".
|
||||||
|
|
0
trunk/research/players/jwplayer6.html
Executable file → Normal file
0
trunk/research/players/jwplayer6.html
Executable file → Normal file
14
trunk/research/players/nginx_index.html
Executable file → Normal file
14
trunk/research/players/nginx_index.html
Executable file → Normal file
|
@ -3,19 +3,11 @@
|
||||||
<head>
|
<head>
|
||||||
<title>SRS</title>
|
<title>SRS</title>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<script type="text/javascript" src="players/js/jquery-1.10.2.min.js"></script>
|
|
||||||
<script type="text/javascript" src="players/js/srs.page.js"></script>
|
|
||||||
<script type="text/javascript" src="players/js/srs.utility.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var query = parse_query_string();
|
|
||||||
var url = window.location.protocol + "//" + query.hostname + ":" + srs_get_api_server_port() + "/index.html" + window.location.search;
|
|
||||||
document.write("请确认api-server已经开启,跳转到api-server的页面(解决IE跨域问题)<br/>");
|
|
||||||
document.write("正在跳转,若您的浏览器没有跳转,请点击: <a href='" + url + "'>" + url + "</a>");
|
|
||||||
|
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
window.location.href = url;
|
window.location.href = "players/index.html" + window.location.search;
|
||||||
}, 3000);
|
}, 500);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
0
trunk/research/players/osmf.html
Executable file → Normal file
0
trunk/research/players/osmf.html
Executable file → Normal file
16
trunk/research/players/srs-http-server_index.html
Normal file
16
trunk/research/players/srs-http-server_index.html
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>SRS</title>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<script type="text/javascript" src="players/js/jquery-1.10.2.min.js"></script>
|
||||||
|
<script type="text/javascript" src="players/js/srs.page.js"></script>
|
||||||
|
<script type="text/javascript" src="players/js/srs.utility.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<script type="text/javascript">
|
||||||
|
setTimeout(function(){
|
||||||
|
window.location.href = "players/index.html" + window.location.search;
|
||||||
|
}, 500);
|
||||||
|
</script>
|
||||||
|
</body>
|
0
trunk/research/players/srs_bwt.html
Executable file → Normal file
0
trunk/research/players/srs_bwt.html
Executable file → Normal file
0
trunk/research/players/srs_chat.html
Executable file → Normal file
0
trunk/research/players/srs_chat.html
Executable file → Normal file
0
trunk/research/players/srs_player.html
Executable file → Normal file
0
trunk/research/players/srs_player.html
Executable file → Normal file
0
trunk/research/players/srs_publisher.html
Executable file → Normal file
0
trunk/research/players/srs_publisher.html
Executable file → Normal file
0
trunk/research/players/vlc.html
Executable file → Normal file
0
trunk/research/players/vlc.html
Executable file → Normal file
|
@ -52,6 +52,13 @@ bool srs_path_equals(const char* expect, const char* path, int nb_path)
|
||||||
return equals;
|
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()
|
SrsHttpHandlerMatch::SrsHttpHandlerMatch()
|
||||||
{
|
{
|
||||||
handler = NULL;
|
handler = NULL;
|
||||||
|
@ -217,6 +224,34 @@ SrsHttpHandler* SrsHttpHandler::res_content_type(std::stringstream& ss)
|
||||||
return this;
|
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)
|
SrsHttpHandler* SrsHttpHandler::res_content_type_json(std::stringstream& ss)
|
||||||
{
|
{
|
||||||
ss << "Content-Type: application/json;charset=utf-8" << __CRLF
|
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);
|
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)
|
int SrsHttpHandler::res_m3u8(SrsSocket* skt, SrsHttpMessage* req, std::string body)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
|
@ -152,7 +152,12 @@ class SrsHttpHandler;
|
||||||
|
|
||||||
// compare the path.
|
// compare the path.
|
||||||
// full compare, extractly match.
|
// full compare, extractly match.
|
||||||
|
// used for api match.
|
||||||
extern bool srs_path_equals(const char* expect, const char* path, int nb_path);
|
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
|
// state of message
|
||||||
enum SrsHttpParseState {
|
enum SrsHttpParseState {
|
||||||
|
@ -228,6 +233,10 @@ public:
|
||||||
virtual SrsHttpHandler* res_status_line(std::stringstream& ss);
|
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_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(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_json(std::stringstream& ss);
|
||||||
virtual SrsHttpHandler* res_content_type_m3u8(std::stringstream& ss);
|
virtual SrsHttpHandler* res_content_type_m3u8(std::stringstream& ss);
|
||||||
virtual SrsHttpHandler* res_content_type_mpegts(std::stringstream& ss);
|
virtual SrsHttpHandler* res_content_type_mpegts(std::stringstream& ss);
|
||||||
|
@ -239,6 +248,10 @@ public:
|
||||||
public:
|
public:
|
||||||
virtual int res_options(SrsSocket* skt);
|
virtual int res_options(SrsSocket* skt);
|
||||||
virtual int res_text(SrsSocket* skt, SrsHttpMessage* req, std::string body);
|
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_m3u8(SrsSocket* skt, SrsHttpMessage* req, std::string body);
|
||||||
virtual int res_mpegts(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);
|
virtual int res_json(SrsSocket* skt, SrsHttpMessage* req, std::string json);
|
||||||
|
|
|
@ -40,6 +40,8 @@ using namespace std;
|
||||||
#include <srs_app_json.hpp>
|
#include <srs_app_json.hpp>
|
||||||
#include <srs_app_config.hpp>
|
#include <srs_app_config.hpp>
|
||||||
|
|
||||||
|
#define SRS_HTTP_DEFAULT_PAGE "index.html"
|
||||||
|
|
||||||
SrsHttpRoot::SrsHttpRoot()
|
SrsHttpRoot::SrsHttpRoot()
|
||||||
{
|
{
|
||||||
// TODO: FIXME: support reload vhosts.
|
// TODO: FIXME: support reload vhosts.
|
||||||
|
@ -88,14 +90,26 @@ int SrsHttpRoot::initialize()
|
||||||
return ret;
|
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,
|
int ret = ERROR_SUCCESS;
|
||||||
// for child to reparse the path.
|
|
||||||
*pchild = path;
|
// find the best matched child handler.
|
||||||
|
std::vector<SrsHttpHandler*>::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.
|
// if already matched by child, return.
|
||||||
return true;
|
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)
|
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*/)
|
bool SrsHttpVhost::can_handle(const char* path, int length, const char** /*pchild*/)
|
||||||
{
|
{
|
||||||
int min_match = srs_min(length, (int)_mount.length());
|
return srs_path_like(_mount.c_str(), path, length);
|
||||||
return srs_path_equals(_mount.c_str(), path, min_match);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsHttpVhost::is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase)
|
bool SrsHttpVhost::is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase)
|
||||||
{
|
{
|
||||||
std::string fullpath = _dir + "/" + req->match()->unmatched_url;
|
std::string fullpath = get_request_file(req);
|
||||||
if (_mount == "/") {
|
|
||||||
fullpath = _dir + "/" + req->match()->matched_url;
|
|
||||||
if (!req->match()->unmatched_url.empty()) {
|
|
||||||
fullpath += "/" + req->match()->unmatched_url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (::access(fullpath.c_str(), F_OK | R_OK) < 0) {
|
if (::access(fullpath.c_str(), F_OK | R_OK) < 0) {
|
||||||
srs_warn("check file %s does not exists", fullpath.c_str());
|
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;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
std::string fullpath = _dir + "/" + req->match()->unmatched_url;
|
std::string fullpath = get_request_file(req);
|
||||||
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";
|
|
||||||
}
|
|
||||||
|
|
||||||
int fd = ::open(fullpath.c_str(), O_RDONLY);
|
int fd = ::open(fullpath.c_str(), O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -194,6 +191,14 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
|
||||||
return res_mpegts(skt, req, str);
|
return res_mpegts(skt, req, str);
|
||||||
} else if (srs_string_ends_with(fullpath, ".m3u8")) {
|
} else if (srs_string_ends_with(fullpath, ".m3u8")) {
|
||||||
return res_m3u8(skt, req, str);
|
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 {
|
} else {
|
||||||
return res_text(skt, req, str);
|
return res_text(skt, req, str);
|
||||||
}
|
}
|
||||||
|
@ -201,6 +206,31 @@ int SrsHttpVhost::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
|
||||||
return ret;
|
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()
|
string SrsHttpVhost::vhost()
|
||||||
{
|
{
|
||||||
return _vhost;
|
return _vhost;
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
virtual ~SrsHttpRoot();
|
virtual ~SrsHttpRoot();
|
||||||
public:
|
public:
|
||||||
virtual int initialize();
|
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:
|
protected:
|
||||||
virtual bool is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase);
|
virtual bool is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase);
|
||||||
virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req);
|
virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req);
|
||||||
|
@ -69,6 +69,8 @@ public:
|
||||||
protected:
|
protected:
|
||||||
virtual bool is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase);
|
virtual bool is_handler_valid(SrsHttpMessage* req, int& status_code, std::string& reason_phrase);
|
||||||
virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req);
|
virtual int do_process_request(SrsSocket* skt, SrsHttpMessage* req);
|
||||||
|
private:
|
||||||
|
virtual std::string get_request_file(SrsHttpMessage* req);
|
||||||
public:
|
public:
|
||||||
virtual std::string vhost();
|
virtual std::string vhost();
|
||||||
virtual std::string mount();
|
virtual std::string mount();
|
||||||
|
|
|
@ -239,6 +239,7 @@ int SrsRtmpConn::stream_service_cycle()
|
||||||
srs_error("identify client failed. ret=%d", ret);
|
srs_error("identify client failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
req->strip();
|
||||||
srs_trace("identify client success. type=%s, stream_name=%s",
|
srs_trace("identify client success. type=%s, stream_name=%s",
|
||||||
srs_client_type_string(type).c_str(), req->stream.c_str());
|
srs_client_type_string(type).c_str(), req->stream.c_str());
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,24 @@ string srs_string_trim_end(string str, string trim_chars)
|
||||||
return ret;
|
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)
|
string srs_string_remove(string str, string remove_chars)
|
||||||
{
|
{
|
||||||
std::string ret = str;
|
std::string ret = str;
|
||||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// current release version
|
// current release version
|
||||||
#define VERSION_MAJOR "0"
|
#define VERSION_MAJOR "0"
|
||||||
#define VERSION_MINOR "9"
|
#define VERSION_MINOR "9"
|
||||||
#define VERSION_REVISION "50"
|
#define VERSION_REVISION "51"
|
||||||
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
||||||
// server info.
|
// server info.
|
||||||
#define RTMP_SIG_SRS_KEY "srs"
|
#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);
|
extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str);
|
||||||
// trim char in trim_chars of str
|
// trim char in trim_chars of str
|
||||||
extern std::string srs_string_trim_end(std::string str, std::string trim_chars);
|
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
|
// remove char in remove_chars of str
|
||||||
extern std::string srs_string_remove(std::string str, std::string remove_chars);
|
extern std::string srs_string_remove(std::string str, std::string remove_chars);
|
||||||
// whether string end with
|
// whether string end with
|
||||||
|
|
|
@ -127,15 +127,8 @@ int SrsRequest::discovery_app()
|
||||||
app = url;
|
app = url;
|
||||||
vhost = host;
|
vhost = host;
|
||||||
srs_vhost_resolve(vhost, app);
|
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
|
strip();
|
||||||
app = srs_string_trim_end(app, "/");
|
|
||||||
stream = srs_string_trim_end(stream, "/");
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -153,6 +146,22 @@ string SrsRequest::get_stream_url()
|
||||||
return 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()
|
SrsResponse::SrsResponse()
|
||||||
{
|
{
|
||||||
stream_id = SRS_DEFAULT_SID;
|
stream_id = SRS_DEFAULT_SID;
|
||||||
|
|
|
@ -82,6 +82,9 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual int discovery_app();
|
virtual int discovery_app();
|
||||||
virtual std::string get_stream_url();
|
virtual std::string get_stream_url();
|
||||||
|
|
||||||
|
// strip url, user must strip when update the url.
|
||||||
|
virtual void strip();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue