mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Merge branch '2.0release' into develop
This commit is contained in:
commit
5721bc371c
6 changed files with 57 additions and 12 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
6
trunk/src/app/srs_app_statistic.cpp
Executable file → Normal file
6
trunk/src/app/srs_app_statistic.cpp
Executable file → Normal file
|
@ -49,6 +49,7 @@ SrsStatisticVhost::SrsStatisticVhost()
|
|||
kbps->set_io(NULL, NULL);
|
||||
|
||||
nb_clients = 0;
|
||||
nb_streams = 0;
|
||||
}
|
||||
|
||||
SrsStatisticVhost::~SrsStatisticVhost()
|
||||
|
@ -69,6 +70,7 @@ int SrsStatisticVhost::dumps(stringstream& ss)
|
|||
<< SRS_JFIELD_STR("name", vhost) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_BOOL("enabled", enabled) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_ORG("clients", nb_clients) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_ORG("streams", nb_streams) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_ORG("send_bytes", kbps->get_send_bytes()) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_ORG("recv_bytes", kbps->get_recv_bytes()) << SRS_JFIELD_CONT
|
||||
<< SRS_JFIELD_OBJ("kbps")
|
||||
|
@ -169,6 +171,8 @@ void SrsStatisticStream::publish(int cid)
|
|||
{
|
||||
connection_cid = cid;
|
||||
active = true;
|
||||
|
||||
vhost->nb_streams++;
|
||||
}
|
||||
|
||||
void SrsStatisticStream::close()
|
||||
|
@ -176,6 +180,8 @@ void SrsStatisticStream::close()
|
|||
has_video = false;
|
||||
has_audio = false;
|
||||
active = false;
|
||||
|
||||
vhost->nb_streams--;
|
||||
}
|
||||
|
||||
SrsStatisticClient::SrsStatisticClient()
|
||||
|
|
1
trunk/src/app/srs_app_statistic.hpp
Executable file → Normal file
1
trunk/src/app/srs_app_statistic.hpp
Executable file → Normal file
|
@ -45,6 +45,7 @@ struct SrsStatisticVhost
|
|||
public:
|
||||
int64_t id;
|
||||
std::string vhost;
|
||||
int nb_streams;
|
||||
int nb_clients;
|
||||
public:
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue