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
2014-04-03 16:39:55 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4984631cd6a4f82c096d8c5b5abac69035cfbc99
4984631c
1 parent
133a6f0d
refine the http crossdomain, send it only required
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
58 行增加
和
18 行删除
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.cpp
查看文件 @
4984631
...
...
@@ -84,6 +84,7 @@ bool SrsHttpHandler::can_handle(const char* /*path*/, int /*length*/, const char
int
SrsHttpHandler
::
process_request
(
SrsSocket
*
skt
,
SrsHttpMessage
*
req
)
{
if
(
req
->
method
()
==
HTTP_OPTIONS
)
{
req
->
set_requires_crossdomain
(
true
);
return
res_options
(
skt
);
}
...
...
@@ -101,7 +102,7 @@ int SrsHttpHandler::process_request(SrsSocket* skt, SrsHttpMessage* req)
<<
JOBJECT_END
<<
JOBJECT_END
;
return
res_error
(
skt
,
status_code
,
reason_phrase
,
ss
.
str
());
return
res_error
(
skt
,
req
,
status_code
,
reason_phrase
,
ss
.
str
());
}
return
do_process_request
(
skt
,
req
);
...
...
@@ -266,37 +267,52 @@ int SrsHttpHandler::res_options(SrsSocket* skt)
return
res_flush
(
skt
,
ss
);
}
int
SrsHttpHandler
::
res_text
(
SrsSocket
*
skt
,
std
::
string
body
)
int
SrsHttpHandler
::
res_text
(
SrsSocket
*
skt
,
SrsHttpMessage
*
req
,
std
::
string
body
)
{
std
::
stringstream
ss
;
res_status_line
(
ss
)
->
res_content_type
(
ss
)
->
res_content_length
(
ss
,
(
int
)
body
.
length
())
->
res_enable_crossdomain
(
ss
)
->
res_header_eof
(
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_json
(
SrsSocket
*
skt
,
std
::
string
json
)
int
SrsHttpHandler
::
res_json
(
SrsSocket
*
skt
,
SrsHttpMessage
*
req
,
std
::
string
json
)
{
std
::
stringstream
ss
;
res_status_line
(
ss
)
->
res_content_type_json
(
ss
)
->
res_content_length
(
ss
,
(
int
)
json
.
length
())
->
res_enable_crossdomain
(
ss
)
->
res_header_eof
(
ss
)
->
res_content_length
(
ss
,
(
int
)
json
.
length
());
if
(
req
->
requires_crossdomain
())
{
res_enable_crossdomain
(
ss
);
}
res_header_eof
(
ss
)
->
res_body
(
ss
,
json
);
return
res_flush
(
skt
,
ss
);
}
int
SrsHttpHandler
::
res_error
(
SrsSocket
*
skt
,
int
code
,
std
::
string
reason_phrase
,
std
::
string
body
)
int
SrsHttpHandler
::
res_error
(
SrsSocket
*
skt
,
SrsHttpMessage
*
req
,
int
code
,
std
::
string
reason_phrase
,
std
::
string
body
)
{
std
::
stringstream
ss
;
res_status_line_error
(
ss
,
code
,
reason_phrase
)
->
res_content_type_json
(
ss
)
->
res_content_length
(
ss
,
(
int
)
body
.
length
())
->
res_enable_crossdomain
(
ss
)
->
res_header_eof
(
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
);
...
...
@@ -319,6 +335,7 @@ SrsHttpMessage::SrsHttpMessage()
_state
=
SrsHttpParseStateInit
;
_uri
=
new
SrsHttpUri
();
_match
=
NULL
;
_requires_crossdomain
=
false
;
}
SrsHttpMessage
::~
SrsHttpMessage
()
...
...
@@ -404,6 +421,11 @@ SrsHttpHandlerMatch* SrsHttpMessage::match()
return
_match
;
}
bool
SrsHttpMessage
::
requires_crossdomain
()
{
return
_requires_crossdomain
;
}
void
SrsHttpMessage
::
set_url
(
std
::
string
url
)
{
_url
=
url
;
...
...
@@ -425,6 +447,11 @@ void SrsHttpMessage::set_match(SrsHttpHandlerMatch* match)
_match
=
match
;
}
void
SrsHttpMessage
::
set_requires_crossdomain
(
bool
requires_crossdomain
)
{
_requires_crossdomain
=
requires_crossdomain
;
}
void
SrsHttpMessage
::
append_body
(
const
char
*
body
,
int
length
)
{
_body
->
append
(
body
,
length
);
...
...
trunk/src/app/srs_app_http.hpp
查看文件 @
4984631
...
...
@@ -236,9 +236,9 @@ public:
virtual
int
res_flush
(
SrsSocket
*
skt
,
std
::
stringstream
&
ss
);
public
:
virtual
int
res_options
(
SrsSocket
*
skt
);
virtual
int
res_text
(
SrsSocket
*
skt
,
std
::
string
body
);
virtual
int
res_json
(
SrsSocket
*
skt
,
std
::
string
json
);
virtual
int
res_error
(
SrsSocket
*
skt
,
int
code
,
std
::
string
reason_phrase
,
std
::
string
body
);
virtual
int
res_text
(
SrsSocket
*
skt
,
SrsHttpMessage
*
req
,
std
::
string
body
);
virtual
int
res_json
(
SrsSocket
*
skt
,
SrsHttpMessage
*
req
,
std
::
string
json
);
virtual
int
res_error
(
SrsSocket
*
skt
,
SrsHttpMessage
*
req
,
int
code
,
std
::
string
reason_phrase
,
std
::
string
body
);
// object creator
public:
/**
...
...
@@ -283,6 +283,10 @@ private:
* best matched handler.
*/
SrsHttpHandlerMatch
*
_match
;
/**
* whether the message requires crossdomain.
*/
bool
_requires_crossdomain
;
public
:
SrsHttpMessage
();
virtual
~
SrsHttpMessage
();
...
...
@@ -299,10 +303,12 @@ public:
virtual
int64_t
body_size
();
virtual
int64_t
content_length
();
virtual
SrsHttpHandlerMatch
*
match
();
virtual
bool
requires_crossdomain
();
virtual
void
set_url
(
std
::
string
url
);
virtual
void
set_state
(
SrsHttpParseState
state
);
virtual
void
set_header
(
http_parser
*
header
);
virtual
void
set_match
(
SrsHttpHandlerMatch
*
match
);
virtual
void
set_requires_crossdomain
(
bool
requires_crossdomain
);
virtual
void
append_body
(
const
char
*
body
,
int
length
);
};
...
...
trunk/src/app/srs_app_http_api.cpp
查看文件 @
4984631
...
...
@@ -80,7 +80,7 @@ int SrsApiRoot::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
<<
JOBJECT_END
<<
JOBJECT_END
;
return
res_json
(
skt
,
ss
.
str
());
return
res_json
(
skt
,
req
,
ss
.
str
());
}
SrsApiApi
::
SrsApiApi
()
...
...
@@ -108,7 +108,7 @@ int SrsApiApi::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
<<
JOBJECT_END
<<
JOBJECT_END
;
return
res_json
(
skt
,
ss
.
str
());
return
res_json
(
skt
,
req
,
ss
.
str
());
}
SrsApiV1
::
SrsApiV1
()
...
...
@@ -138,7 +138,7 @@ int SrsApiV1::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
<<
JOBJECT_END
<<
JOBJECT_END
;
return
res_json
(
skt
,
ss
.
str
());
return
res_json
(
skt
,
req
,
ss
.
str
());
}
SrsApiVersion
::
SrsApiVersion
()
...
...
@@ -168,7 +168,7 @@ int SrsApiVersion::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
<<
JOBJECT_END
<<
JOBJECT_END
;
return
res_json
(
skt
,
ss
.
str
());
return
res_json
(
skt
,
req
,
ss
.
str
());
}
SrsApiAuthors
::
SrsApiAuthors
()
...
...
@@ -197,7 +197,7 @@ int SrsApiAuthors::do_process_request(SrsSocket* skt, SrsHttpMessage* req)
<<
JOBJECT_END
<<
JOBJECT_END
;
return
res_json
(
skt
,
ss
.
str
());
return
res_json
(
skt
,
req
,
ss
.
str
());
}
SrsHttpApi
::
SrsHttpApi
(
SrsServer
*
srs_server
,
st_netfd_t
client_stfd
,
SrsHttpHandler
*
_handler
)
...
...
@@ -205,6 +205,7 @@ SrsHttpApi::SrsHttpApi(SrsServer* srs_server, st_netfd_t client_stfd, SrsHttpHan
{
parser
=
new
SrsHttpParser
();
handler
=
_handler
;
requires_crossdomain
=
false
;
}
SrsHttpApi
::~
SrsHttpApi
()
...
...
@@ -284,6 +285,7 @@ int SrsHttpApi::process_request(SrsSocket* skt, SrsHttpMessage* req)
srs_info
(
"best match handler, matched_url=%s"
,
p
->
matched_url
.
c_str
());
req
->
set_match
(
p
);
req
->
set_requires_crossdomain
(
requires_crossdomain
);
// use handler to process request.
if
((
ret
=
p
->
handler
->
process_request
(
skt
,
req
))
!=
ERROR_SUCCESS
)
{
...
...
@@ -291,6 +293,10 @@ int SrsHttpApi::process_request(SrsSocket* skt, SrsHttpMessage* req)
return
ret
;
}
if
(
req
->
requires_crossdomain
())
{
requires_crossdomain
=
true
;
}
return
ret
;
}
...
...
trunk/src/app/srs_app_http_api.hpp
查看文件 @
4984631
...
...
@@ -98,6 +98,7 @@ class SrsHttpApi : public SrsConnection
private
:
SrsHttpParser
*
parser
;
SrsHttpHandler
*
handler
;
bool
requires_crossdomain
;
public
:
SrsHttpApi
(
SrsServer
*
srs_server
,
st_netfd_t
client_stfd
,
SrsHttpHandler
*
_handler
);
virtual
~
SrsHttpApi
();
...
...
请
注册
或
登录
后发表评论