From d67b050935799a2d74251a58eebab34fd645e14b Mon Sep 17 00:00:00 2001 From: winlin Date: Thu, 5 Nov 2020 17:57:22 +0800 Subject: [PATCH] For #1657, fix the jsonp bug --- trunk/src/app/srs_app_http_api.cpp | 12 ++++--- trunk/src/app/srs_app_http_conn.cpp | 25 +++++++-------- .../src/protocol/srs_service_http_client.cpp | 2 +- trunk/src/protocol/srs_service_http_conn.cpp | 9 ++++-- trunk/src/protocol/srs_service_http_conn.hpp | 5 +-- trunk/src/utest/srs_utest_http.cpp | 32 +++++++++---------- trunk/src/utest/srs_utest_protocol.cpp | 12 +++---- trunk/src/utest/srs_utest_service.cpp | 16 +++++----- 8 files changed, 60 insertions(+), 53 deletions(-) diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index d1bbfb9b9..7231627f4 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -1691,7 +1691,13 @@ SrsHttpApi::~SrsHttpApi() srs_error_t SrsHttpApi::on_start() { - return srs_success; + srs_error_t err = srs_success; + + if ((err = conn->set_jsonp(true)) != srs_success) { + return srs_error_wrap(err, "set jsonp"); + } + + return err; } srs_error_t SrsHttpApi::on_http_message(ISrsHttpMessage* req) @@ -1742,10 +1748,6 @@ srs_error_t SrsHttpApi::start() return srs_error_wrap(err, "set cors=%d", v); } - if ((err = conn->set_jsonp(true)) != srs_success) { - return srs_error_wrap(err, "set jsonp"); - } - return conn->start(); } diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 01aad9fb0..5adee860b 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -159,11 +159,6 @@ srs_error_t SrsHttpConn::cycle() srs_error_t SrsHttpConn::do_cycle() { srs_error_t err = srs_success; - - // Notify the handler that we are starting to process the connection. - if ((err = handler_->on_start()) != srs_success) { - return srs_error_wrap(err, "start"); - } // set the recv timeout, for some clients never disconnect the connection. // @see https://github.com/ossrs/srs/issues/398 @@ -171,6 +166,16 @@ srs_error_t SrsHttpConn::do_cycle() SrsRequest* last_req = NULL; SrsAutoFree(SrsRequest, last_req); + + // initialize parser + if ((err = parser->initialize(HTTP_REQUEST)) != srs_success) { + return srs_error_wrap(err, "init parser for %s", ip.c_str()); + } + + // Notify the handler that we are starting to process the connection. + if ((err = handler_->on_start()) != srs_success) { + return srs_error_wrap(err, "start"); + } // process http messages. for (int req_id = 0; (err = trd->pull()) == srs_success; req_id++) { @@ -268,14 +273,8 @@ srs_error_t SrsHttpConn::set_crossdomain_enabled(bool v) srs_error_t SrsHttpConn::set_jsonp(bool v) { - srs_error_t err = srs_success; - - // initialize parser - if ((err = parser->initialize(HTTP_REQUEST, v)) != srs_success) { - return srs_error_wrap(err, "init parser for %s", ip.c_str()); - } - - return err; + parser->set_jsonp(v); + return srs_success; } srs_error_t SrsHttpConn::set_tcp_nodelay(bool v) diff --git a/trunk/src/protocol/srs_service_http_client.cpp b/trunk/src/protocol/srs_service_http_client.cpp index 08e72887c..9ca239632 100644 --- a/trunk/src/protocol/srs_service_http_client.cpp +++ b/trunk/src/protocol/srs_service_http_client.cpp @@ -281,7 +281,7 @@ srs_error_t SrsHttpClient::initialize(string schema, string h, int p, srs_utime_ srs_freep(parser); parser = new SrsHttpParser(); - if ((err = parser->initialize(HTTP_RESPONSE, false)) != srs_success) { + if ((err = parser->initialize(HTTP_RESPONSE)) != srs_success) { return srs_error_wrap(err, "http: init parser"); } diff --git a/trunk/src/protocol/srs_service_http_conn.cpp b/trunk/src/protocol/srs_service_http_conn.cpp index 185634046..bb2574f63 100644 --- a/trunk/src/protocol/srs_service_http_conn.cpp +++ b/trunk/src/protocol/srs_service_http_conn.cpp @@ -52,11 +52,11 @@ SrsHttpParser::~SrsHttpParser() srs_freep(header); } -srs_error_t SrsHttpParser::initialize(enum http_parser_type type, bool allow_jsonp) +srs_error_t SrsHttpParser::initialize(enum http_parser_type type) { srs_error_t err = srs_success; - jsonp = allow_jsonp; + jsonp = false; type_ = type; // Initialize the parser, however it's not necessary. @@ -75,6 +75,11 @@ srs_error_t SrsHttpParser::initialize(enum http_parser_type type, bool allow_jso return err; } +void SrsHttpParser::set_jsonp(bool allow_jsonp) +{ + jsonp = allow_jsonp; +} + srs_error_t SrsHttpParser::parse_message(ISrsReader* reader, ISrsHttpMessage** ppmsg) { srs_error_t err = srs_success; diff --git a/trunk/src/protocol/srs_service_http_conn.hpp b/trunk/src/protocol/srs_service_http_conn.hpp index b9cfba74b..b380faba1 100644 --- a/trunk/src/protocol/srs_service_http_conn.hpp +++ b/trunk/src/protocol/srs_service_http_conn.hpp @@ -67,8 +67,9 @@ public: public: // initialize the http parser with specified type, // one parser can only parse request or response messages. - // @param allow_jsonp whether allow jsonp parser, which indicates the method in query string. - virtual srs_error_t initialize(enum http_parser_type type, bool allow_jsonp = false); + virtual srs_error_t initialize(enum http_parser_type type); + // Whether allow jsonp parser, which indicates the method in query string. + virtual void set_jsonp(bool allow_jsonp); // always parse a http message, // that is, the *ppmsg always NOT-NULL when return success. // or error and *ppmsg must be NULL. diff --git a/trunk/src/utest/srs_utest_http.cpp b/trunk/src/utest/srs_utest_http.cpp index 21d6f4b4b..7a65368aa 100644 --- a/trunk/src/utest/srs_utest_http.cpp +++ b/trunk/src/utest/srs_utest_http.cpp @@ -358,7 +358,7 @@ VOID TEST(ProtocolHTTPTest, ChunkSmallBuffer) io.append(mock_http_response2(200, "0d\r\n")); io.append("Hello, world!\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); char buf[32]; ssize_t nread = 0; @@ -382,7 +382,7 @@ VOID TEST(ProtocolHTTPTest, ChunkSmallBuffer) io.append(mock_http_response2(200, "0d\r\n")); io.append("Hello, world!\r\n0\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); char buf[32]; ssize_t nread = 0; @@ -409,7 +409,7 @@ VOID TEST(ProtocolHTTPTest, ChunkSmallBuffer) io.append(mock_http_response2(200, "0d\r\n")); io.append("Hello, world!\r\n0\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); char buf[32]; ssize_t nread = 0; @@ -436,7 +436,7 @@ VOID TEST(ProtocolHTTPTest, ClientSmallBuffer) io.append(" world!"); io.append("\r\n0\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); char buf[32]; ssize_t nread = 0; @@ -461,7 +461,7 @@ VOID TEST(ProtocolHTTPTest, ClientSmallBuffer) io.append(mock_http_response2(200, "0d\r\n")); io.append("Hello, world!\r\n0\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); char buf[32]; ssize_t nread = 0; @@ -478,7 +478,7 @@ VOID TEST(ProtocolHTTPTest, ClientSmallBuffer) // If buffer is smaller than chunk, we could read N times to get the whole chunk. if (true) { MockBufferIO io; io.append(mock_http_response2(200, "0d\r\nHello, world!\r\n0\r\n\r\n")); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); char buf[32]; ssize_t nread = 0; @@ -513,7 +513,7 @@ VOID TEST(ProtocolHTTPTest, ClientRequest) // Normal case, with chunked encoding. if (true) { MockBufferIO io; io.append(mock_http_response2(200, "0d\r\nHello, world!\r\n0\r\n\r\n")); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + 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()); @@ -522,7 +522,7 @@ VOID TEST(ProtocolHTTPTest, ClientRequest) } if (true) { MockBufferIO io; io.append(mock_http_response2(200, "6\r\nHello!\r\n0\r\n\r\n")); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + 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()); @@ -533,7 +533,7 @@ VOID TEST(ProtocolHTTPTest, ClientRequest) // Normal case, with specified content-length. if (true) { MockBufferIO io; io.append(mock_http_response(200, "Hello, world!")); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + 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()); @@ -1418,7 +1418,7 @@ VOID TEST(ProtocolHTTPTest, HTTPMessageParser) r.in_bytes.push_back("\r\n"); SrsHttpParser p; - HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg)); @@ -1436,7 +1436,7 @@ VOID TEST(ProtocolHTTPTest, HTTPMessageParser) r.in_bytes.push_back("\r\n"); SrsHttpParser p; - HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg)); @@ -1455,7 +1455,7 @@ VOID TEST(ProtocolHTTPTest, HTTPMessageParser) r.in_bytes.push_back("\r\n"); SrsHttpParser p; - HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg)); @@ -1476,7 +1476,7 @@ VOID TEST(ProtocolHTTPTest, HTTPMessageParser) r.in_bytes.push_back("\r\n"); SrsHttpParser p; - HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg)); @@ -1498,7 +1498,7 @@ VOID TEST(ProtocolHTTPTest, HTTPMessageParser) r.in_bytes.push_back("\r\n"); SrsHttpParser p; - HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg)); @@ -1516,7 +1516,7 @@ VOID TEST(ProtocolHTTPTest, HTTPMessageParser) r.in_bytes.push_back("\r\n"); SrsHttpParser p; - HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(p.initialize(HTTP_REQUEST)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(p.parse_message(&r, &msg)); @@ -1780,7 +1780,7 @@ VOID TEST(ProtocolHTTPTest, ParsingLargeMessages) 0x66, 0x6d, 0x74, 0x70, 0x3a, 0x31, 0x31, 0x39, 0x20, 0x61, 0x70, 0x74, 0x3d, 0x31, 0x32, 0x33, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x72, 0x74, 0x70, 0x6d, 0x61, 0x70, 0x3a, 0x31, 0x31, 0x34, 0x20, 0x72, 0x65, 0x64, 0x2f, 0x39, 0x30, 0x30, 0x30, 0x30, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x72, 0x74, 0x70, 0x6d, 0x61, 0x70, 0x3a, 0x31, 0x31, 0x35, 0x20, 0x72, 0x74, 0x78, 0x2f, 0x39, 0x30, 0x30, 0x30, 0x30, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x66, 0x6d, 0x74, 0x70, 0x3a, 0x31, 0x31, 0x35, 0x20, 0x61, 0x70, 0x74, 0x3d, 0x31, 0x31, 0x34, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x72, 0x74, 0x70, 0x6d, 0x61, 0x70, 0x3a, 0x31, 0x31, 0x36, 0x20, 0x75, 0x6c, 0x70, 0x66, 0x65, 0x63, 0x2f, 0x39, 0x30, 0x30, 0x30, 0x30, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x73, 0x73, 0x72, 0x63, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x3a, 0x46, 0x49, 0x44, 0x20, 0x31, 0x34, 0x34, 0x33, 0x36, 0x34, 0x38, 0x35, 0x32, 0x33, 0x20, 0x31, 0x30, 0x39, 0x31, 0x38, 0x39, 0x32, 0x33, 0x39, 0x39, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x73, 0x73, 0x72, 0x63, 0x3a, 0x31, 0x34, 0x34, 0x33, 0x36, 0x34, 0x38, 0x35, 0x32, 0x33, 0x20, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x33, 0x4c, 0x75, 0x6d, 0x55, 0x62, 0x6a, 0x6c, 0x70, 0x50, 0x4d, 0x79, 0x77, 0x45, 0x31, 0x52, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x73, 0x73, 0x72, 0x63, 0x3a, 0x31, 0x34, 0x34, 0x33, 0x36, 0x34, 0x38, 0x35, 0x32, 0x33, 0x20, 0x6d, 0x73, 0x69, 0x64, 0x3a, 0x76, 0x72, 0x79, 0x33, 0x6b, 0x78, 0x38, 0x4f, 0x44, 0x50, 0x77, 0x48, 0x45, 0x55, 0x71, 0x74, 0x67, 0x34, 0x6a, 0x51, 0x65, 0x37, 0x6d, 0x63, 0x4b, 0x5a, 0x58, 0x6d, 0x34, 0x41, 0x6b, 0x79, 0x54, 0x4f, 0x49, 0x42, 0x20, 0x37, 0x63, 0x37, 0x31, 0x37, 0x66, 0x36, 0x39, 0x2d, 0x62, 0x63, 0x33, 0x35, 0x2d, 0x34, 0x30, 0x38, 0x39, 0x2d, 0x38, 0x34, 0x63, 0x65, 0x2d, 0x34, 0x31, 0x65, 0x61, 0x38, 0x65, 0x31, 0x63, 0x34, 0x33, 0x39, 0x31, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x73, 0x73, 0x72, 0x63, 0x3a, 0x31, 0x34, 0x34, 0x33, 0x36, 0x34, 0x38, 0x35, 0x32, 0x33, 0x20, 0x6d, 0x73, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x3a, 0x76, 0x72, 0x79, 0x33, 0x6b, 0x78, 0x38, 0x4f, 0x44, 0x50, 0x77, 0x48, 0x45, 0x55, 0x71, 0x74, 0x67, 0x34, 0x6a, 0x51, 0x65, 0x37, 0x6d, 0x63, 0x4b, 0x5a, 0x58, 0x6d, 0x34, 0x41, 0x6b, 0x79, 0x54, 0x4f, 0x49, 0x42, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x73, 0x73, 0x72, 0x63, 0x3a, 0x31, 0x34, 0x34, 0x33, 0x36, 0x34, 0x38, 0x35, 0x32, 0x33, 0x20, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x3a, 0x37, 0x63, 0x37, 0x31, 0x37, 0x66, 0x36, 0x39, 0x2d, 0x62, 0x63, 0x33, 0x35, 0x2d, 0x34, 0x30, 0x38, 0x39, 0x2d, 0x38, 0x34, 0x63, 0x65, 0x2d, 0x34, 0x31, 0x65, 0x61, 0x38, 0x65, 0x31, 0x63, 0x34, 0x33, 0x39, 0x31, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x73, 0x73, 0x72, 0x63, 0x3a, 0x31, 0x30, 0x39, 0x31, 0x38, 0x39, 0x32, 0x33, 0x39, 0x39, 0x20, 0x63, 0x6e, 0x61, 0x6d, 0x65, 0x3a, 0x33, 0x4c, 0x75, 0x6d, 0x55, 0x62, 0x6a, 0x6c, 0x70, 0x50, 0x4d, 0x79, 0x77, 0x45, 0x31, 0x52, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x73, 0x73, 0x72, 0x63, 0x3a, 0x31, 0x30, 0x39, 0x31, 0x38, 0x39, 0x32, 0x33, 0x39, 0x39, 0x20, 0x6d, 0x73, 0x69, 0x64, 0x3a, 0x76, 0x72, 0x79, 0x33, 0x6b, 0x78, 0x38, 0x4f, 0x44, 0x50, 0x77, 0x48, 0x45, 0x55, 0x71, 0x74, 0x67, 0x34, 0x6a, 0x51, 0x65, 0x37, 0x6d, 0x63, 0x4b, 0x5a, 0x58, 0x6d, 0x34, 0x41, 0x6b, 0x79, 0x54, 0x4f, 0x49, 0x42, 0x20, 0x37, 0x63, 0x37, 0x31, 0x37, 0x66, 0x36, 0x39, 0x2d, 0x62, 0x63, 0x33, 0x35, 0x2d, 0x34, 0x30, 0x38, 0x39, 0x2d, 0x38, 0x34, 0x63, 0x65, 0x2d, 0x34, 0x31, 0x65, 0x61, 0x38, 0x65, 0x31, 0x63, 0x34, 0x33, 0x39, 0x31, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x73, 0x73, 0x72, 0x63, 0x3a, 0x31, 0x30, 0x39, 0x31, 0x38, 0x39, 0x32, 0x33, 0x39, 0x39, 0x20, 0x6d, 0x73, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x3a, 0x76, 0x72, 0x79, 0x33, 0x6b, 0x78, 0x38, 0x4f, 0x44, 0x50, 0x77, 0x48, 0x45, 0x55, 0x71, 0x74, 0x67, 0x34, 0x6a, 0x51, 0x65, 0x37, 0x6d, 0x63, 0x4b, 0x5a, 0x58, 0x6d, 0x34, 0x41, 0x6b, 0x79, 0x54, 0x4f, 0x49, 0x42, 0x5c, 0x72, 0x5c, 0x6e, 0x61, 0x3d, 0x73, 0x73, 0x72, 0x63, 0x3a, 0x31, 0x30, 0x39, 0x31, 0x38, 0x39, 0x32, 0x33, 0x39, 0x39, 0x20, 0x6c, 0x61, 0x62, 0x65, 0x6c, 0x3a, 0x37, 0x63, 0x37, 0x31, 0x37, 0x66, 0x36, 0x39, 0x2d, 0x62, 0x63, 0x33, 0x35, 0x2d, 0x34, 0x30, 0x38, 0x39, 0x2d, 0x38, 0x34, 0x63, 0x65, 0x2d, 0x34, 0x31, 0x65, 0x61, 0x38, 0x65, 0x31, 0x63, 0x34, 0x33, 0x39, 0x31, 0x5c, 0x72, 0x5c, 0x6e, 0x22, 0x7d, 0x7d, 0x50, 0x4f, 0x53, 0x54, 0x20, 0x2f, 0x6a, 0x61, 0x6e, 0x75, 0x73, 0x2f, 0x32, 0x35, 0x38, 0x30, 0x34, 0x39, 0x32, 0x38, 0x30, 0x38, 0x36, 0x34, 0x32, 0x39, 0x31, 0x31, 0x39, 0x30, 0x32, 0x2f, 0x34, 0x32, 0x36, 0x38, 0x30, 0x33, 0x37, 0x39, 0x33, 0x30, 0x36, 0x34, 0x39, 0x33, 0x33, 0x36, 0x30, 0x38, 0x36, 0x20, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x48, 0x6f, 0x73, 0x74, 0x3a, 0x20, 0x33, 0x33, 0x2e, 0x31, 0x38, 0x2e, 0x34, 0x2e, 0x31, 0x32, 0x33, 0x3a, 0x31, 0x39, 0x38, 0x35, 0x0d, 0x0a, 0x55, 0x73, 0x65, 0x72, 0x2d, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x3a, 0x20, 0x47, 0x6f, 0x2d, 0x68, 0x74, 0x74, 0x70, 0x2d, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x2f, 0x31, 0x2e, 0x31, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x2d, 0x4c, 0x65, 0x6e, 0x67, 0x74, 0x68, 0x3a, 0x20, 0x33, 0x35, 0x34, 0x0d, 0x0a, 0x41, 0x63, 0x63, 0x65, 0x70, 0x74, 0x2d, 0x45, 0x6e, 0x63, 0x6f, 0x64, 0x69, 0x6e, 0x67, 0x3a, 0x20, 0x67, 0x7a, 0x69, 0x70, 0x0d, 0x0a, 0x0d, 0x0a, 0x7b, 0x22, 0x6a, 0x61, 0x6e, 0x75, 0x73, 0x22, 0x3a, 0x22, 0x74, 0x72, 0x69, 0x63, 0x6b, 0x6c, 0x65, 0x22, 0x2c, 0x22, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3a, 0x22, 0x62, 0x33, 0x31, 0x38, 0x65, 0x30, 0x32, 0x65, 0x32, 0x35, 0x34, 0x39, 0x35, 0x33, 0x30, 0x33, 0x61, 0x66, 0x39, 0x37, 0x66, 0x64, 0x36, 0x38, 0x38, 0x39, 0x35, 0x65, 0x35, 0x30, 0x62, 0x64, 0x22, 0x2c, 0x22, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x69, 0x64, 0x22, 0x3a, 0x22, 0x30, 0x6f, 0x77, 0x65, 0x67, 0x75, 0x35, 0x6f, 0x74, 0x66, 0x75, 0x30, 0x68, 0x64, 0x67, 0x6e, 0x68, 0x72, 0x6d, 0x6d, 0x76, 0x34, 0x63, 0x30, 0x79, 0x6b, 0x35, 0x67, 0x6e, 0x74, 0x38, 0x39, 0x22, 0x2c, 0x22, 0x72, 0x70, 0x63, 0x69, 0x64, 0x22, 0x3a, 0x22, 0x22, 0x2c, 0x22, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x22, 0x3a, 0x22, 0x73, 0x69, 0x67, 0x22, 0x2c, 0x22, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x7b, 0x22, 0x73, 0x64, 0x70, 0x4d, 0x4c, 0x69, 0x6e, 0x65, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x22, 0x3a, 0x30, 0x2c, 0x22, 0x73, 0x64, 0x70, 0x4d, 0x69, 0x64, 0x22, 0x3a, 0x22, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x22, 0x2c, 0x22, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x22, 0x3a, 0x22, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x3a, 0x32, 0x35, 0x31, 0x30, 0x36, 0x35, 0x35, 0x31, 0x30, 0x39, 0x20, 0x31, 0x20, 0x75, 0x64, 0x70, 0x20, 0x34, 0x31, 0x38, 0x38, 0x35, 0x36, 0x39, 0x35, 0x20, 0x31, 0x31, 0x2e, 0x31, 0x33, 0x33, 0x2e, 0x31, 0x37, 0x32, 0x2e, 0x32, 0x34, 0x31, 0x20, 0x31, 0x30, 0x38, 0x30, 0x31, 0x20, 0x74, 0x79, 0x70, 0x20, 0x72, 0x65, 0x6c, 0x61, 0x79, 0x20, 0x72, 0x61, 0x64, 0x64, 0x72, 0x20, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x2e, 0x30, 0x20, 0x72, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x30, 0x20, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x30, 0x20, 0x75, 0x66, 0x72, 0x61, 0x67, 0x20, 0x67, 0x4b, 0x2f, 0x62, 0x20, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2d, 0x69, 0x64, 0x20, 0x31, 0x20, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x2d, 0x63, 0x6f, 0x73, 0x74, 0x20, 0x31, 0x30, 0x22, 0x7d, 0x7d }; uint8_t* p = data; MockBufferIO io; SrsHttpParser hp; - HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); if (true) { // First message, 144 header + 315 body. diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index 0c7a40e34..faaff3b20 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -6006,7 +6006,7 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage) SrsHttpParser hp; bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello"); - HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); ISrsHttpMessage* req = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&bio, &req)); @@ -6030,7 +6030,7 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage) SrsHttpParser hp; bio.append("GET"); - HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); // Should fail if not completed message. ISrsHttpMessage* req = NULL; @@ -6043,7 +6043,7 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage) SrsHttpParser hp; bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello"); - HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); ISrsHttpMessage* req = NULL; SrsAutoFree(ISrsHttpMessage, req); @@ -6061,7 +6061,7 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage) SrsHttpParser hp; bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 0\r\n\r\n"); - HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); ISrsHttpMessage* req = NULL; SrsAutoFree(ISrsHttpMessage, req); @@ -6073,7 +6073,7 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage) SrsHttpParser hp; bio.append("GET /gslb/v1/versions HTTP/1.1\r\n\r\n"); - HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); ISrsHttpMessage* req = NULL; SrsAutoFree(ISrsHttpMessage, req); @@ -6085,7 +6085,7 @@ VOID TEST(ProtocolHTTPTest, ParseHTTPMessage) SrsHttpParser hp; bio.append("GET /gslb/v1/versions HTTP/1.1\r\n\r\n"); - HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); ISrsHttpMessage* req = NULL; SrsAutoFree(ISrsHttpMessage, req); diff --git a/trunk/src/utest/srs_utest_service.cpp b/trunk/src/utest/srs_utest_service.cpp index 3f2492e47..76570b0a8 100644 --- a/trunk/src/utest/srs_utest_service.cpp +++ b/trunk/src/utest/srs_utest_service.cpp @@ -633,7 +633,7 @@ VOID TEST(HTTPServerTest, ContentLength) MockBufferIO io; io.append("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); char buf[32]; ssize_t nread = 0; @@ -661,7 +661,7 @@ VOID TEST(HTTPServerTest, HTTPChunked) MockBufferIO io; io.append("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); char buf[32]; ssize_t nread = 0; @@ -690,7 +690,7 @@ VOID TEST(HTTPServerTest, InfiniteChunked) MockBufferIO io; io.append("HTTP/1.1 200 OK\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); SrsAutoFree(ISrsHttpMessage, msg); @@ -717,7 +717,7 @@ VOID TEST(HTTPServerTest, InfiniteChunked) MockBufferIO io; io.append("HTTP/1.1 200 OK\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* msg = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &msg)); char buf[32]; ssize_t nread = 0; @@ -745,7 +745,7 @@ VOID TEST(HTTPServerTest, OPTIONSRead) MockBufferIO io; io.append("OPTIONS /rtc/v1/play HTTP/1.1\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); ISrsHttpMessage* req = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req)); SrsAutoFree(ISrsHttpMessage, req); @@ -758,7 +758,7 @@ VOID TEST(HTTPServerTest, OPTIONSRead) MockBufferIO io; io.append("HTTP/1.1 200 OK\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_RESPONSE)); ISrsHttpMessage* req = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req)); SrsAutoFree(ISrsHttpMessage, req); @@ -771,7 +771,7 @@ VOID TEST(HTTPServerTest, OPTIONSRead) MockBufferIO io; io.append("OPTIONS /rtc/v1/play HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); ISrsHttpMessage* req = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req)); SrsAutoFree(ISrsHttpMessage, req); @@ -793,7 +793,7 @@ VOID TEST(HTTPServerTest, OPTIONSRead) MockBufferIO io; io.append("OPTIONS /rtc/v1/play HTTP/1.1\r\n\r\n"); - SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST, false)); + SrsHttpParser hp; HELPER_ASSERT_SUCCESS(hp.initialize(HTTP_REQUEST)); ISrsHttpMessage* req = NULL; HELPER_ASSERT_SUCCESS(hp.parse_message(&io, &req)); SrsAutoFree(ISrsHttpMessage, req);