1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

HTTP: Support HTTP header in creating order. v5.0.68

This commit is contained in:
winlin 2022-09-30 18:22:25 +08:00
parent d65c699829
commit 4b7d9587f4
5 changed files with 83 additions and 12 deletions

View file

@ -152,6 +152,10 @@ void SrsHttpHeader::set(string key, string value)
pchar = ch;
}
if (headers.find(key) == headers.end()) {
keys_.push_back(key);
}
headers[key] = value;
}
@ -169,9 +173,18 @@ string SrsHttpHeader::get(string key)
void SrsHttpHeader::del(string key)
{
map<string, string>::iterator it = headers.find(key);
if (it != headers.end()) {
headers.erase(it);
if (true) {
vector<string>::iterator it = std::find(keys_.begin(), keys_.end(), key);
if (it != keys_.end()) {
it = keys_.erase(it);
}
}
if (true) {
map<string, string>::iterator it = headers.find(key);
if (it != headers.end()) {
headers.erase(it);
}
}
}
@ -182,10 +195,11 @@ int SrsHttpHeader::count()
void SrsHttpHeader::dumps(SrsJsonObject* o)
{
map<string, string>::iterator it;
for (it = headers.begin(); it != headers.end(); ++it) {
string v = it->second;
o->set(it->first, SrsJsonAny::str(v.c_str()));
vector<string>::iterator it;
for (it = keys_.begin(); it != keys_.end(); ++it) {
const string& key = *it;
const string& value = headers[key];
o->set(key, SrsJsonAny::str(value.c_str()));
}
}
@ -217,9 +231,11 @@ void SrsHttpHeader::set_content_type(string ct)
void SrsHttpHeader::write(stringstream& ss)
{
map<string, string>::iterator it;
for (it = headers.begin(); it != headers.end(); ++it) {
ss << it->first << ": " << it->second << SRS_HTTP_CRLF;
vector<string>::iterator it;
for (it = keys_.begin(); it != keys_.end(); ++it) {
const string& key = *it;
const string& value = headers[key];
ss << key << ": " << value << SRS_HTTP_CRLF;
}
}
@ -657,7 +673,7 @@ void SrsHttpServeMux::unhijack(ISrsHttpMatchHijacker* h)
if (it == hijackers.end()) {
return;
}
hijackers.erase(it);
it = hijackers.erase(it);
}
srs_error_t SrsHttpServeMux::handle(std::string pattern, ISrsHttpHandler* handler)