Close #115 升级http-parser到2.9.0版本并增加对以\r\n起始的HTTP应答执行HTTP解析的单元测试用例

This commit is contained in:
luqiuwen
2019-01-29 14:45:57 +06:00
parent 9666280834
commit f6c1ea0e28
4 changed files with 65 additions and 2 deletions

View File

@@ -1478,6 +1478,69 @@ TEST_F(HttpHalfResponseParser, GzipChunkResponseStream)
EXPECT_EQ(ret, 1);
}
static const char * __str_test_split_http_1 =
"GET http://download.bookset.me/d.php?f=2008/9/%5B%E6%97%A5%5D-%E4%B8%9C%E9%87%8E%E5%9C%AD%E5%90%BE-%E7%99%BD%E5%A4%9C%E8%A1%8C-9787544242516.epub HTTP/1.1\r\n"
"Host: download.bookset.me\r\n"
"Proxy-Connection: keep-alive\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Upgrade-Insecure-Requests: 1\r\n"
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36\r\n"
"DNT: 1\r\n"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n"
"Accept-Encoding: gzip, deflate";
static const char * __str_test_split_http_2 =
"\r\nAccept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-US;q=0.7\r\n"
"Cookie: __cfduid=d9409925f352f688f4276a454c05a6b8e1548735697\r\n"
"\r\n";
static const char * __str_test_split_http_resp_1 =
"\nHTTP/1.1 200 OK\r\n"
"Date: Tue, 29 Jan 2019 04:22:25 GMT\r\n"
"Content-Type: application/octet-stream\r\n"
"Content-Length: 491664\r\n"
"Connection: close\r\n"
"X-Powered-By: PHP/7.0.21\r\n"
"Content-Transfer-Encoding: Binary\r\n"
"Content-disposition: attachment; filename=87544242516.epub\r\n"
"Server: cloudflare\r\n"
"CF-RAY: 4a08eae2e77dc28d-FRA\r\n";
TEST(HttpHalfRequestParser, SplitRequestAtHeader)
{
auto * hf_request = hf_private_create(TFE_HTTP_REQUEST, 1, 1);
ASSERT_TRUE(hf_request != NULL);
/* First Part of HTTP Request */
int ret = hf_private_parse(hf_request, (const unsigned char *) __str_test_split_http_1,
strlen(__str_test_split_http_1));
EXPECT_EQ(ret, 0);
EXPECT_EQ(hf_request->parse_cursor, strlen(__str_test_split_http_1));
hf_request->parse_cursor = 0;
ret = hf_private_parse(hf_request, (const unsigned char *) __str_test_split_http_2,
strlen(__str_test_split_http_2));
EXPECT_EQ(ret, 1);
EXPECT_EQ(hf_request->parse_cursor, strlen(__str_test_split_http_2));
}
TEST(HttpHalfRequestParser, SplitResponseAtHeader)
{
auto * hf_request = hf_private_create(TFE_HTTP_RESPONSE, 1, 1);
ASSERT_TRUE(hf_request != NULL);
/* First Part of HTTP Request */
int ret = hf_private_parse(hf_request, (const unsigned char *) __str_test_split_http_resp_1,
strlen(__str_test_split_http_resp_1));
EXPECT_EQ(ret, 0);
EXPECT_EQ(hf_request->parse_cursor, strlen(__str_test_split_http_resp_1));
}
void tfe_stream_write_access_log(const struct tfe_stream * stream, int level, const char * fmt, ...)
{
return;

View File

@@ -61,8 +61,8 @@ set_property(TARGET libevent-static-pthreads PROPERTY INTERFACE_INCLUDE_DIRECTOR
### http parser
ExternalProject_Add(http-parser PREFIX http-parser
URL ${CMAKE_CURRENT_SOURCE_DIR}/http-parser-2.8.1.tar.gz
URL_MD5 cb8cbe17d68c4101eebe80229e32efdb
URL ${CMAKE_CURRENT_SOURCE_DIR}/http-parser-2.9.0.tar.gz
URL_MD5 203c6fbb7e24714fd22398f2a9c5c210
CONFIGURE_COMMAND ""
BUILD_COMMAND make package
INSTALL_COMMAND ""

Binary file not shown.

BIN
vendor/http-parser-2.9.0.tar.gz vendored Normal file

Binary file not shown.