mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
For #1181, Add utest
This commit is contained in:
parent
01d8bba455
commit
928c6ab091
3 changed files with 96 additions and 1 deletions
|
@ -243,8 +243,8 @@ srs_error_t SrsResponseOnlyHttpConn::on_got_http_message(ISrsHttpMessage* msg)
|
|||
}
|
||||
|
||||
// drop all request body.
|
||||
while (!br->eof()) {
|
||||
char body[4096];
|
||||
while (!br->eof()) {
|
||||
if ((err = br->read(body, 4096, NULL)) != srs_success) {
|
||||
return srs_error_wrap(err, "read response");
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ using namespace std;
|
|||
#include <srs_app_st.hpp>
|
||||
#include <srs_protocol_amf0.hpp>
|
||||
#include <srs_rtmp_stack.hpp>
|
||||
#include <srs_service_http_conn.hpp>
|
||||
|
||||
MockEmptyIO::MockEmptyIO()
|
||||
{
|
||||
|
@ -105,6 +106,12 @@ MockBufferIO::~MockBufferIO()
|
|||
{
|
||||
}
|
||||
|
||||
MockBufferIO* MockBufferIO::append(string data)
|
||||
{
|
||||
in_buffer.append(data.data(), data.length());
|
||||
return this;
|
||||
}
|
||||
|
||||
bool MockBufferIO::is_never_timeout(int64_t tm)
|
||||
{
|
||||
return tm == SRS_CONSTS_NO_TMMS;
|
||||
|
@ -5523,5 +5530,91 @@ VOID TEST(ProtocolRTMPTest, RTMPHandshakeBytes)
|
|||
EXPECT_TRUE(bytes.s0s1s2 != NULL);
|
||||
}
|
||||
|
||||
VOID TEST(ProtocolHTTPTest, ParseHTTPMessage)
|
||||
{
|
||||
if (true) {
|
||||
MockBufferIO bio;
|
||||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello");
|
||||
EXPECT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
if (true) {
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
ASSERT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
|
||||
// We should read body, or next parsing message will fail.
|
||||
// @see https://github.com/ossrs/srs/issues/1181
|
||||
EXPECT_FALSE(req->body_reader()->eof());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello");
|
||||
|
||||
// Should fail because there is body which not read.
|
||||
// @see https://github.com/ossrs/srs/issues/1181
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
ASSERT_FALSE(0 == hp.parse_message(&bio, &req));
|
||||
}
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO bio;
|
||||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 5\r\n\r\nHello");
|
||||
ASSERT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
ASSERT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
|
||||
char v[64] = {0};
|
||||
EXPECT_TRUE(0 == req->body_reader()->read(v, sizeof(v), NULL));
|
||||
EXPECT_TRUE(string("Hello") == string(v));
|
||||
|
||||
EXPECT_TRUE(req->body_reader()->eof());
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO bio;
|
||||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\nContent-Length: 0\r\n\r\n");
|
||||
ASSERT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
EXPECT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO bio;
|
||||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\n\r\n");
|
||||
ASSERT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
EXPECT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
}
|
||||
|
||||
if (true) {
|
||||
MockBufferIO bio;
|
||||
SrsHttpParser hp;
|
||||
|
||||
bio.append("GET /gslb/v1/versions HTTP/1.1\r\n\r\n");
|
||||
ASSERT_TRUE(0 == hp.initialize(HTTP_REQUEST, false));
|
||||
|
||||
ISrsHttpMessage* req = NULL;
|
||||
SrsAutoFree(ISrsHttpMessage, req);
|
||||
EXPECT_TRUE(0 == hp.parse_message(&bio, &req));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -86,6 +86,8 @@ public:
|
|||
public:
|
||||
MockBufferIO();
|
||||
virtual ~MockBufferIO();
|
||||
public:
|
||||
virtual MockBufferIO* append(std::string data);
|
||||
// for protocol
|
||||
public:
|
||||
virtual bool is_never_timeout(int64_t tm);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue