From 4651fad4401b9889ebd6357ae0b3980277b68a05 Mon Sep 17 00:00:00 2001 From: chenhaibo Date: Sun, 23 Jan 2022 15:21:08 +0800 Subject: [PATCH 1/2] Fix bug when the value of http header is empty --- trunk/src/protocol/srs_service_http_conn.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/trunk/src/protocol/srs_service_http_conn.cpp b/trunk/src/protocol/srs_service_http_conn.cpp index b1365c13aa..f5fd10fd7d 100644 --- a/trunk/src/protocol/srs_service_http_conn.cpp +++ b/trunk/src/protocol/srs_service_http_conn.cpp @@ -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; From 6ecb3fbbf9e33780e90ac090d527c5b87fc8d3b1 Mon Sep 17 00:00:00 2001 From: chenhaibo Date: Thu, 3 Feb 2022 13:19:22 +0800 Subject: [PATCH 2/2] add utest --- trunk/src/utest/srs_utest_http.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/trunk/src/utest/srs_utest_http.cpp b/trunk/src/utest/srs_utest_http.cpp index e5de7dd0dd..c32fa77ac7 100644 --- a/trunk/src/utest/srs_utest_http.cpp +++ b/trunk/src/utest/srs_utest_http.cpp @@ -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)