From 0886acbdb7185f74ff5ccf90f9263d4ca5cde88c Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 16 Dec 2019 12:11:29 +0800 Subject: [PATCH] Improve test coverage for HTTP header. --- trunk/src/utest/srs_utest_http.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/trunk/src/utest/srs_utest_http.cpp b/trunk/src/utest/srs_utest_http.cpp index 217071807..21a856de6 100644 --- a/trunk/src/utest/srs_utest_http.cpp +++ b/trunk/src/utest/srs_utest_http.cpp @@ -128,3 +128,28 @@ VOID TEST(ProtocolHTTPTest, ResponseHTTPError) EXPECT_STREQ(mock_http_response(302,"Found").c_str(), HELPER_BUFFER2STR(&w.io.out_buffer).c_str()); } } + +VOID TEST(ProtocolHTTPTest, HTTPHeader) +{ + SrsHttpHeader h; + h.set("Server", "SRS"); + EXPECT_STREQ("SRS", h.get("Server").c_str()); + + stringstream ss; + h.write(ss); + EXPECT_STREQ("Server: SRS\r\n", ss.str().c_str()); + + h.del("Server"); + EXPECT_TRUE(h.get("Server").empty()); + + EXPECT_EQ(-1, h.content_length()); + + h.set_content_length(0); + EXPECT_EQ(0, h.content_length()); + + h.set_content_length(1024); + EXPECT_EQ(1024, h.content_length()); + + h.set_content_type("text/plain"); + EXPECT_STREQ("text/plain", h.content_type().c_str()); +}