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:
parent
474266eae7
commit
8c10c26f00
6 changed files with 141 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue