Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions trunk/src/protocol/srs_service_http_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ int SrsHttpParser::on_header_value(http_parser* parser, const char* at, size_t l

if (length > 0) {
obj->field_value.append(at, (int)length);
}

// When header parsed, we must save the position of start for body,
// because we have to consume the header in buffer.
// @see https://github.com/ossrs/srs/issues/1508
obj->p_header_tail = at;
// When header parsed, we must save the position of start for body,
// because we have to consume the header in buffer.
// @see https://github.com/ossrs/srs/issues/1508
obj->p_header_tail = at;
}

srs_info("Header value(%d bytes): %.*s", (int)length, (int)length, at);
return 0;
Expand Down
21 changes: 21 additions & 0 deletions trunk/src/utest/srs_utest_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down