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
2016-12-15 14:10:02 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f30b3073a2bec6d6b2c37bd5f30203b0541bb496
f30b3073
1 parent
3df8f118
refine the cros of api for flv
显示空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
83 行增加
和
30 行删除
trunk/src/app/srs_app_http_api.cpp
trunk/src/app/srs_app_http_api.hpp
trunk/src/protocol/srs_http_stack.cpp
trunk/src/protocol/srs_http_stack.hpp
trunk/src/app/srs_app_http_api.cpp
查看文件 @
f30b307
...
...
@@ -1312,8 +1312,8 @@ SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m
:
SrsConnection
(
cm
,
fd
,
cip
)
{
mux
=
m
;
cros
=
new
SrsHttpCrosMux
();
parser
=
new
SrsHttpParser
();
crossdomain_required
=
false
;
_srs_config
->
subscribe
(
this
);
}
...
...
@@ -1321,6 +1321,7 @@ SrsHttpApi::SrsHttpApi(IConnectionManager* cm, st_netfd_t fd, SrsHttpServeMux* m
SrsHttpApi
::~
SrsHttpApi
()
{
srs_freep
(
parser
);
srs_freep
(
cros
);
_srs_config
->
unsubscribe
(
this
);
}
...
...
@@ -1366,8 +1367,11 @@ int SrsHttpApi::do_cycle()
// @see https://github.com/ossrs/srs/issues/398
skt
.
set_recv_timeout
(
SRS_HTTP_RECV_TIMEOUT_US
);
// initialize the crossdomain
crossdomain_enabled
=
_srs_config
->
get_http_api_crossdomain
();
// initialize the cros, which will proxy to mux.
bool
crossdomain_enabled
=
_srs_config
->
get_http_api_crossdomain
();
if
((
ret
=
cros
->
initialize
(
mux
,
crossdomain_enabled
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
// process http messages.
while
(
!
disposed
)
{
...
...
@@ -1420,31 +1424,8 @@ int SrsHttpApi::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
r
->
method_str
().
c_str
(),
r
->
url
().
c_str
(),
r
->
content_length
(),
hm
->
is_chunked
(),
hm
->
is_infinite_chunked
());
// method is OPTIONS and enable crossdomain, required crossdomain header.
if
(
r
->
is_http_options
()
&&
_srs_config
->
get_http_api_crossdomain
())
{
crossdomain_required
=
true
;
}
// whenever crossdomain required, set crossdomain header.
if
(
crossdomain_required
)
{
w
->
header
()
->
set
(
"Access-Control-Allow-Origin"
,
"*"
);
w
->
header
()
->
set
(
"Access-Control-Allow-Methods"
,
"GET, POST, HEAD, PUT, DELETE"
);
w
->
header
()
->
set
(
"Access-Control-Allow-Headers"
,
"Cache-Control,X-Proxy-Authorization,X-Requested-With,Content-Type"
);
}
// handle the http options.
if
(
r
->
is_http_options
())
{
w
->
header
()
->
set_content_length
(
0
);
if
(
_srs_config
->
get_http_api_crossdomain
())
{
w
->
write_header
(
SRS_CONSTS_HTTP_OK
);
}
else
{
w
->
write_header
(
SRS_CONSTS_HTTP_MethodNotAllowed
);
}
return
w
->
final_request
();
}
// use default server mux to serve http request.
if
((
ret
=
mux
->
serve_http
(
w
,
r
))
!=
ERROR_SUCCESS
)
{
if
((
ret
=
cros
->
serve_http
(
w
,
r
))
!=
ERROR_SUCCESS
)
{
if
(
!
srs_is_client_gracefully_close
(
ret
))
{
srs_error
(
"serve http msg failed. ret=%d"
,
ret
);
}
...
...
@@ -1456,7 +1437,12 @@ int SrsHttpApi::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
int
SrsHttpApi
::
on_reload_http_api_crossdomain
()
{
crossdomain_enabled
=
_srs_config
->
get_http_api_crossdomain
();
int
ret
=
ERROR_SUCCESS
;
bool
crossdomain_enabled
=
_srs_config
->
get_http_api_crossdomain
();
if
((
ret
=
cros
->
initialize
(
mux
,
crossdomain_enabled
))
!=
ERROR_SUCCESS
)
{
return
ret
;
}
return
ERROR_SUCCESS
;
}
...
...
trunk/src/app/srs_app_http_api.hpp
查看文件 @
f30b307
...
...
@@ -211,9 +211,8 @@ class SrsHttpApi : virtual public SrsConnection, virtual public ISrsReloadHandle
{
private
:
SrsHttpParser
*
parser
;
SrsHttpCrosMux
*
cros
;
SrsHttpServeMux
*
mux
;
bool
crossdomain_required
;
bool
crossdomain_enabled
;
public
:
SrsHttpApi
(
IConnectionManager
*
cm
,
st_netfd_t
fd
,
SrsHttpServeMux
*
m
,
std
::
string
cip
);
virtual
~
SrsHttpApi
();
...
...
trunk/src/protocol/srs_http_stack.cpp
查看文件 @
f30b307
...
...
@@ -761,6 +761,54 @@ bool SrsHttpServeMux::path_match(string pattern, string path)
return
false
;
}
SrsHttpCrosMux
::
SrsHttpCrosMux
()
{
next
=
NULL
;
enabled
=
false
;
required
=
false
;
}
SrsHttpCrosMux
::~
SrsHttpCrosMux
()
{
}
int
SrsHttpCrosMux
::
initialize
(
ISrsHttpServeMux
*
worker
,
bool
cros_enabled
)
{
next
=
worker
;
enabled
=
cros_enabled
;
return
ERROR_SUCCESS
;
}
int
SrsHttpCrosMux
::
serve_http
(
ISrsHttpResponseWriter
*
w
,
ISrsHttpMessage
*
r
)
{
// method is OPTIONS and enable crossdomain, required crossdomain header.
if
(
r
->
is_http_options
()
&&
enabled
)
{
required
=
true
;
}
// whenever crossdomain required, set crossdomain header.
if
(
required
)
{
w
->
header
()
->
set
(
"Access-Control-Allow-Origin"
,
"*"
);
w
->
header
()
->
set
(
"Access-Control-Allow-Methods"
,
"GET, POST, HEAD, PUT, DELETE"
);
w
->
header
()
->
set
(
"Access-Control-Allow-Headers"
,
"Cache-Control,X-Proxy-Authorization,X-Requested-With,Content-Type"
);
}
// handle the http options.
if
(
r
->
is_http_options
())
{
w
->
header
()
->
set_content_length
(
0
);
if
(
enabled
)
{
w
->
write_header
(
SRS_CONSTS_HTTP_OK
);
}
else
{
w
->
write_header
(
SRS_CONSTS_HTTP_MethodNotAllowed
);
}
return
w
->
final_request
();
}
srs_assert
(
next
);
return
next
->
serve_http
(
w
,
r
);
}
ISrsHttpMessage
::
ISrsHttpMessage
()
{
_http_ts_send_buffer
=
new
char
[
SRS_HTTP_TS_SEND_BUFFER_SIZE
];
...
...
trunk/src/protocol/srs_http_stack.hpp
查看文件 @
f30b307
...
...
@@ -442,6 +442,26 @@ private:
virtual
bool
path_match
(
std
::
string
pattern
,
std
::
string
path
);
};
/**
* The filter http mux, directly serve the http CROS requests,
* while proxy to the worker mux for services.
*/
class
SrsHttpCrosMux
:
public
ISrsHttpServeMux
{
private
:
bool
required
;
bool
enabled
;
ISrsHttpServeMux
*
next
;
public
:
SrsHttpCrosMux
();
virtual
~
SrsHttpCrosMux
();
public
:
virtual
int
initialize
(
ISrsHttpServeMux
*
worker
,
bool
cros_enabled
);
// interface ISrsHttpServeMux
public:
virtual
int
serve_http
(
ISrsHttpResponseWriter
*
w
,
ISrsHttpMessage
*
r
);
};
// for http header.
typedef
std
::
pair
<
std
::
string
,
std
::
string
>
SrsHttpHeaderField
;
...
...
请
注册
或
登录
后发表评论