Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2015-03-04 13:09:35 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
04dc60ebe1dd2f7f2f83b5f54a715c75807f1957
04dc60eb
1 parent
983ab8fb
refine http for srs, rename SrsGoHttp to SrsHttp.
隐藏空白字符变更
内嵌
并排对比
正在显示
8 个修改的文件
包含
197 行增加
和
197 行删除
trunk/src/app/srs_app_http.cpp
trunk/src/app/srs_app_http.hpp
trunk/src/app/srs_app_http_api.cpp
trunk/src/app/srs_app_http_api.hpp
trunk/src/app/srs_app_http_conn.cpp
trunk/src/app/srs_app_http_conn.hpp
trunk/src/app/srs_app_server.cpp
trunk/src/app/srs_app_server.hpp
trunk/src/app/srs_app_http.cpp
查看文件 @
04dc60e
...
...
@@ -53,7 +53,7 @@ using namespace std;
#define SRS_HTTP_DEFAULT_PAGE "index.html"
int
srs_go_http_response_json
(
ISrs
Go
HttpResponseWriter
*
w
,
string
data
)
int
srs_go_http_response_json
(
ISrsHttpResponseWriter
*
w
,
string
data
)
{
w
->
header
()
->
set_content_length
(
data
.
length
());
w
->
header
()
->
set_content_type
(
"application/json"
);
...
...
@@ -147,7 +147,7 @@ string srs_go_http_detect(char* data, int size)
// Error replies to the request with the specified error message and HTTP code.
// The error message should be plain text.
int
srs_go_http_error
(
ISrs
Go
HttpResponseWriter
*
w
,
int
code
,
string
error
)
int
srs_go_http_error
(
ISrsHttpResponseWriter
*
w
,
int
code
,
string
error
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -159,20 +159,20 @@ int srs_go_http_error(ISrsGoHttpResponseWriter* w, int code, string error)
return
ret
;
}
Srs
GoHttpHeader
::
SrsGo
HttpHeader
()
Srs
HttpHeader
::
Srs
HttpHeader
()
{
}
Srs
GoHttpHeader
::~
SrsGo
HttpHeader
()
Srs
HttpHeader
::~
Srs
HttpHeader
()
{
}
void
Srs
Go
HttpHeader
::
set
(
string
key
,
string
value
)
void
SrsHttpHeader
::
set
(
string
key
,
string
value
)
{
headers
[
key
]
=
value
;
}
string
Srs
Go
HttpHeader
::
get
(
string
key
)
string
SrsHttpHeader
::
get
(
string
key
)
{
std
::
string
v
;
...
...
@@ -183,7 +183,7 @@ string SrsGoHttpHeader::get(string key)
return
v
;
}
int64_t
Srs
Go
HttpHeader
::
content_length
()
int64_t
SrsHttpHeader
::
content_length
()
{
std
::
string
cl
=
get
(
"Content-Length"
);
...
...
@@ -194,24 +194,24 @@ int64_t SrsGoHttpHeader::content_length()
return
(
int64_t
)
::
atof
(
cl
.
c_str
());
}
void
Srs
Go
HttpHeader
::
set_content_length
(
int64_t
size
)
void
SrsHttpHeader
::
set_content_length
(
int64_t
size
)
{
char
buf
[
64
];
snprintf
(
buf
,
sizeof
(
buf
),
"%"
PRId64
,
size
);
set
(
"Content-Length"
,
buf
);
}
string
Srs
Go
HttpHeader
::
content_type
()
string
SrsHttpHeader
::
content_type
()
{
return
get
(
"Content-Type"
);
}
void
Srs
Go
HttpHeader
::
set_content_type
(
string
ct
)
void
SrsHttpHeader
::
set_content_type
(
string
ct
)
{
set
(
"Content-Type"
,
ct
);
}
void
Srs
Go
HttpHeader
::
write
(
stringstream
&
ss
)
void
SrsHttpHeader
::
write
(
stringstream
&
ss
)
{
std
::
map
<
std
::
string
,
std
::
string
>::
iterator
it
;
for
(
it
=
headers
.
begin
();
it
!=
headers
.
end
();
++
it
)
{
...
...
@@ -219,64 +219,64 @@ void SrsGoHttpHeader::write(stringstream& ss)
}
}
ISrs
GoHttpResponseWriter
::
ISrsGo
HttpResponseWriter
()
ISrs
HttpResponseWriter
::
ISrs
HttpResponseWriter
()
{
}
ISrs
GoHttpResponseWriter
::~
ISrsGo
HttpResponseWriter
()
ISrs
HttpResponseWriter
::~
ISrs
HttpResponseWriter
()
{
}
ISrs
GoHttpHandler
::
ISrsGo
HttpHandler
()
ISrs
HttpHandler
::
ISrs
HttpHandler
()
{
entry
=
NULL
;
}
ISrs
GoHttpHandler
::~
ISrsGo
HttpHandler
()
ISrs
HttpHandler
::~
ISrs
HttpHandler
()
{
}
Srs
GoHttpRedirectHandler
::
SrsGo
HttpRedirectHandler
(
string
u
,
int
c
)
Srs
HttpRedirectHandler
::
Srs
HttpRedirectHandler
(
string
u
,
int
c
)
{
url
=
u
;
code
=
c
;
}
Srs
GoHttpRedirectHandler
::~
SrsGo
HttpRedirectHandler
()
Srs
HttpRedirectHandler
::~
Srs
HttpRedirectHandler
()
{
}
int
Srs
GoHttpRedirectHandler
::
serve_http
(
ISrsGo
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
Srs
HttpRedirectHandler
::
serve_http
(
ISrs
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
// TODO: FIXME: implements it.
return
ret
;
}
Srs
GoHttpNotFoundHandler
::
SrsGo
HttpNotFoundHandler
()
Srs
HttpNotFoundHandler
::
Srs
HttpNotFoundHandler
()
{
}
Srs
GoHttpNotFoundHandler
::~
SrsGo
HttpNotFoundHandler
()
Srs
HttpNotFoundHandler
::~
Srs
HttpNotFoundHandler
()
{
}
int
Srs
GoHttpNotFoundHandler
::
serve_http
(
ISrsGo
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
Srs
HttpNotFoundHandler
::
serve_http
(
ISrs
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
return
srs_go_http_error
(
w
,
SRS_CONSTS_HTTP_NotFound
,
SRS_CONSTS_HTTP_NotFound_str
);
}
Srs
GoHttpFileServer
::
SrsGo
HttpFileServer
(
string
root_dir
)
Srs
HttpFileServer
::
Srs
HttpFileServer
(
string
root_dir
)
{
dir
=
root_dir
;
}
Srs
GoHttpFileServer
::~
SrsGo
HttpFileServer
()
Srs
HttpFileServer
::~
Srs
HttpFileServer
()
{
}
int
Srs
GoHttpFileServer
::
serve_http
(
ISrsGo
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
Srs
HttpFileServer
::
serve_http
(
ISrs
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
string
upath
=
r
->
path
();
...
...
@@ -300,7 +300,7 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
if
(
!
srs_path_exists
(
fullpath
))
{
srs_warn
(
"http miss file=%s, pattern=%s, upath=%s"
,
fullpath
.
c_str
(),
entry
->
pattern
.
c_str
(),
upath
.
c_str
());
return
Srs
Go
HttpNotFoundHandler
().
serve_http
(
w
,
r
);
return
SrsHttpNotFoundHandler
().
serve_http
(
w
,
r
);
}
srs_trace
(
"http match file=%s, pattern=%s, upath=%s"
,
fullpath
.
c_str
(),
entry
->
pattern
.
c_str
(),
upath
.
c_str
());
...
...
@@ -317,7 +317,7 @@ int SrsGoHttpFileServer::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
return
serve_file
(
w
,
r
,
fullpath
);
}
int
Srs
GoHttpFileServer
::
serve_file
(
ISrsGo
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
)
int
Srs
HttpFileServer
::
serve_file
(
ISrs
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -391,7 +391,7 @@ int SrsGoHttpFileServer::serve_file(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
return
w
->
final_request
();
}
int
Srs
GoHttpFileServer
::
serve_flv_file
(
ISrsGo
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
)
int
Srs
HttpFileServer
::
serve_flv_file
(
ISrs
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
)
{
std
::
string
start
=
r
->
query_get
(
"start"
);
if
(
start
.
empty
())
{
...
...
@@ -406,7 +406,7 @@ int SrsGoHttpFileServer::serve_flv_file(ISrsGoHttpResponseWriter* w, SrsHttpMess
return
serve_flv_stream
(
w
,
r
,
fullpath
,
offset
);
}
int
Srs
GoHttpFileServer
::
serve_mp4_file
(
ISrsGo
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
)
int
Srs
HttpFileServer
::
serve_mp4_file
(
ISrs
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
)
{
// for flash to request mp4 range in query string.
// for example, http://digitalprimates.net/dash/DashTest.html?url=http://dashdemo.edgesuite.net/digitalprimates/nexus/oops-20120802-manifest.mpd
...
...
@@ -443,17 +443,17 @@ int SrsGoHttpFileServer::serve_mp4_file(ISrsGoHttpResponseWriter* w, SrsHttpMess
return
serve_mp4_stream
(
w
,
r
,
fullpath
,
start
,
end
);
}
int
Srs
GoHttpFileServer
::
serve_flv_stream
(
ISrsGo
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
,
int
offset
)
int
Srs
HttpFileServer
::
serve_flv_stream
(
ISrs
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
,
int
offset
)
{
return
serve_file
(
w
,
r
,
fullpath
);
}
int
Srs
GoHttpFileServer
::
serve_mp4_stream
(
ISrsGo
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
,
int
start
,
int
end
)
int
Srs
HttpFileServer
::
serve_mp4_stream
(
ISrs
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
,
int
start
,
int
end
)
{
return
serve_file
(
w
,
r
,
fullpath
);
}
int
Srs
GoHttpFileServer
::
copy
(
ISrsGo
HttpResponseWriter
*
w
,
SrsFileReader
*
fs
,
SrsHttpMessage
*
r
,
int
size
)
int
Srs
HttpFileServer
::
copy
(
ISrs
HttpResponseWriter
*
w
,
SrsFileReader
*
fs
,
SrsHttpMessage
*
r
,
int
size
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -476,27 +476,27 @@ int SrsGoHttpFileServer::copy(ISrsGoHttpResponseWriter* w, SrsFileReader* fs, Sr
return
ret
;
}
Srs
GoHttpMuxEntry
::
SrsGo
HttpMuxEntry
()
Srs
HttpMuxEntry
::
Srs
HttpMuxEntry
()
{
enabled
=
true
;
explicit_match
=
false
;
handler
=
NULL
;
}
Srs
GoHttpMuxEntry
::~
SrsGo
HttpMuxEntry
()
Srs
HttpMuxEntry
::~
Srs
HttpMuxEntry
()
{
srs_freep
(
handler
);
}
Srs
GoHttpServeMux
::
SrsGo
HttpServeMux
()
Srs
HttpServeMux
::
Srs
HttpServeMux
()
{
}
Srs
GoHttpServeMux
::~
SrsGo
HttpServeMux
()
Srs
HttpServeMux
::~
Srs
HttpServeMux
()
{
std
::
map
<
std
::
string
,
Srs
Go
HttpMuxEntry
*>::
iterator
it
;
std
::
map
<
std
::
string
,
SrsHttpMuxEntry
*>::
iterator
it
;
for
(
it
=
entries
.
begin
();
it
!=
entries
.
end
();
++
it
)
{
Srs
Go
HttpMuxEntry
*
entry
=
it
->
second
;
SrsHttpMuxEntry
*
entry
=
it
->
second
;
srs_freep
(
entry
);
}
entries
.
clear
();
...
...
@@ -504,14 +504,14 @@ SrsGoHttpServeMux::~SrsGoHttpServeMux()
vhosts
.
clear
();
}
int
Srs
Go
HttpServeMux
::
initialize
()
int
SrsHttpServeMux
::
initialize
()
{
int
ret
=
ERROR_SUCCESS
;
// TODO: FIXME: implements it.
return
ret
;
}
int
Srs
GoHttpServeMux
::
handle
(
std
::
string
pattern
,
ISrsGo
HttpHandler
*
handler
)
int
Srs
HttpServeMux
::
handle
(
std
::
string
pattern
,
ISrs
HttpHandler
*
handler
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -524,7 +524,7 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
}
if
(
entries
.
find
(
pattern
)
!=
entries
.
end
())
{
Srs
Go
HttpMuxEntry
*
exists
=
entries
[
pattern
];
SrsHttpMuxEntry
*
exists
=
entries
[
pattern
];
if
(
exists
->
explicit_match
)
{
ret
=
ERROR_HTTP_PATTERN_DUPLICATED
;
srs_error
(
"http: multiple registrations for %s. ret=%d"
,
pattern
.
c_str
(),
ret
);
...
...
@@ -541,14 +541,14 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
}
if
(
true
)
{
Srs
GoHttpMuxEntry
*
entry
=
new
SrsGo
HttpMuxEntry
();
Srs
HttpMuxEntry
*
entry
=
new
Srs
HttpMuxEntry
();
entry
->
explicit_match
=
true
;
entry
->
handler
=
handler
;
entry
->
pattern
=
pattern
;
entry
->
handler
->
entry
=
entry
;
if
(
entries
.
find
(
pattern
)
!=
entries
.
end
())
{
Srs
Go
HttpMuxEntry
*
exists
=
entries
[
pattern
];
SrsHttpMuxEntry
*
exists
=
entries
[
pattern
];
srs_freep
(
exists
);
}
entries
[
pattern
]
=
entry
;
...
...
@@ -559,11 +559,11 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
// It can be overridden by an explicit registration.
if
(
pattern
!=
"/"
&&
!
pattern
.
empty
()
&&
pattern
.
at
(
pattern
.
length
()
-
1
)
==
'/'
)
{
std
::
string
rpattern
=
pattern
.
substr
(
0
,
pattern
.
length
()
-
1
);
Srs
Go
HttpMuxEntry
*
entry
=
NULL
;
SrsHttpMuxEntry
*
entry
=
NULL
;
// free the exists not explicit entry
if
(
entries
.
find
(
rpattern
)
!=
entries
.
end
())
{
Srs
Go
HttpMuxEntry
*
exists
=
entries
[
rpattern
];
SrsHttpMuxEntry
*
exists
=
entries
[
rpattern
];
if
(
!
exists
->
explicit_match
)
{
entry
=
exists
;
}
...
...
@@ -573,9 +573,9 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
if
(
!
entry
||
entry
->
explicit_match
)
{
srs_freep
(
entry
);
entry
=
new
Srs
Go
HttpMuxEntry
();
entry
=
new
SrsHttpMuxEntry
();
entry
->
explicit_match
=
false
;
entry
->
handler
=
new
Srs
Go
HttpRedirectHandler
(
pattern
,
SRS_CONSTS_HTTP_MovedPermanently
);
entry
->
handler
=
new
SrsHttpRedirectHandler
(
pattern
,
SRS_CONSTS_HTTP_MovedPermanently
);
entry
->
pattern
=
pattern
;
entry
->
handler
->
entry
=
entry
;
...
...
@@ -586,11 +586,11 @@ int SrsGoHttpServeMux::handle(std::string pattern, ISrsGoHttpHandler* handler)
return
ret
;
}
int
Srs
GoHttpServeMux
::
serve_http
(
ISrsGo
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
Srs
HttpServeMux
::
serve_http
(
ISrs
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
ISrs
Go
HttpHandler
*
h
=
NULL
;
ISrsHttpHandler
*
h
=
NULL
;
if
((
ret
=
find_handler
(
r
,
&
h
))
!=
ERROR_SUCCESS
)
{
srs_error
(
"find handler failed. ret=%d"
,
ret
);
return
ret
;
...
...
@@ -607,7 +607,7 @@ int SrsGoHttpServeMux::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r
return
ret
;
}
int
Srs
GoHttpServeMux
::
find_handler
(
SrsHttpMessage
*
r
,
ISrsGo
HttpHandler
**
ph
)
int
Srs
HttpServeMux
::
find_handler
(
SrsHttpMessage
*
r
,
ISrs
HttpHandler
**
ph
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -624,13 +624,13 @@ int SrsGoHttpServeMux::find_handler(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
}
if
(
*
ph
==
NULL
)
{
*
ph
=
new
Srs
Go
HttpNotFoundHandler
();
*
ph
=
new
SrsHttpNotFoundHandler
();
}
return
ret
;
}
int
Srs
GoHttpServeMux
::
match
(
SrsHttpMessage
*
r
,
ISrsGo
HttpHandler
**
ph
)
int
Srs
HttpServeMux
::
match
(
SrsHttpMessage
*
r
,
ISrs
HttpHandler
**
ph
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -642,12 +642,12 @@ int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
}
int
nb_matched
=
0
;
ISrs
Go
HttpHandler
*
h
=
NULL
;
ISrsHttpHandler
*
h
=
NULL
;
std
::
map
<
std
::
string
,
Srs
Go
HttpMuxEntry
*>::
iterator
it
;
std
::
map
<
std
::
string
,
SrsHttpMuxEntry
*>::
iterator
it
;
for
(
it
=
entries
.
begin
();
it
!=
entries
.
end
();
++
it
)
{
std
::
string
pattern
=
it
->
first
;
Srs
Go
HttpMuxEntry
*
entry
=
it
->
second
;
SrsHttpMuxEntry
*
entry
=
it
->
second
;
if
(
!
entry
->
enabled
)
{
continue
;
...
...
@@ -668,7 +668,7 @@ int SrsGoHttpServeMux::match(SrsHttpMessage* r, ISrsGoHttpHandler** ph)
return
ret
;
}
bool
Srs
Go
HttpServeMux
::
path_match
(
string
pattern
,
string
path
)
bool
SrsHttpServeMux
::
path_match
(
string
pattern
,
string
path
)
{
if
(
pattern
.
empty
())
{
return
false
;
...
...
@@ -692,10 +692,10 @@ bool SrsGoHttpServeMux::path_match(string pattern, string path)
return
false
;
}
Srs
GoHttpResponseWriter
::
SrsGo
HttpResponseWriter
(
SrsStSocket
*
io
)
Srs
HttpResponseWriter
::
Srs
HttpResponseWriter
(
SrsStSocket
*
io
)
{
skt
=
io
;
hdr
=
new
Srs
Go
HttpHeader
();
hdr
=
new
SrsHttpHeader
();
header_wrote
=
false
;
status
=
SRS_CONSTS_HTTP_OK
;
content_length
=
-
1
;
...
...
@@ -703,12 +703,12 @@ SrsGoHttpResponseWriter::SrsGoHttpResponseWriter(SrsStSocket* io)
header_sent
=
false
;
}
Srs
GoHttpResponseWriter
::~
SrsGo
HttpResponseWriter
()
Srs
HttpResponseWriter
::~
Srs
HttpResponseWriter
()
{
srs_freep
(
hdr
);
}
int
Srs
Go
HttpResponseWriter
::
final_request
()
int
SrsHttpResponseWriter
::
final_request
()
{
// complete the chunked encoding.
if
(
content_length
==
-
1
)
{
...
...
@@ -722,12 +722,12 @@ int SrsGoHttpResponseWriter::final_request()
return
write
(
NULL
,
0
);
}
Srs
GoHttpHeader
*
SrsGo
HttpResponseWriter
::
header
()
Srs
HttpHeader
*
Srs
HttpResponseWriter
::
header
()
{
return
hdr
;
}
int
Srs
Go
HttpResponseWriter
::
write
(
char
*
data
,
int
size
)
int
SrsHttpResponseWriter
::
write
(
char
*
data
,
int
size
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -774,7 +774,7 @@ int SrsGoHttpResponseWriter::write(char* data, int size)
return
ret
;
}
void
Srs
Go
HttpResponseWriter
::
write_header
(
int
code
)
void
SrsHttpResponseWriter
::
write_header
(
int
code
)
{
if
(
header_wrote
)
{
srs_warn
(
"http: multiple write_header calls, code=%d"
,
code
);
...
...
@@ -788,7 +788,7 @@ void SrsGoHttpResponseWriter::write_header(int code)
content_length
=
hdr
->
content_length
();
}
int
Srs
Go
HttpResponseWriter
::
send_header
(
char
*
data
,
int
size
)
int
SrsHttpResponseWriter
::
send_header
(
char
*
data
,
int
size
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_http.hpp
查看文件 @
04dc60e
...
...
@@ -47,8 +47,8 @@ class SrsHttpUri;
class
SrsHttpMessage
;
class
SrsFileReader
;
class
SrsSimpleBuffer
;
class
SrsGoHttpMuxEntry
;
class
ISrsGoHttpResponseWriter
;
class
SrsHttpMuxEntry
;
class
ISrsHttpResponseWriter
;
// http specification
// CR = <US-ASCII CR, carriage return (13)>
...
...
@@ -70,7 +70,7 @@ class ISrsGoHttpResponseWriter;
#define __SRS_HTTP_TS_SEND_BUFFER_SIZE 4096
// helper function: response in json format.
extern
int
srs_go_http_response_json
(
ISrs
Go
HttpResponseWriter
*
w
,
std
::
string
data
);
extern
int
srs_go_http_response_json
(
ISrsHttpResponseWriter
*
w
,
std
::
string
data
);
// state of message
enum
SrsHttpParseState
{
...
...
@@ -80,13 +80,13 @@ enum SrsHttpParseState {
};
// A Header represents the key-value pairs in an HTTP header.
class
Srs
Go
HttpHeader
class
SrsHttpHeader
{
private
:
std
::
map
<
std
::
string
,
std
::
string
>
headers
;
public
:
SrsGoHttpHeader
();
virtual
~
SrsGoHttpHeader
();
SrsHttpHeader
();
virtual
~
SrsHttpHeader
();
public
:
// Add adds the key, value pair to the header.
// It appends to any existing values associated with key.
...
...
@@ -124,7 +124,7 @@ public:
// A ResponseWriter interface is used by an HTTP handler to
// construct an HTTP response.
// Usage 1, response with specified length content:
// ISrs
Go
HttpResponseWriter* w; // create or get response.
// ISrsHttpResponseWriter* w; // create or get response.
// std::string msg = "Hello, HTTP!";
// w->header()->set_content_type("text/plain; charset=utf-8");
// w->header()->set_content_length(msg.length());
...
...
@@ -132,12 +132,12 @@ public:
// w->write((char*)msg.data(), (int)msg.length());
// w->final_request(); // optional flush.
// Usage 2, response with HTTP code only, zero content length.
// ISrs
Go
HttpResponseWriter* w; // create or get response.
// ISrsHttpResponseWriter* w; // create or get response.
// w->header()->set_content_length(0);
// w->write_header(SRS_CONSTS_HTTP_OK);
// w->final_request();
// Usage 3, response in chunked encoding.
// ISrs
Go
HttpResponseWriter* w; // create or get response.
// ISrsHttpResponseWriter* w; // create or get response.
// std::string msg = "Hello, HTTP!";
// w->header()->set_content_type("application/octet-stream");
// w->write_header(SRS_CONSTS_HTTP_OK);
...
...
@@ -146,11 +146,11 @@ public:
// w->write((char*)msg.data(), (int)msg.length());
// w->write((char*)msg.data(), (int)msg.length());
// w->final_request(); // required to end the chunked and flush.
class
ISrs
Go
HttpResponseWriter
class
ISrsHttpResponseWriter
{
public
:
ISrsGoHttpResponseWriter
();
virtual
~
ISrsGoHttpResponseWriter
();
ISrsHttpResponseWriter
();
virtual
~
ISrsHttpResponseWriter
();
public
:
// when chunked mode,
// final the request to complete the chunked encoding.
...
...
@@ -159,7 +159,7 @@ public:
// Header returns the header map that will be sent by WriteHeader.
// Changing the header after a call to WriteHeader (or Write) has
// no effect.
virtual
Srs
Go
HttpHeader
*
header
()
=
0
;
virtual
SrsHttpHeader
*
header
()
=
0
;
// Write writes the data to the connection as part of an HTTP reply.
// If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK)
...
...
@@ -186,38 +186,38 @@ public:
// and then return. Returning signals that the request is finished
// and that the HTTP server can move on to the next request on
// the connection.
class
ISrs
Go
HttpHandler
class
ISrsHttpHandler
{
public
:
Srs
Go
HttpMuxEntry
*
entry
;
SrsHttpMuxEntry
*
entry
;
public
:
ISrsGoHttpHandler
();
virtual
~
ISrsGoHttpHandler
();
ISrsHttpHandler
();
virtual
~
ISrsHttpHandler
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
=
0
;
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
=
0
;
};
// Redirect to a fixed URL
class
Srs
GoHttpRedirectHandler
:
public
ISrsGo
HttpHandler
class
Srs
HttpRedirectHandler
:
public
ISrs
HttpHandler
{
private
:
std
::
string
url
;
int
code
;
public
:
SrsGoHttpRedirectHandler
(
std
::
string
u
,
int
c
);
virtual
~
SrsGoHttpRedirectHandler
();
SrsHttpRedirectHandler
(
std
::
string
u
,
int
c
);
virtual
~
SrsHttpRedirectHandler
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
// NotFound replies to the request with an HTTP 404 not found error.
class
Srs
GoHttpNotFoundHandler
:
public
ISrsGo
HttpHandler
class
Srs
HttpNotFoundHandler
:
public
ISrs
HttpHandler
{
public
:
SrsGoHttpNotFoundHandler
();
virtual
~
SrsGoHttpNotFoundHandler
();
SrsHttpNotFoundHandler
();
virtual
~
SrsHttpNotFoundHandler
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
// FileServer returns a handler that serves HTTP requests
...
...
@@ -226,54 +226,54 @@ public:
// To use the operating system's file system implementation,
// use http.Dir:
//
// http.Handle("/", SrsGoHttpFileServer("/tmp"))
// http.Handle("/", SrsGoHttpFileServer("static-dir"))
class
SrsGoHttpFileServer
:
public
ISrsGoHttpHandler
// http.Handle("/", SrsHttpFileServer("/tmp"))
// http.Handle("/", SrsHttpFileServer("static-dir"))
class
SrsHttpFileServer
:
public
ISrsHttpHandler
{
protected
:
std
::
string
dir
;
public
:
SrsGoHttpFileServer
(
std
::
string
root_dir
);
virtual
~
SrsGoHttpFileServer
();
SrsHttpFileServer
(
std
::
string
root_dir
);
virtual
~
SrsHttpFileServer
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
private
:
/**
* serve the file by specified path
*/
virtual
int
serve_file
(
ISrsGoHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
);
virtual
int
serve_flv_file
(
ISrsGoHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
);
virtual
int
serve_mp4_file
(
ISrsGoHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
);
virtual
int
serve_file
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
);
virtual
int
serve_flv_file
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
);
virtual
int
serve_mp4_file
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
);
protected
:
/**
* when access flv file with x.flv?start=xxx
*/
virtual
int
serve_flv_stream
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
,
int
offset
);
virtual
int
serve_flv_stream
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
,
int
offset
);
/**
* when access mp4 file with x.mp4?range=start-end
* @param start the start offset in bytes.
* @param end the end offset in bytes. -1 to end of file.
* @remark response data in [start, end].
*/
virtual
int
serve_mp4_stream
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
,
int
start
,
int
end
);
virtual
int
serve_mp4_stream
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
,
int
start
,
int
end
);
protected
:
/**
* copy the fs to response writer in size bytes.
*/
virtual
int
copy
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsFileReader
*
fs
,
SrsHttpMessage
*
r
,
int
size
);
virtual
int
copy
(
ISrsHttpResponseWriter
*
w
,
SrsFileReader
*
fs
,
SrsHttpMessage
*
r
,
int
size
);
};
// the mux entry for server mux.
class
Srs
Go
HttpMuxEntry
class
SrsHttpMuxEntry
{
public
:
bool
explicit_match
;
ISrs
Go
HttpHandler
*
handler
;
ISrsHttpHandler
*
handler
;
std
::
string
pattern
;
bool
enabled
;
public
:
SrsGoHttpMuxEntry
();
virtual
~
SrsGoHttpMuxEntry
();
SrsHttpMuxEntry
();
virtual
~
SrsHttpMuxEntry
();
};
// ServeMux is an HTTP request multiplexer.
...
...
@@ -303,16 +303,16 @@ public:
// ServeMux also takes care of sanitizing the URL request path,
// redirecting any request containing . or .. elements to an
// equivalent .- and ..-free URL.
class
Srs
Go
HttpServeMux
class
SrsHttpServeMux
{
private
:
// the pattern handler.
std
::
map
<
std
::
string
,
Srs
Go
HttpMuxEntry
*>
entries
;
std
::
map
<
std
::
string
,
SrsHttpMuxEntry
*>
entries
;
// the vhost handler.
std
::
map
<
std
::
string
,
ISrs
Go
HttpHandler
*>
vhosts
;
std
::
map
<
std
::
string
,
ISrsHttpHandler
*>
vhosts
;
public
:
SrsGoHttpServeMux
();
virtual
~
SrsGoHttpServeMux
();
SrsHttpServeMux
();
virtual
~
SrsHttpServeMux
();
public
:
/**
* initialize the http serve mux.
...
...
@@ -321,24 +321,24 @@ public:
public
:
// Handle registers the handler for the given pattern.
// If a handler already exists for pattern, Handle panics.
virtual
int
handle
(
std
::
string
pattern
,
ISrsGoHttpHandler
*
handler
);
// interface ISrsGoHttpHandler
virtual
int
handle
(
std
::
string
pattern
,
ISrsHttpHandler
*
handler
);
// interface ISrsHttpHandler
public:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
private
:
virtual
int
find_handler
(
SrsHttpMessage
*
r
,
ISrsGoHttpHandler
**
ph
);
virtual
int
match
(
SrsHttpMessage
*
r
,
ISrsGoHttpHandler
**
ph
);
virtual
int
find_handler
(
SrsHttpMessage
*
r
,
ISrsHttpHandler
**
ph
);
virtual
int
match
(
SrsHttpMessage
*
r
,
ISrsHttpHandler
**
ph
);
virtual
bool
path_match
(
std
::
string
pattern
,
std
::
string
path
);
};
/**
* response writer use st socket
*/
class
Srs
GoHttpResponseWriter
:
public
ISrsGo
HttpResponseWriter
class
Srs
HttpResponseWriter
:
public
ISrs
HttpResponseWriter
{
private
:
SrsStSocket
*
skt
;
Srs
Go
HttpHeader
*
hdr
;
SrsHttpHeader
*
hdr
;
private
:
// reply header has been (logically) written
bool
header_wrote
;
...
...
@@ -356,11 +356,11 @@ private:
// logically written.
bool
header_sent
;
public
:
SrsGoHttpResponseWriter
(
SrsStSocket
*
io
);
virtual
~
SrsGoHttpResponseWriter
();
SrsHttpResponseWriter
(
SrsStSocket
*
io
);
virtual
~
SrsHttpResponseWriter
();
public
:
virtual
int
final_request
();
virtual
Srs
Go
HttpHeader
*
header
();
virtual
SrsHttpHeader
*
header
();
virtual
int
write
(
char
*
data
,
int
size
);
virtual
void
write_header
(
int
code
);
virtual
int
send_header
(
char
*
data
,
int
size
);
...
...
trunk/src/app/srs_app_http_api.cpp
查看文件 @
04dc60e
...
...
@@ -48,7 +48,7 @@ SrsGoApiRoot::~SrsGoApiRoot()
{
}
int
SrsGoApiRoot
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiRoot
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
ss
;
...
...
@@ -70,7 +70,7 @@ SrsGoApiApi::~SrsGoApiApi()
{
}
int
SrsGoApiApi
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiApi
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
ss
;
...
...
@@ -92,7 +92,7 @@ SrsGoApiV1::~SrsGoApiV1()
{
}
int
SrsGoApiV1
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiV1
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
ss
;
...
...
@@ -123,7 +123,7 @@ SrsGoApiVersion::~SrsGoApiVersion()
{
}
int
SrsGoApiVersion
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiVersion
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
ss
;
...
...
@@ -148,7 +148,7 @@ SrsGoApiSummaries::~SrsGoApiSummaries()
{
}
int
SrsGoApiSummaries
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiSummaries
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
ss
;
srs_api_dump_summaries
(
ss
);
...
...
@@ -163,7 +163,7 @@ SrsGoApiRusages::~SrsGoApiRusages()
{
}
int
SrsGoApiRusages
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
req
)
int
SrsGoApiRusages
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
req
)
{
std
::
stringstream
ss
;
...
...
@@ -204,7 +204,7 @@ SrsGoApiSelfProcStats::~SrsGoApiSelfProcStats()
{
}
int
SrsGoApiSelfProcStats
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiSelfProcStats
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
ss
;
...
...
@@ -274,7 +274,7 @@ SrsGoApiSystemProcStats::~SrsGoApiSystemProcStats()
{
}
int
SrsGoApiSystemProcStats
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiSystemProcStats
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
ss
;
...
...
@@ -309,7 +309,7 @@ SrsGoApiMemInfos::~SrsGoApiMemInfos()
{
}
int
SrsGoApiMemInfos
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiMemInfos
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
ss
;
...
...
@@ -345,7 +345,7 @@ SrsGoApiAuthors::~SrsGoApiAuthors()
{
}
int
SrsGoApiAuthors
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiAuthors
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
ss
;
...
...
@@ -370,7 +370,7 @@ SrsGoApiRequests::~SrsGoApiRequests()
{
}
int
SrsGoApiRequests
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiRequests
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
SrsHttpMessage
*
req
=
r
;
...
...
@@ -431,7 +431,7 @@ SrsGoApiVhosts::~SrsGoApiVhosts()
{
}
int
SrsGoApiVhosts
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiVhosts
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
data
;
SrsStatistic
*
stat
=
SrsStatistic
::
instance
();
...
...
@@ -456,7 +456,7 @@ SrsGoApiStreams::~SrsGoApiStreams()
{
}
int
SrsGoApiStreams
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsGoApiStreams
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
std
::
stringstream
data
;
SrsStatistic
*
stat
=
SrsStatistic
::
instance
();
...
...
@@ -473,7 +473,7 @@ int SrsGoApiStreams::serve_http(ISrsGoHttpResponseWriter* w, SrsHttpMessage* r)
return
srs_go_http_response_json
(
w
,
ss
.
str
());
}
SrsHttpApi
::
SrsHttpApi
(
SrsServer
*
svr
,
st_netfd_t
fd
,
Srs
Go
HttpServeMux
*
m
)
SrsHttpApi
::
SrsHttpApi
(
SrsServer
*
svr
,
st_netfd_t
fd
,
SrsHttpServeMux
*
m
)
:
SrsConnection
(
svr
,
fd
)
{
mux
=
m
;
...
...
@@ -535,7 +535,7 @@ int SrsHttpApi::do_cycle()
SrsAutoFree
(
SrsHttpMessage
,
req
);
// ok, handle http request.
Srs
Go
HttpResponseWriter
writer
(
&
skt
);
SrsHttpResponseWriter
writer
(
&
skt
);
if
((
ret
=
process_request
(
&
writer
,
req
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -544,7 +544,7 @@ int SrsHttpApi::do_cycle()
return
ret
;
}
int
SrsHttpApi
::
process_request
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsHttpApi
::
process_request
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_http_api.hpp
查看文件 @
04dc60e
...
...
@@ -42,131 +42,131 @@ class SrsHttpHandler;
#include <srs_app_http.hpp>
// for http root.
class
SrsGoApiRoot
:
public
ISrs
Go
HttpHandler
class
SrsGoApiRoot
:
public
ISrsHttpHandler
{
public
:
SrsGoApiRoot
();
virtual
~
SrsGoApiRoot
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiApi
:
public
ISrs
Go
HttpHandler
class
SrsGoApiApi
:
public
ISrsHttpHandler
{
public
:
SrsGoApiApi
();
virtual
~
SrsGoApiApi
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiV1
:
public
ISrs
Go
HttpHandler
class
SrsGoApiV1
:
public
ISrsHttpHandler
{
public
:
SrsGoApiV1
();
virtual
~
SrsGoApiV1
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiVersion
:
public
ISrs
Go
HttpHandler
class
SrsGoApiVersion
:
public
ISrsHttpHandler
{
public
:
SrsGoApiVersion
();
virtual
~
SrsGoApiVersion
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiSummaries
:
public
ISrs
Go
HttpHandler
class
SrsGoApiSummaries
:
public
ISrsHttpHandler
{
public
:
SrsGoApiSummaries
();
virtual
~
SrsGoApiSummaries
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiRusages
:
public
ISrs
Go
HttpHandler
class
SrsGoApiRusages
:
public
ISrsHttpHandler
{
public
:
SrsGoApiRusages
();
virtual
~
SrsGoApiRusages
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiSelfProcStats
:
public
ISrs
Go
HttpHandler
class
SrsGoApiSelfProcStats
:
public
ISrsHttpHandler
{
public
:
SrsGoApiSelfProcStats
();
virtual
~
SrsGoApiSelfProcStats
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiSystemProcStats
:
public
ISrs
Go
HttpHandler
class
SrsGoApiSystemProcStats
:
public
ISrsHttpHandler
{
public
:
SrsGoApiSystemProcStats
();
virtual
~
SrsGoApiSystemProcStats
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiMemInfos
:
public
ISrs
Go
HttpHandler
class
SrsGoApiMemInfos
:
public
ISrsHttpHandler
{
public
:
SrsGoApiMemInfos
();
virtual
~
SrsGoApiMemInfos
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiAuthors
:
public
ISrs
Go
HttpHandler
class
SrsGoApiAuthors
:
public
ISrsHttpHandler
{
public
:
SrsGoApiAuthors
();
virtual
~
SrsGoApiAuthors
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiRequests
:
public
ISrs
Go
HttpHandler
class
SrsGoApiRequests
:
public
ISrsHttpHandler
{
public
:
SrsGoApiRequests
();
virtual
~
SrsGoApiRequests
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiVhosts
:
public
ISrs
Go
HttpHandler
class
SrsGoApiVhosts
:
public
ISrsHttpHandler
{
public
:
SrsGoApiVhosts
();
virtual
~
SrsGoApiVhosts
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsGoApiStreams
:
public
ISrs
Go
HttpHandler
class
SrsGoApiStreams
:
public
ISrsHttpHandler
{
public
:
SrsGoApiStreams
();
virtual
~
SrsGoApiStreams
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
class
SrsHttpApi
:
public
SrsConnection
{
private
:
SrsHttpParser
*
parser
;
Srs
Go
HttpServeMux
*
mux
;
SrsHttpServeMux
*
mux
;
bool
crossdomain_required
;
public
:
SrsHttpApi
(
SrsServer
*
svr
,
st_netfd_t
fd
,
Srs
Go
HttpServeMux
*
m
);
SrsHttpApi
(
SrsServer
*
svr
,
st_netfd_t
fd
,
SrsHttpServeMux
*
m
);
virtual
~
SrsHttpApi
();
public
:
virtual
void
kbps_resample
();
...
...
@@ -177,7 +177,7 @@ public:
protected
:
virtual
int
do_cycle
();
private
:
virtual
int
process_request
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
process_request
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
#endif
...
...
trunk/src/app/srs_app_http_conn.cpp
查看文件 @
04dc60e
...
...
@@ -50,7 +50,7 @@ using namespace std;
#include <srs_app_pithy_print.hpp>
SrsVodStream
::
SrsVodStream
(
string
root_dir
)
:
Srs
Go
HttpFileServer
(
root_dir
)
:
SrsHttpFileServer
(
root_dir
)
{
}
...
...
@@ -58,7 +58,7 @@ SrsVodStream::~SrsVodStream()
{
}
int
SrsVodStream
::
serve_flv_stream
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
,
int
offset
)
int
SrsVodStream
::
serve_flv_stream
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
,
int
offset
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -142,7 +142,7 @@ int SrsVodStream::serve_flv_stream(ISrsGoHttpResponseWriter* w, SrsHttpMessage*
return
ret
;
}
int
SrsVodStream
::
serve_mp4_stream
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
,
int
start
,
int
end
)
int
SrsVodStream
::
serve_mp4_stream
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
string
fullpath
,
int
start
,
int
end
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -517,7 +517,7 @@ int SrsMp3StreamEncoder::dump_cache(SrsConsumer* consumer)
return
cache
->
dump_cache
(
consumer
);
}
SrsStreamWriter
::
SrsStreamWriter
(
ISrs
Go
HttpResponseWriter
*
w
)
SrsStreamWriter
::
SrsStreamWriter
(
ISrsHttpResponseWriter
*
w
)
{
writer
=
w
;
}
...
...
@@ -565,7 +565,7 @@ SrsLiveStream::~SrsLiveStream()
srs_freep
(
req
);
}
int
SrsLiveStream
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsLiveStream
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -708,7 +708,7 @@ void SrsHlsM3u8Stream::set_m3u8(std::string v)
m3u8
=
v
;
}
int
SrsHlsM3u8Stream
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsHlsM3u8Stream
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -740,7 +740,7 @@ void SrsHlsTsStream::set_ts(std::string v)
ts
=
v
;
}
int
SrsHlsTsStream
::
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsHlsTsStream
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -879,9 +879,9 @@ int SrsHttpServer::mount_hls(SrsRequest* r)
SrsHlsEntry
*
entry
=
hls
[
r
->
vhost
];
// TODO: FIXME: supports reload.
std
::
map
<
std
::
string
,
ISrs
Go
HttpHandler
*>::
iterator
it
;
std
::
map
<
std
::
string
,
ISrsHttpHandler
*>::
iterator
it
;
for
(
it
=
entry
->
streams
.
begin
();
it
!=
entry
->
streams
.
end
();
++
it
)
{
ISrs
Go
HttpHandler
*
stream
=
it
->
second
;
ISrsHttpHandler
*
stream
=
it
->
second
;
stream
->
entry
->
enabled
=
true
;
}
...
...
@@ -911,7 +911,7 @@ int SrsHttpServer::hls_update_m3u8(SrsRequest* r, string m3u8)
mount
=
srs_string_replace
(
mount
,
SRS_CONSTS_RTMP_DEFAULT_VHOST
"/"
,
"/"
);
if
(
entry
->
streams
.
find
(
mount
)
==
entry
->
streams
.
end
())
{
ISrs
Go
HttpHandler
*
he
=
new
SrsHlsM3u8Stream
();
ISrsHttpHandler
*
he
=
new
SrsHlsM3u8Stream
();
entry
->
streams
[
mount
]
=
he
;
if
((
ret
=
mux
.
handle
(
mount
,
he
))
!=
ERROR_SUCCESS
)
{
...
...
@@ -962,7 +962,7 @@ int SrsHttpServer::hls_update_ts(SrsRequest* r, string uri, string ts)
mount
+=
uri
;
if
(
entry
->
streams
.
find
(
mount
)
==
entry
->
streams
.
end
())
{
ISrs
Go
HttpHandler
*
he
=
new
SrsHlsTsStream
();
ISrsHttpHandler
*
he
=
new
SrsHlsTsStream
();
entry
->
streams
[
mount
]
=
he
;
if
((
ret
=
mux
.
handle
(
mount
,
he
))
!=
ERROR_SUCCESS
)
{
...
...
@@ -990,9 +990,9 @@ void SrsHttpServer::unmount_hls(SrsRequest* r)
SrsHlsEntry
*
entry
=
hls
[
r
->
vhost
];
std
::
map
<
std
::
string
,
ISrs
Go
HttpHandler
*>::
iterator
it
;
std
::
map
<
std
::
string
,
ISrsHttpHandler
*>::
iterator
it
;
for
(
it
=
entry
->
streams
.
begin
();
it
!=
entry
->
streams
.
end
();
++
it
)
{
ISrs
Go
HttpHandler
*
stream
=
it
->
second
;
ISrsHttpHandler
*
stream
=
it
->
second
;
stream
->
entry
->
enabled
=
false
;
}
}
...
...
@@ -1202,7 +1202,7 @@ int SrsHttpConn::do_cycle()
SrsAutoFree
(
SrsHttpMessage
,
req
);
// ok, handle http request.
Srs
Go
HttpResponseWriter
writer
(
&
skt
);
SrsHttpResponseWriter
writer
(
&
skt
);
if
((
ret
=
process_request
(
&
writer
,
req
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
...
...
@@ -1211,7 +1211,7 @@ int SrsHttpConn::do_cycle()
return
ret
;
}
int
SrsHttpConn
::
process_request
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
int
SrsHttpConn
::
process_request
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/app/srs_app_http_conn.hpp
查看文件 @
04dc60e
...
...
@@ -59,14 +59,14 @@ class SrsSharedPtrMessage;
* server will write flv header and sequence header,
* then seek(10240) and response flv tag data.
*/
class
SrsVodStream
:
public
Srs
Go
HttpFileServer
class
SrsVodStream
:
public
SrsHttpFileServer
{
public
:
SrsVodStream
(
std
::
string
root_dir
);
virtual
~
SrsVodStream
();
protected
:
virtual
int
serve_flv_stream
(
ISrsGoHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
,
int
offset
);
virtual
int
serve_mp4_stream
(
ISrsGoHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
,
int
start
,
int
end
);
virtual
int
serve_flv_stream
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
,
int
offset
);
virtual
int
serve_mp4_stream
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
,
std
::
string
fullpath
,
int
start
,
int
end
);
};
/**
...
...
@@ -214,9 +214,9 @@ public:
class
SrsStreamWriter
:
public
SrsFileWriter
{
private
:
ISrs
Go
HttpResponseWriter
*
writer
;
ISrsHttpResponseWriter
*
writer
;
public
:
SrsStreamWriter
(
ISrs
Go
HttpResponseWriter
*
w
);
SrsStreamWriter
(
ISrsHttpResponseWriter
*
w
);
virtual
~
SrsStreamWriter
();
public
:
virtual
int
open
(
std
::
string
file
);
...
...
@@ -232,7 +232,7 @@ public:
* the flv live stream supports access rtmp in flv over http.
* srs will remux rtmp to flv streaming.
*/
class
SrsLiveStream
:
public
ISrs
Go
HttpHandler
class
SrsLiveStream
:
public
ISrsHttpHandler
{
private
:
SrsRequest
*
req
;
...
...
@@ -242,7 +242,7 @@ public:
SrsLiveStream
(
SrsSource
*
s
,
SrsRequest
*
r
,
SrsStreamCache
*
c
);
virtual
~
SrsLiveStream
();
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
private
:
virtual
int
streaming_send_messages
(
ISrsStreamEncoder
*
enc
,
SrsSharedPtrMessage
**
msgs
,
int
nb_msgs
);
};
...
...
@@ -263,7 +263,7 @@ struct SrsLiveEntry
/**
* the m3u8 stream handler.
*/
class
SrsHlsM3u8Stream
:
public
ISrs
Go
HttpHandler
class
SrsHlsM3u8Stream
:
public
ISrsHttpHandler
{
private
:
std
::
string
m3u8
;
...
...
@@ -273,13 +273,13 @@ public:
public
:
virtual
void
set_m3u8
(
std
::
string
v
);
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
/**
* the ts stream handler.
*/
class
SrsHlsTsStream
:
public
ISrs
Go
HttpHandler
class
SrsHlsTsStream
:
public
ISrsHttpHandler
{
private
:
std
::
string
ts
;
...
...
@@ -289,7 +289,7 @@ public:
public
:
virtual
void
set_ts
(
std
::
string
v
);
public
:
virtual
int
serve_http
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
/**
...
...
@@ -302,7 +302,7 @@ struct SrsHlsEntry
// key: the m3u8/ts file path.
// value: the http handler.
std
::
map
<
std
::
string
,
ISrs
Go
HttpHandler
*>
streams
;
std
::
map
<
std
::
string
,
ISrsHttpHandler
*>
streams
;
SrsHlsEntry
();
};
...
...
@@ -314,7 +314,7 @@ struct SrsHlsEntry
class
SrsHttpServer
:
public
ISrsReloadHandler
{
public
:
Srs
Go
HttpServeMux
mux
;
SrsHttpServeMux
mux
;
// the flv live streaming template.
std
::
map
<
std
::
string
,
SrsLiveEntry
*>
flvs
;
// the hls live streaming template.
...
...
@@ -362,7 +362,7 @@ public:
protected
:
virtual
int
do_cycle
();
private
:
virtual
int
process_request
(
ISrs
Go
HttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
virtual
int
process_request
(
ISrsHttpResponseWriter
*
w
,
SrsHttpMessage
*
r
);
};
#endif
...
...
trunk/src/app/srs_app_server.cpp
查看文件 @
04dc60e
...
...
@@ -398,7 +398,7 @@ SrsServer::SrsServer()
// for some global instance is not ready now,
// new these objects in initialize instead.
#ifdef SRS_AUTO_HTTP_API
http_api_mux
=
new
Srs
Go
HttpServeMux
();
http_api_mux
=
new
SrsHttpServeMux
();
#endif
#ifdef SRS_AUTO_HTTP_SERVER
http_stream_mux
=
new
SrsHttpServer
();
...
...
trunk/src/app/srs_app_server.hpp
查看文件 @
04dc60e
...
...
@@ -41,7 +41,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class
SrsServer
;
class
SrsConnection
;
class
Srs
Go
HttpServeMux
;
class
SrsHttpServeMux
;
class
SrsHttpServer
;
class
SrsIngester
;
class
SrsHttpHeartbeat
;
...
...
@@ -178,7 +178,7 @@ class SrsServer : virtual public ISrsReloadHandler
{
private
:
#ifdef SRS_AUTO_HTTP_API
Srs
Go
HttpServeMux
*
http_api_mux
;
SrsHttpServeMux
*
http_api_mux
;
#endif
#ifdef SRS_AUTO_HTTP_SERVER
SrsHttpServer
*
http_stream_mux
;
...
...
请
注册
或
登录
后发表评论