mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
refine http, support no host.
This commit is contained in:
parent
2941328ee8
commit
f971538cf3
3 changed files with 31 additions and 27 deletions
|
@ -58,6 +58,7 @@ using namespace std;
|
|||
#include <srs_protocol_json.hpp>
|
||||
#include <srs_app_http_hooks.hpp>
|
||||
#include <srs_protocol_amf0.hpp>
|
||||
#include <srs_app_utility.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -541,11 +542,10 @@ int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, Sr
|
|||
// parse uri from url.
|
||||
std::string host = get_request_header("Host");
|
||||
|
||||
// donot parse the empty host for uri,
|
||||
// for example, the response contains no host,
|
||||
// ignore it is ok.
|
||||
// use server public ip when no host specified.
|
||||
// to make telnet happy.
|
||||
if (host.empty()) {
|
||||
return ret;
|
||||
host= srs_get_public_internet_address();
|
||||
}
|
||||
|
||||
// parse uri to schema/server:port/path?query
|
||||
|
@ -554,32 +554,12 @@ int SrsHttpMessage::update(string url, bool allow_jsonp, http_parser* header, Sr
|
|||
return ret;
|
||||
}
|
||||
|
||||
// must format as key=value&...&keyN=valueN
|
||||
std::string q = _uri->get_query();
|
||||
size_t pos = string::npos;
|
||||
while (!q.empty()) {
|
||||
std::string k = q;
|
||||
if ((pos = q.find("=")) != string::npos) {
|
||||
k = q.substr(0, pos);
|
||||
q = q.substr(pos + 1);
|
||||
} else {
|
||||
q = "";
|
||||
}
|
||||
|
||||
std::string v = q;
|
||||
if ((pos = q.find("&")) != string::npos) {
|
||||
v = q.substr(0, pos);
|
||||
q = q.substr(pos + 1);
|
||||
} else {
|
||||
q = "";
|
||||
}
|
||||
|
||||
_query[k] = v;
|
||||
}
|
||||
|
||||
// parse ext.
|
||||
_ext = srs_path_filext(_uri->get_path());
|
||||
|
||||
// parse query string.
|
||||
srs_parse_query_string(_uri->get_query(), _query);
|
||||
|
||||
// parse jsonp request message.
|
||||
if (allow_jsonp) {
|
||||
if (!query_get("callback").empty()) {
|
||||
|
|
|
@ -654,6 +654,9 @@ extern void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps);
|
|||
// get local ip, fill to @param ips
|
||||
extern std::vector<std::string>& srs_get_local_ipv4_ips();
|
||||
|
||||
// get local public ip, empty string if no public internet address found.
|
||||
extern std::string srs_get_public_internet_address();
|
||||
|
||||
// get local or peer ip.
|
||||
// where local ip is the server ip which client connected.
|
||||
extern std::string srs_get_local_ip(int fd);
|
||||
|
|
|
@ -117,6 +117,27 @@ void srs_discovery_tc_url(
|
|||
srs_vhost_resolve(vhost, app, param);
|
||||
}
|
||||
|
||||
void srs_parse_query_string(string q, map<string,string>& query)
|
||||
{
|
||||
// query string flags.
|
||||
static vector<string> flags;
|
||||
if (flags.empty()) {
|
||||
flags.push_back("=");
|
||||
flags.push_back(",");
|
||||
flags.push_back("&&");
|
||||
flags.push_back("&");
|
||||
flags.push_back(";");
|
||||
}
|
||||
|
||||
vector<string> kvs = srs_string_split(q, flags);
|
||||
for (int i = 0; i < (int)kvs.size(); i+=2) {
|
||||
string k = kvs.at(i);
|
||||
string v = (i < (int)kvs.size() - 1)? kvs.at(i+1):"";
|
||||
|
||||
query[k] = v;
|
||||
}
|
||||
}
|
||||
|
||||
void srs_random_generate(char* bytes, int size)
|
||||
{
|
||||
static bool _random_initialized = false;
|
||||
|
|
Loading…
Reference in a new issue