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

Refactor header of HTTP message by using SrsHttpHeader.

This commit is contained in:
winlin 2019-12-16 16:00:02 +08:00
parent dcb7b6aae0
commit ca2b68f428
6 changed files with 95 additions and 120 deletions

View file

@ -173,6 +173,20 @@ void SrsHttpHeader::del(string key)
}
}
int SrsHttpHeader::count()
{
return (int)headers.size();
}
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()));
}
}
int64_t SrsHttpHeader::content_length()
{
std::string cl = get("Content-Length");
@ -776,13 +790,8 @@ srs_error_t SrsHttpCorsMux::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessag
// If CORS enabled, and there is a "Origin" header, it's CORS.
if (enabled) {
for (int i = 0; i < r->request_header_count(); i++) {
string k = r->request_header_key_at(i);
if (k == "Origin" || k == "origin") {
required = true;
break;
}
}
SrsHttpHeader* h = r->header();
required = !h->get("Origin").empty();
}
// When CORS required, set the CORS headers.