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

Fix bug when the value of http header is empty (#2888)

* Fix bug when the value of http header is empty

* add utest
This commit is contained in:
Haibo Chen 2022-02-03 15:05:09 +08:00 committed by GitHub
parent 6b7fc6fdb5
commit b94ce1485a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 deletions

View file

@ -143,6 +143,16 @@ string mock_http_response2(int status, string content)
return ss.str();
}
string mock_http_response3(int status, string content)
{
stringstream ss;
ss << "HTTP/1.1 " << status << " " << srs_generate_http_status_text(status) << "\r\n"
<< "Server:" << "\r\n"
<< "\r\n"
<< content;
return ss.str();
}
bool is_string_contain(string substr, string str)
{
return (string::npos != str.find(substr));
@ -528,6 +538,17 @@ VOID TEST(ProtocolHTTPTest, ClientRequest)
EXPECT_STREQ("Hello, world!", res.c_str());
srs_freep(msg);
}
// Normal case, with empty server.
if(true) {
MockBufferIO io; io.append(mock_http_response3(200, "Hello, world!"));
SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE));
ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg));
string res; HELPER_ASSERT_SUCCESS(msg->body_read_all(res));
EXPECT_EQ(200, msg->status_code());
EXPECT_STREQ("Hello, world!", res.c_str());
srs_freep(msg);
}
}
VOID TEST(ProtocolHTTPTest, ResponseHTTPError)