aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authordarkk <darkk@yandex-team.ru>2022-02-10 16:49:49 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:49 +0300
commitf772ca38c4a395b911129411c06b2074d69d826f (patch)
tree76717845f670ca68fd5ebb858eaaf9963032c74e /library/cpp
parentab4e3e6f0c4354283ce0375c811569c080cbfbc3 (diff)
downloadydb-f772ca38c4a395b911129411c06b2074d69d826f.tar.gz
Restoring authorship annotation for <darkk@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/http/fetch/httpfsm.h14
-rw-r--r--library/cpp/http/fetch/httpfsm_ut.cpp256
-rw-r--r--library/cpp/http/fetch/httpparser_ut.cpp232
-rw-r--r--library/cpp/http/fetch/ut/ya.make2
4 files changed, 252 insertions, 252 deletions
diff --git a/library/cpp/http/fetch/httpfsm.h b/library/cpp/http/fetch/httpfsm.h
index c4abdcd0d2..d09670545b 100644
--- a/library/cpp/http/fetch/httpfsm.h
+++ b/library/cpp/http/fetch/httpfsm.h
@@ -8,13 +8,13 @@
#include <time.h>
struct THttpHeaderParser {
- static constexpr int ErrFirstlineTypeMismatch = -3;
- static constexpr int ErrHeader = -2;
- static constexpr int Err = -1;
- static constexpr int Final = 0;
- static constexpr int NeedMore = 1;
- static constexpr int Accepted = 2;
-
+ static constexpr int ErrFirstlineTypeMismatch = -3;
+ static constexpr int ErrHeader = -2;
+ static constexpr int Err = -1;
+ static constexpr int Final = 0;
+ static constexpr int NeedMore = 1;
+ static constexpr int Accepted = 2;
+
int Execute(const void* inBuf, size_t len) {
return execute((unsigned char*)inBuf, (int)len);
}
diff --git a/library/cpp/http/fetch/httpfsm_ut.cpp b/library/cpp/http/fetch/httpfsm_ut.cpp
index b018e80101..2c996d6d9c 100644
--- a/library/cpp/http/fetch/httpfsm_ut.cpp
+++ b/library/cpp/http/fetch/httpfsm_ut.cpp
@@ -2,7 +2,7 @@
#include "library-htfetch_ut_hreflang_in.h"
#include "library-htfetch_ut_hreflang_out.h"
-#include <util/generic/ptr.h>
+#include <util/generic/ptr.h>
#include <library/cpp/charset/doccodes.h>
#include <library/cpp/testing/unittest/registar.h>
@@ -33,7 +33,7 @@ class THttpHeaderParserTestSuite: public TTestBase {
UNIT_TEST_SUITE_END();
private:
- THolder<THttpHeaderParser> httpHeaderParser;
+ THolder<THttpHeaderParser> httpHeaderParser;
private:
void TestStart();
@@ -41,8 +41,8 @@ private:
public:
void TestRequestHeader();
- void TestSplitRequestHeader();
- void TestTrailingData();
+ void TestSplitRequestHeader();
+ void TestTrailingData();
void TestProxyRequestHeader();
void TestIncorrectRequestHeader();
void TestLastModified();
@@ -65,11 +65,11 @@ public:
};
void THttpHeaderParserTestSuite::TestStart() {
- httpHeaderParser.Reset(new THttpHeaderParser());
+ httpHeaderParser.Reset(new THttpHeaderParser());
}
void THttpHeaderParserTestSuite::TestFinish() {
- httpHeaderParser.Reset();
+ httpHeaderParser.Reset();
}
void THttpHeaderParserTestSuite::TestRequestHeader() {
@@ -83,7 +83,7 @@ void THttpHeaderParserTestSuite::TestRequestHeader() {
UNIT_ASSERT_EQUAL(httpRequestHeader.http_method, HTTP_METHOD_GET);
UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.host, "www.google.ru:8080"), 0);
UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "/search?q=hi");
- UNIT_ASSERT_EQUAL(httpRequestHeader.GetUrl(), "http://www.google.ru:8080/search?q=hi");
+ UNIT_ASSERT_EQUAL(httpRequestHeader.GetUrl(), "http://www.google.ru:8080/search?q=hi");
UNIT_ASSERT_EQUAL(httpHeaderParser->lastchar - request + 1,
(i32)strlen(request));
UNIT_ASSERT_EQUAL(httpRequestHeader.x_yandex_response_timeout,
@@ -97,61 +97,61 @@ void THttpHeaderParserTestSuite::TestRequestHeader() {
UNIT_ASSERT_EQUAL(httpRequestHeader.max_age, DEFAULT_MAX_AGE);
}
-void THttpHeaderParserTestSuite::TestSplitRequestHeader() {
- TestStart();
+void THttpHeaderParserTestSuite::TestSplitRequestHeader() {
+ TestStart();
const char* request =
- "GET /search?q=hi HTTP/1.1\r\n"
- "Host: www.google.ru:8080 \r\n"
- "\r\n";
- const size_t rlen = strlen(request);
-
- for (size_t n1 = 0; n1 < rlen; n1++) {
- for (size_t n2 = n1; n2 < rlen; n2++) {
+ "GET /search?q=hi HTTP/1.1\r\n"
+ "Host: www.google.ru:8080 \r\n"
+ "\r\n";
+ const size_t rlen = strlen(request);
+
+ for (size_t n1 = 0; n1 < rlen; n1++) {
+ for (size_t n2 = n1; n2 < rlen; n2++) {
TString s1{request, 0, n1};
TString s2{request, n1, n2 - n1};
TString s3{request, n2, rlen - n2};
- UNIT_ASSERT_EQUAL(s1 + s2 + s3, request);
-
- THttpRequestHeader httpRequestHeader;
- UNIT_ASSERT(0 == httpHeaderParser->Init(&httpRequestHeader));
- i32 result = httpHeaderParser->Execute(s1);
- UNIT_ASSERT_EQUAL(result, 1);
- result = httpHeaderParser->Execute(s2);
- UNIT_ASSERT_EQUAL(result, 1);
- result = httpHeaderParser->Execute(s3);
- UNIT_ASSERT_EQUAL(result, 2);
-
- UNIT_ASSERT_EQUAL(httpRequestHeader.http_method, HTTP_METHOD_GET);
- UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.host, "www.google.ru:8080"), 0);
+ UNIT_ASSERT_EQUAL(s1 + s2 + s3, request);
+
+ THttpRequestHeader httpRequestHeader;
+ UNIT_ASSERT(0 == httpHeaderParser->Init(&httpRequestHeader));
+ i32 result = httpHeaderParser->Execute(s1);
+ UNIT_ASSERT_EQUAL(result, 1);
+ result = httpHeaderParser->Execute(s2);
+ UNIT_ASSERT_EQUAL(result, 1);
+ result = httpHeaderParser->Execute(s3);
+ UNIT_ASSERT_EQUAL(result, 2);
+
+ UNIT_ASSERT_EQUAL(httpRequestHeader.http_method, HTTP_METHOD_GET);
+ UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.host, "www.google.ru:8080"), 0);
UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "/search?q=hi");
- }
- }
-
- TestFinish();
-}
-
-void THttpHeaderParserTestSuite::TestTrailingData() {
- TestStart();
- THttpRequestHeader httpRequestHeader;
- UNIT_ASSERT(0 == httpHeaderParser->Init(&httpRequestHeader));
+ }
+ }
+
+ TestFinish();
+}
+
+void THttpHeaderParserTestSuite::TestTrailingData() {
+ TestStart();
+ THttpRequestHeader httpRequestHeader;
+ UNIT_ASSERT(0 == httpHeaderParser->Init(&httpRequestHeader));
const char* request =
- "GET /search?q=hi HTTP/1.1\r\n"
- "Host: www.google.ru:8080\r\n"
- "\r\n"
- "high.ru";
- i32 result = httpHeaderParser->Execute(request, strlen(request));
- UNIT_ASSERT_EQUAL(result, 2);
- UNIT_ASSERT_EQUAL(httpRequestHeader.http_method, HTTP_METHOD_GET);
- UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.host, "www.google.ru:8080"), 0);
+ "GET /search?q=hi HTTP/1.1\r\n"
+ "Host: www.google.ru:8080\r\n"
+ "\r\n"
+ "high.ru";
+ i32 result = httpHeaderParser->Execute(request, strlen(request));
+ UNIT_ASSERT_EQUAL(result, 2);
+ UNIT_ASSERT_EQUAL(httpRequestHeader.http_method, HTTP_METHOD_GET);
+ UNIT_ASSERT_EQUAL(strcmp(httpRequestHeader.host, "www.google.ru:8080"), 0);
UNIT_ASSERT_EQUAL(httpRequestHeader.request_uri, "/search?q=hi");
UNIT_ASSERT_EQUAL(TString(httpHeaderParser->lastchar + 1), "high.ru");
- UNIT_ASSERT_EQUAL(httpRequestHeader.http_minor, 1);
- UNIT_ASSERT_EQUAL(httpRequestHeader.transfer_chunked, -1);
- UNIT_ASSERT_EQUAL(httpRequestHeader.content_length, -1);
- UNIT_ASSERT_EQUAL(httpRequestHeader.connection_closed, -1);
- TestFinish();
-}
-
+ UNIT_ASSERT_EQUAL(httpRequestHeader.http_minor, 1);
+ UNIT_ASSERT_EQUAL(httpRequestHeader.transfer_chunked, -1);
+ UNIT_ASSERT_EQUAL(httpRequestHeader.content_length, -1);
+ UNIT_ASSERT_EQUAL(httpRequestHeader.connection_closed, -1);
+ TestFinish();
+}
+
void THttpHeaderParserTestSuite::TestProxyRequestHeader() {
TestStart();
THttpRequestHeader httpRequestHeader;
@@ -431,7 +431,7 @@ void THttpHeaderParserTestSuite::TestResponseHeaderOnRequest() {
const char* request = "GET /search?q=hi HTP/1.1\r\n"
"Host: www.google.ru:8080\r\n\r\n";
i32 result = httpHeaderParser->Execute(request, strlen(request));
- UNIT_ASSERT_EQUAL(result, -3);
+ UNIT_ASSERT_EQUAL(result, -3);
TestFinish();
}
@@ -443,7 +443,7 @@ void THttpHeaderParserTestSuite::TestRequestHeaderOnResponse() {
"Content-Type: text/html\r\n"
"Last-Modified: Thu, 13 Aug 2009 14:\r\n\r\n";
i32 result = httpHeaderParser->Execute(response, strlen(response));
- UNIT_ASSERT_EQUAL(result, -3);
+ UNIT_ASSERT_EQUAL(result, -3);
TestFinish();
}
@@ -489,103 +489,103 @@ void THttpHeaderParserTestSuite::TestRepeatedContentEncoding() {
UNIT_TEST_SUITE_REGISTRATION(THttpHeaderParserTestSuite);
Y_UNIT_TEST_SUITE(TestHttpChunkParser) {
- static THttpChunkParser initParser() {
- THttpChunkParser parser;
- parser.Init();
- return parser;
- }
-
+ static THttpChunkParser initParser() {
+ THttpChunkParser parser;
+ parser.Init();
+ return parser;
+ }
+
static THttpChunkParser parseByteByByte(const TStringBuf& blob, const TVector<int>& states) {
UNIT_ASSERT(states.size() <= blob.size());
- THttpChunkParser parser{initParser()};
- for (size_t n = 0; n < states.size(); n++) {
- const TStringBuf d{blob, n, 1};
+ THttpChunkParser parser{initParser()};
+ for (size_t n = 0; n < states.size(); n++) {
+ const TStringBuf d{blob, n, 1};
int code = parser.Execute(d.data(), d.size());
Cout << TString(d).Quote() << " " << code << Endl;
- UNIT_ASSERT_EQUAL(code, states[n]);
- }
- return parser;
- }
-
- static THttpChunkParser parseBytesWithLastState(const TStringBuf& blob, const int last_state) {
+ UNIT_ASSERT_EQUAL(code, states[n]);
+ }
+ return parser;
+ }
+
+ static THttpChunkParser parseBytesWithLastState(const TStringBuf& blob, const int last_state) {
TVector<int> states(blob.size() - 1, 1);
- states.push_back(last_state);
- return parseByteByByte(blob, states);
- }
-
+ states.push_back(last_state);
+ return parseByteByByte(blob, states);
+ }
+
Y_UNIT_TEST(TestWithoutEolHead) {
- const TStringBuf blob{
- "4\r\n"
+ const TStringBuf blob{
+ "4\r\n"
"____\r\n"};
TVector<int> states{
-1, /* 1, -1,
1, -1, 1, -1, 1, -1 */};
- // as soon as error happens parser state should be considered
- // undefined, state is meaningless after the very first `-1`
- // moreover, testenv produces `states[1] == -1` for this input and
- // my local build produces `states[1] == 1`.
- parseByteByByte(blob, states);
- }
-
+ // as soon as error happens parser state should be considered
+ // undefined, state is meaningless after the very first `-1`
+ // moreover, testenv produces `states[1] == -1` for this input and
+ // my local build produces `states[1] == 1`.
+ parseByteByByte(blob, states);
+ }
+
Y_UNIT_TEST(TestTrivialChunk) {
- const TStringBuf blob{
- "\r\n"
+ const TStringBuf blob{
+ "\r\n"
"4\r\n"};
- THttpChunkParser parser(parseBytesWithLastState(blob, 2));
- UNIT_ASSERT_EQUAL(parser.chunk_length, 4);
- UNIT_ASSERT_EQUAL(parser.cnt64, 4);
- }
-
+ THttpChunkParser parser(parseBytesWithLastState(blob, 2));
+ UNIT_ASSERT_EQUAL(parser.chunk_length, 4);
+ UNIT_ASSERT_EQUAL(parser.cnt64, 4);
+ }
+
Y_UNIT_TEST(TestNegative) {
- const TStringBuf blob{
- "\r\n"
+ const TStringBuf blob{
+ "\r\n"
"-1"};
TVector<int> states{
- 1, 1,
+ 1, 1,
-1,
/* 1 */};
- parseByteByByte(blob, states);
- }
-
+ parseByteByByte(blob, states);
+ }
+
Y_UNIT_TEST(TestLeadingZero) {
- const TStringBuf blob{
- "\r\n"
+ const TStringBuf blob{
+ "\r\n"
"042\r\n"};
- THttpChunkParser parser(parseBytesWithLastState(blob, 2));
- UNIT_ASSERT_EQUAL(parser.chunk_length, 0x42);
- }
-
+ THttpChunkParser parser(parseBytesWithLastState(blob, 2));
+ UNIT_ASSERT_EQUAL(parser.chunk_length, 0x42);
+ }
+
Y_UNIT_TEST(TestIntOverflow) {
- const TStringBuf blob{
- "\r\n"
+ const TStringBuf blob{
+ "\r\n"
"deadbeef"};
- THttpChunkParser parser(parseBytesWithLastState(blob, -2));
- UNIT_ASSERT_EQUAL(parser.chunk_length, 0);
- UNIT_ASSERT_EQUAL(parser.cnt64, 0xdeadbeef);
- }
-
+ THttpChunkParser parser(parseBytesWithLastState(blob, -2));
+ UNIT_ASSERT_EQUAL(parser.chunk_length, 0);
+ UNIT_ASSERT_EQUAL(parser.cnt64, 0xdeadbeef);
+ }
+
Y_UNIT_TEST(TestTrivialChunkWithTail) {
- const TStringBuf blob{
- "\r\n"
- "4\r\n"
- "_" // first byte of the chunk
- };
+ const TStringBuf blob{
+ "\r\n"
+ "4\r\n"
+ "_" // first byte of the chunk
+ };
TVector<int> states{
1, 1,
1, 1, 2,
-1};
- parseByteByByte(blob, states);
- }
-
+ parseByteByByte(blob, states);
+ }
+
Y_UNIT_TEST(TestLastChunk) {
- // NB: current parser does not permit whitespace before `foo`,
- // but I've never seen the feature in real-life traffic
- const TStringBuf blob{
- "\r\n"
- "000 ;foo = bar \r\n"
- "Trailer: bar\r\n"
+ // NB: current parser does not permit whitespace before `foo`,
+ // but I've never seen the feature in real-life traffic
+ const TStringBuf blob{
+ "\r\n"
+ "000 ;foo = bar \r\n"
+ "Trailer: bar\r\n"
"\r\n"};
- THttpChunkParser parser(parseBytesWithLastState(blob, 2));
- UNIT_ASSERT_EQUAL(parser.chunk_length, 0);
- }
-}
+ THttpChunkParser parser(parseBytesWithLastState(blob, 2));
+ UNIT_ASSERT_EQUAL(parser.chunk_length, 0);
+ }
+}
diff --git a/library/cpp/http/fetch/httpparser_ut.cpp b/library/cpp/http/fetch/httpparser_ut.cpp
index 3b3b938e7a..6bb83f3971 100644
--- a/library/cpp/http/fetch/httpparser_ut.cpp
+++ b/library/cpp/http/fetch/httpparser_ut.cpp
@@ -1,41 +1,41 @@
-#include "httpparser.h"
-
+#include "httpparser.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
#define ENUM_OUT(arg) \
case type ::arg: { \
out << #arg; \
return; \
}
-
+
template <>
void Out<THttpParserBase::States>(IOutputStream& out, THttpParserBase::States st) {
- using type = THttpParserBase::States;
- switch (st) {
- ENUM_OUT(hp_error)
- ENUM_OUT(hp_eof)
- ENUM_OUT(hp_in_header)
- ENUM_OUT(hp_read_alive)
- ENUM_OUT(hp_read_closed)
- ENUM_OUT(hp_begin_chunk_header)
- ENUM_OUT(hp_chunk_header)
- ENUM_OUT(hp_read_chunk)
- }
-}
-
-namespace {
+ using type = THttpParserBase::States;
+ switch (st) {
+ ENUM_OUT(hp_error)
+ ENUM_OUT(hp_eof)
+ ENUM_OUT(hp_in_header)
+ ENUM_OUT(hp_read_alive)
+ ENUM_OUT(hp_read_closed)
+ ENUM_OUT(hp_begin_chunk_header)
+ ENUM_OUT(hp_chunk_header)
+ ENUM_OUT(hp_read_chunk)
+ }
+}
+
+namespace {
class TSomethingLikeFakeCheck;
-
+
using TTestHttpParser = THttpParser<TSomethingLikeFakeCheck>;
-
+
class TSomethingLikeFakeCheck {
TString Body_;
-
+
public:
const TString& Body() const {
return Body_;
}
-
+
// other functions are not really called by THttpParser
void CheckDocPart(const void* buf, size_t len, THttpHeader* /* header */) {
TString s(static_cast<const char*>(buf), len);
@@ -43,74 +43,74 @@ namespace {
Body_ += s;
}
};
-
+
}
-
+
Y_UNIT_TEST_SUITE(TestHttpParser) {
Y_UNIT_TEST(TestTrivialRequest) {
const TString blob{
- "GET /search?q=hi HTTP/1.1\r\n"
- "Host: www.google.ru:8080 \r\n"
- "\r\n"};
- THttpHeader hdr;
- THttpParser<> parser;
- parser.Init(&hdr);
+ "GET /search?q=hi HTTP/1.1\r\n"
+ "Host: www.google.ru:8080 \r\n"
+ "\r\n"};
+ THttpHeader hdr;
+ THttpParser<> parser;
+ parser.Init(&hdr);
parser.Parse((void*)blob.data(), blob.size());
- UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_error); // can't parse request as response
- }
-
- // XXX: `entity_size` is i32 and `content_length` is i64!
+ UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_error); // can't parse request as response
+ }
+
+ // XXX: `entity_size` is i32 and `content_length` is i64!
Y_UNIT_TEST(TestTrivialResponse) {
const TString blob{
- "HTTP/1.1 200 Ok\r\n"
- "Content-Length: 2\r\n"
- "\r\n"
- "OK"};
- THttpHeader hdr;
- TTestHttpParser parser;
- parser.Init(&hdr);
+ "HTTP/1.1 200 Ok\r\n"
+ "Content-Length: 2\r\n"
+ "\r\n"
+ "OK"};
+ THttpHeader hdr;
+ TTestHttpParser parser;
+ parser.Init(&hdr);
parser.Parse((void*)blob.data(), blob.size());
- UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
- UNIT_ASSERT_EQUAL(parser.Body(), "OK");
- UNIT_ASSERT_EQUAL(hdr.header_size, strlen(
+ UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
+ UNIT_ASSERT_EQUAL(parser.Body(), "OK");
+ UNIT_ASSERT_EQUAL(hdr.header_size, strlen(
"HTTP/1.1 200 Ok\r\n"
"Content-Length: 2\r\n"
"\r\n"));
- UNIT_ASSERT_EQUAL(hdr.entity_size, strlen("OK"));
- }
-
- // XXX: `entity_size` is off by one in TE:chunked case.
+ UNIT_ASSERT_EQUAL(hdr.entity_size, strlen("OK"));
+ }
+
+ // XXX: `entity_size` is off by one in TE:chunked case.
Y_UNIT_TEST(TestChunkedResponse) {
const TString blob{
- "HTTP/1.1 200 OK\r\n"
- "Transfer-Encoding: chunked\r\n"
- "\r\n"
- "2\r\n"
- "Ok\r\n"
- "8\r\n"
- "AllRight\r\n"
- "0\r\n"
- "\r\n"};
- THttpHeader hdr;
- TTestHttpParser parser;
- parser.Init(&hdr);
+ "HTTP/1.1 200 OK\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "2\r\n"
+ "Ok\r\n"
+ "8\r\n"
+ "AllRight\r\n"
+ "0\r\n"
+ "\r\n"};
+ THttpHeader hdr;
+ TTestHttpParser parser;
+ parser.Init(&hdr);
parser.Parse((void*)blob.data(), blob.size());
- UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
- UNIT_ASSERT_EQUAL(parser.Body(), "OkAllRight");
- UNIT_ASSERT_EQUAL(hdr.header_size, strlen(
+ UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
+ UNIT_ASSERT_EQUAL(parser.Body(), "OkAllRight");
+ UNIT_ASSERT_EQUAL(hdr.header_size, strlen(
"HTTP/1.1 200 OK\r\n"
"Transfer-Encoding: chunked\r\n"
"\r\n"));
- const int off_by_one_err = -1; // XXX: it really looks so
- UNIT_ASSERT_EQUAL(hdr.entity_size + off_by_one_err, strlen(
+ const int off_by_one_err = -1; // XXX: it really looks so
+ UNIT_ASSERT_EQUAL(hdr.entity_size + off_by_one_err, strlen(
"2\r\n"
"Ok\r\n"
"8\r\n"
"AllRight\r\n"
"0\r\n"
"\r\n"));
- }
-
+ }
+
static const TString PipelineClenBlob_{
"HTTP/1.1 200 Ok\r\n"
"Content-Length: 4\r\n"
@@ -120,53 +120,53 @@ Y_UNIT_TEST_SUITE(TestHttpParser) {
"Content-Length: 4\r\n"
"\r\n"
"ZZ\r\n"};
-
+
void AssertPipelineClen(TTestHttpParser & parser, const THttpHeader& hdr) {
- UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
- UNIT_ASSERT_EQUAL(4, hdr.content_length);
- UNIT_ASSERT_EQUAL(hdr.header_size, strlen(
+ UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
+ UNIT_ASSERT_EQUAL(4, hdr.content_length);
+ UNIT_ASSERT_EQUAL(hdr.header_size, strlen(
"HTTP/1.1 200 Ok\r\n"
"Content-Length: 4\r\n"
"\r\n"));
- }
-
+ }
+
Y_UNIT_TEST(TestPipelineClenByteByByte) {
const TString& blob = PipelineClenBlob_;
- THttpHeader hdr;
- TTestHttpParser parser;
- parser.Init(&hdr);
+ THttpHeader hdr;
+ TTestHttpParser parser;
+ parser.Init(&hdr);
for (size_t i = 0; i < blob.size(); ++i) {
- const TStringBuf d{blob, i, 1};
+ const TStringBuf d{blob, i, 1};
parser.Parse((void*)d.data(), d.size());
Cout << TString(d).Quote() << " -> " << parser.GetState() << Endl;
- }
- AssertPipelineClen(parser, hdr);
- UNIT_ASSERT_EQUAL(parser.Body(), "OK\r\n");
- UNIT_ASSERT_EQUAL(hdr.entity_size, hdr.content_length);
- }
-
- // XXX: Content-Length is ignored, Body() looks unexpected!
+ }
+ AssertPipelineClen(parser, hdr);
+ UNIT_ASSERT_EQUAL(parser.Body(), "OK\r\n");
+ UNIT_ASSERT_EQUAL(hdr.entity_size, hdr.content_length);
+ }
+
+ // XXX: Content-Length is ignored, Body() looks unexpected!
Y_UNIT_TEST(TestPipelineClenOneChunk) {
const TString& blob = PipelineClenBlob_;
- THttpHeader hdr;
- TTestHttpParser parser;
- parser.Init(&hdr);
+ THttpHeader hdr;
+ TTestHttpParser parser;
+ parser.Init(&hdr);
parser.Parse((void*)blob.data(), blob.size());
- AssertPipelineClen(parser, hdr);
- UNIT_ASSERT_EQUAL(parser.Body(),
+ AssertPipelineClen(parser, hdr);
+ UNIT_ASSERT_EQUAL(parser.Body(),
"OK\r\n"
"HTTP/1.1 200 Zz\r\n"
"Content-Length: 4\r\n"
"\r\n"
"ZZ\r\n");
- UNIT_ASSERT_EQUAL(hdr.entity_size, strlen(
+ UNIT_ASSERT_EQUAL(hdr.entity_size, strlen(
"OK\r\n"
"HTTP/1.1 200 Zz\r\n"
"Content-Length: 4\r\n"
"\r\n"
"ZZ\r\n"));
- }
-
+ }
+
static const TString PipelineChunkedBlob_{
"HTTP/1.1 200 OK\r\n"
"Transfer-Encoding: chunked\r\n"
@@ -186,46 +186,46 @@ Y_UNIT_TEST_SUITE(TestHttpParser) {
"uWin!Iam\r\n"
"0\r\n"
"\r\n"};
-
+
void AssertPipelineChunked(TTestHttpParser & parser, const THttpHeader& hdr) {
- UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
- UNIT_ASSERT_EQUAL(parser.Body(), "OkAllRight");
- UNIT_ASSERT_EQUAL(-1, hdr.content_length);
- UNIT_ASSERT_EQUAL(hdr.header_size, strlen(
+ UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
+ UNIT_ASSERT_EQUAL(parser.Body(), "OkAllRight");
+ UNIT_ASSERT_EQUAL(-1, hdr.content_length);
+ UNIT_ASSERT_EQUAL(hdr.header_size, strlen(
"HTTP/1.1 200 OK\r\n"
"Transfer-Encoding: chunked\r\n"
"\r\n"));
- const int off_by_one_err = -1;
- UNIT_ASSERT_EQUAL(hdr.entity_size + off_by_one_err, strlen(
+ const int off_by_one_err = -1;
+ UNIT_ASSERT_EQUAL(hdr.entity_size + off_by_one_err, strlen(
"2\r\n"
"Ok\r\n"
"8\r\n"
"AllRight\r\n"
"0\r\n"
"\r\n"));
- }
-
+ }
+
Y_UNIT_TEST(TestPipelineChunkedByteByByte) {
const TString& blob = PipelineChunkedBlob_;
- THttpHeader hdr;
- TTestHttpParser parser;
- parser.Init(&hdr);
+ THttpHeader hdr;
+ TTestHttpParser parser;
+ parser.Init(&hdr);
for (size_t i = 0; i < blob.size(); ++i) {
- const TStringBuf d{blob, i, 1};
+ const TStringBuf d{blob, i, 1};
parser.Parse((void*)d.data(), d.size());
Cout << TString(d).Quote() << " -> " << parser.GetState() << Endl;
if (blob.size() / 2 - 1 <= i) // last \n sets EOF
- UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
- }
- AssertPipelineChunked(parser, hdr);
- }
-
+ UNIT_ASSERT_EQUAL(parser.GetState(), parser.hp_eof);
+ }
+ AssertPipelineChunked(parser, hdr);
+ }
+
Y_UNIT_TEST(TestPipelineChunkedOneChunk) {
const TString& blob = PipelineChunkedBlob_;
- THttpHeader hdr;
- TTestHttpParser parser;
- parser.Init(&hdr);
+ THttpHeader hdr;
+ TTestHttpParser parser;
+ parser.Init(&hdr);
parser.Parse((void*)blob.data(), blob.size());
- AssertPipelineChunked(parser, hdr);
- }
-}
+ AssertPipelineChunked(parser, hdr);
+ }
+}
diff --git a/library/cpp/http/fetch/ut/ya.make b/library/cpp/http/fetch/ut/ya.make
index 7486986b36..656227d3d4 100644
--- a/library/cpp/http/fetch/ut/ya.make
+++ b/library/cpp/http/fetch/ut/ya.make
@@ -6,7 +6,7 @@ OWNER(
SRCS(
httpfsm_ut.cpp
- httpparser_ut.cpp
+ httpparser_ut.cpp
)
END()