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-08-23 00:01:03 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e43d4e46b465c85ec1d9848fef31ea69099d8092
e43d4e46
1 parent
baa70d4d
support JSONP DELTE/POST/PUT
隐藏空白字符变更
内嵌
并排对比
正在显示
4 个修改的文件
包含
50 行增加
和
12 行删除
trunk/src/app/srs_app_http_api.cpp
trunk/src/app/srs_app_http_conn.cpp
trunk/src/app/srs_app_http_conn.hpp
trunk/src/protocol/srs_http_stack.hpp
trunk/src/app/srs_app_http_api.cpp
查看文件 @
e43d4e4
...
...
@@ -106,29 +106,25 @@ int srs_api_response_json_code(ISrsHttpResponseWriter* w, int code)
int
srs_api_response
(
ISrsHttpResponseWriter
*
w
,
ISrsHttpMessage
*
r
,
std
::
string
json
)
{
string
callback
=
r
->
query_get
(
"callback"
);
bool
jsonp
=
!
callback
.
empty
();
// no jsonp, directly response.
if
(
!
jsonp
)
{
if
(
!
r
->
is_jsonp
()
)
{
return
srs_api_response_json
(
w
,
json
);
}
// jsonp, get function name from query("callback")
string
callback
=
r
->
query_get
(
"callback"
);
return
srs_api_response_jsonp
(
w
,
callback
,
json
);
}
int
srs_api_response_code
(
ISrsHttpResponseWriter
*
w
,
ISrsHttpMessage
*
r
,
int
code
)
{
string
callback
=
r
->
query_get
(
"callback"
);
bool
jsonp
=
!
callback
.
empty
();
// no jsonp, directly response.
if
(
!
jsonp
)
{
if
(
!
r
->
is_jsonp
()
)
{
return
srs_api_response_json_code
(
w
,
code
);
}
// jsonp, get function name from query("callback")
string
callback
=
r
->
query_get
(
"callback"
);
return
srs_api_response_jsonp_code
(
w
,
callback
,
code
);
}
...
...
trunk/src/app/srs_app_http_conn.cpp
查看文件 @
e43d4e4
...
...
@@ -494,6 +494,7 @@ SrsHttpMessage::SrsHttpMessage(SrsStSocket* io, SrsConnection* c) : ISrsHttpMess
_uri
=
new
SrsHttpUri
();
_body
=
new
SrsHttpResponseReader
(
this
,
io
);
_http_ts_send_buffer
=
new
char
[
SRS_HTTP_TS_SEND_BUFFER_SIZE
];
jsonp
=
false
;
}
SrsHttpMessage
::~
SrsHttpMessage
()
...
...
@@ -570,6 +571,14 @@ int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body,
_ext
=
""
;
}
// parse jsonp request message.
if
(
!
query_get
(
"callback"
).
empty
())
{
jsonp
=
true
;
}
if
(
jsonp
)
{
jsonp_method
=
query_get
(
"method"
);
}
return
ret
;
}
...
...
@@ -580,6 +589,18 @@ SrsConnection* SrsHttpMessage::connection()
u_int8_t
SrsHttpMessage
::
method
()
{
if
(
jsonp
&&
!
jsonp_method
.
empty
())
{
if
(
jsonp_method
==
"GET"
)
{
return
SRS_CONSTS_HTTP_GET
;
}
else
if
(
jsonp_method
==
"PUT"
)
{
return
SRS_CONSTS_HTTP_PUT
;
}
else
if
(
jsonp_method
==
"POST"
)
{
return
SRS_CONSTS_HTTP_POST
;
}
else
if
(
jsonp_method
==
"DELETE"
)
{
return
SRS_CONSTS_HTTP_DELETE
;
}
}
return
(
u_int8_t
)
_header
.
method
;
}
...
...
@@ -590,6 +611,10 @@ u_int16_t SrsHttpMessage::status_code()
string
SrsHttpMessage
::
method_str
()
{
if
(
jsonp
&&
!
jsonp_method
.
empty
())
{
return
jsonp_method
;
}
if
(
is_http_get
())
{
return
"GET"
;
}
...
...
@@ -611,22 +636,22 @@ string SrsHttpMessage::method_str()
bool
SrsHttpMessage
::
is_http_get
()
{
return
_header
.
method
==
SRS_CONSTS_HTTP_GET
;
return
method
()
==
SRS_CONSTS_HTTP_GET
;
}
bool
SrsHttpMessage
::
is_http_put
()
{
return
_header
.
method
==
SRS_CONSTS_HTTP_PUT
;
return
method
()
==
SRS_CONSTS_HTTP_PUT
;
}
bool
SrsHttpMessage
::
is_http_post
()
{
return
_header
.
method
==
SRS_CONSTS_HTTP_POST
;
return
method
()
==
SRS_CONSTS_HTTP_POST
;
}
bool
SrsHttpMessage
::
is_http_delete
()
{
return
_header
.
method
==
SRS_CONSTS_HTTP_DELETE
;
return
method
()
==
SRS_CONSTS_HTTP_DELETE
;
}
bool
SrsHttpMessage
::
is_http_options
()
...
...
@@ -803,6 +828,11 @@ SrsRequest* SrsHttpMessage::to_request(string vhost)
return
req
;
}
bool
SrsHttpMessage
::
is_jsonp
()
{
return
jsonp
;
}
SrsHttpParser
::
SrsHttpParser
()
{
buffer
=
new
SrsFastBuffer
();
...
...
trunk/src/app/srs_app_http_conn.hpp
查看文件 @
e43d4e4
...
...
@@ -203,6 +203,10 @@ private:
std
::
map
<
std
::
string
,
std
::
string
>
_query
;
// the transport connection, can be NULL.
SrsConnection
*
conn
;
// whether request is jsonp.
bool
jsonp
;
// the method in QueryString will override the HTTP method.
std
::
string
jsonp_method
;
public
:
SrsHttpMessage
(
SrsStSocket
*
io
,
SrsConnection
*
c
);
virtual
~
SrsHttpMessage
();
...
...
@@ -285,6 +289,8 @@ public:
* @remark user must free the return request.
*/
virtual
SrsRequest
*
to_request
(
std
::
string
vhost
);
public
:
virtual
bool
is_jsonp
();
};
/**
...
...
trunk/src/protocol/srs_http_stack.hpp
查看文件 @
e43d4e4
...
...
@@ -527,6 +527,12 @@ public:
virtual
int
request_header_count
()
=
0
;
virtual
std
::
string
request_header_key_at
(
int
index
)
=
0
;
virtual
std
::
string
request_header_value_at
(
int
index
)
=
0
;
public
:
/**
* whether the current request is JSONP,
* which has a "callback=xxx" in QueryString.
*/
virtual
bool
is_jsonp
()
=
0
;
};
#endif
...
...
请
注册
或
登录
后发表评论