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

Improve the coverage for HTTP error response.

This commit is contained in:
winlin 2019-12-16 11:36:39 +08:00
parent 474266eae7
commit 8c10c26f00
6 changed files with 141 additions and 8 deletions

View file

@ -156,14 +156,23 @@ void SrsHttpHeader::set(string key, string value)
string SrsHttpHeader::get(string key)
{
std::string v;
if (headers.find(key) != headers.end()) {
v = headers[key];
map<string, string>::iterator it = headers.find(key);
if (it != headers.end()) {
v = it->second;
}
return v;
}
void SrsHttpHeader::del(string key)
{
map<string, string>::iterator it = headers.find(key);
if (it != headers.end()) {
headers.erase(it);
}
}
int64_t SrsHttpHeader::content_length()
{
std::string cl = get("Content-Length");
@ -192,7 +201,7 @@ void SrsHttpHeader::set_content_type(string ct)
void SrsHttpHeader::write(stringstream& ss)
{
std::map<std::string, std::string>::iterator it;
map<string, string>::iterator it;
for (it = headers.begin(); it != headers.end(); ++it) {
ss << it->first << ": " << it->second << SRS_HTTP_CRLF;
}

View file

@ -121,6 +121,9 @@ public:
// To access multiple values of a key, access the map directly
// with CanonicalHeaderKey.
virtual std::string get(std::string key);
// Delete the http header indicated by key.
// Return the removed header field.
virtual void del(std::string);
public:
// Get the content length. -1 if not set.
virtual int64_t content_length();