diff options
author | darkk <darkk@yandex-team.ru> | 2022-02-10 16:49:49 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:49 +0300 |
commit | 53d07fb9e28d179add32cd299c9341bf8a231a31 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 | |
parent | f772ca38c4a395b911129411c06b2074d69d826f (diff) | |
download | ydb-53d07fb9e28d179add32cd299c9341bf8a231a31.tar.gz |
Restoring authorship annotation for <darkk@yandex-team.ru>. Commit 2 of 2.
-rw-r--r-- | library/cpp/http/fetch/httpfsm.h | 14 | ||||
-rw-r--r-- | library/cpp/http/fetch/httpfsm_ut.cpp | 256 | ||||
-rw-r--r-- | library/cpp/http/fetch/httpparser_ut.cpp | 232 | ||||
-rw-r--r-- | library/cpp/http/fetch/ut/ya.make | 2 | ||||
-rw-r--r-- | tools/ya.make | 2 | ||||
-rw-r--r-- | util/datetime/parser.h | 2 | ||||
-rw-r--r-- | util/datetime/parser.rl6 | 20 | ||||
-rw-r--r-- | util/datetime/parser_ut.cpp | 54 | ||||
-rw-r--r-- | util/draft/ip.h | 30 | ||||
-rw-r--r-- | util/generic/refcount.h | 18 |
10 files changed, 315 insertions, 315 deletions
diff --git a/library/cpp/http/fetch/httpfsm.h b/library/cpp/http/fetch/httpfsm.h index d09670545b..c4abdcd0d2 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 2c996d6d9c..b018e80101 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 6bb83f3971..3b3b938e7a 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 656227d3d4..7486986b36 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() diff --git a/tools/ya.make b/tools/ya.make index abead533ad..51a6b8b426 100644 --- a/tools/ya.make +++ b/tools/ya.make @@ -176,7 +176,7 @@ RECURSE( webxmltest wizard_yt ygetparam - ylzocat + ylzocat yson_pp zk_client idx_print diff --git a/util/datetime/parser.h b/util/datetime/parser.h index 4735d41c01..f0c1b4a0c7 100644 --- a/util/datetime/parser.h +++ b/util/datetime/parser.h @@ -146,7 +146,7 @@ struct TDurationParser { ui32 Dc; i32 MultiplierPower; // 6 for seconds, 0 for microseconds, -3 for nanoseconds - i32 Multiplier; + i32 Multiplier; ui64 IntegerPart; ui32 FractionPart; ui32 FractionDigits; diff --git a/util/datetime/parser.rl6 b/util/datetime/parser.rl6 index def64235a1..931f09eae1 100644 --- a/util/datetime/parser.rl6 +++ b/util/datetime/parser.rl6 @@ -730,13 +730,13 @@ include DateTimeParserCommon; multiplier = '' # >{ MultiplierPower = 6; } # work around Ragel bugs | 'w' @{ MultiplierPower = 6; Multiplier = 604800; } - | 'd' @{ MultiplierPower = 6; Multiplier = 86400; } - | 'h' @{ MultiplierPower = 6; Multiplier = 3600; } - | 'm' @{ MultiplierPower = 6; Multiplier = 60; } - | 's' @{ MultiplierPower = 6; Multiplier = 1; } - | 'ms' @{ MultiplierPower = 3; Multiplier = 1; } - | 'us' @{ MultiplierPower = 0; Multiplier = 1; } - | 'ns' @{ MultiplierPower = -3; Multiplier = 1; } + | 'd' @{ MultiplierPower = 6; Multiplier = 86400; } + | 'h' @{ MultiplierPower = 6; Multiplier = 3600; } + | 'm' @{ MultiplierPower = 6; Multiplier = 60; } + | 's' @{ MultiplierPower = 6; Multiplier = 1; } + | 'ms' @{ MultiplierPower = 3; Multiplier = 1; } + | 'us' @{ MultiplierPower = 0; Multiplier = 1; } + | 'ns' @{ MultiplierPower = -3; Multiplier = 1; } ; integer = int @{ IntegerPart = I; }; @@ -756,7 +756,7 @@ TDurationParser::TDurationParser() , I(0) , Dc(0) , MultiplierPower(6) - , Multiplier(1) + , Multiplier(1) , IntegerPart(0) , FractionPart(0) , FractionDigits(0) @@ -783,8 +783,8 @@ TDuration TDurationParser::GetResult(TDuration defaultValue) const { if (cs < TDurationParser_first_final) return defaultValue; ui64 us = 0; - us += Multiplier * DecPower(IntegerPart, MultiplierPower); - us += Multiplier * DecPower(FractionPart, MultiplierPower - FractionDigits); + us += Multiplier * DecPower(IntegerPart, MultiplierPower); + us += Multiplier * DecPower(FractionPart, MultiplierPower - FractionDigits); return TDuration::MicroSeconds(us); } diff --git a/util/datetime/parser_ut.cpp b/util/datetime/parser_ut.cpp index fe59b95452..61364af997 100644 --- a/util/datetime/parser_ut.cpp +++ b/util/datetime/parser_ut.cpp @@ -573,38 +573,38 @@ Y_UNIT_TEST_SUITE(TDateTimeParseTest) { Y_UNIT_TEST_SUITE(TDurationParseTest) { Y_UNIT_TEST(TestParse) { UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(60 * 60 * 24 * 7), TDuration::Parse("1w")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(60), TDuration::Parse("1m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(90), TDuration::Parse("1.5m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(102), TDuration::Parse("1.7m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119400), TDuration::Parse("1.99m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119940), TDuration::Parse("1.999m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119994), TDuration::Parse("1.9999m")); - - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(60), TDuration::Parse("1h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(90), TDuration::Parse("1.5h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(102), TDuration::Parse("1.7h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(7164), TDuration::Parse("1.99h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(7196400), TDuration::Parse("1.999h")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(7199640), TDuration::Parse("1.9999h")); - + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(60), TDuration::Parse("1m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(90), TDuration::Parse("1.5m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(102), TDuration::Parse("1.7m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119400), TDuration::Parse("1.99m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119940), TDuration::Parse("1.999m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(119994), TDuration::Parse("1.9999m")); + + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(60), TDuration::Parse("1h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(90), TDuration::Parse("1.5h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(102), TDuration::Parse("1.7h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(7164), TDuration::Parse("1.99h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(7196400), TDuration::Parse("1.999h")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(7199640), TDuration::Parse("1.9999h")); + UNIT_ASSERT_EQUAL(TDuration::Minutes(15), TDuration::Parse("15m")); UNIT_ASSERT_EQUAL(TDuration::Hours(10), TDuration::Parse("10h")); UNIT_ASSERT_EQUAL(TDuration::Days(365), TDuration::Parse("365d")); UNIT_ASSERT_EQUAL(TDuration::Hours(36), TDuration::Parse("1.5d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(24), TDuration::Parse("1d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(36), TDuration::Parse("1.5d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(2448), TDuration::Parse("1.7d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(171936), TDuration::Parse("1.99d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(172713600), TDuration::Parse("1.999d")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(172791360), TDuration::Parse("1.9999d")); - -#if 0 // not implemented - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(90), TDuration::Parse("1m30s")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(90), TDuration::Parse("1h30m")); - UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(36), TDuration::Parse("1d12h")); -#endif - + UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(24), TDuration::Parse("1d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(36), TDuration::Parse("1.5d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(2448), TDuration::Parse("1.7d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(171936), TDuration::Parse("1.99d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(172713600), TDuration::Parse("1.999d")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::MilliSeconds(172791360), TDuration::Parse("1.9999d")); + +#if 0 // not implemented + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(90), TDuration::Parse("1m30s")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Minutes(90), TDuration::Parse("1h30m")); + UNIT_ASSERT_VALUES_EQUAL(TDuration::Hours(36), TDuration::Parse("1d12h")); +#endif + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(10), TDuration::Parse("10s")); UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(10), TDuration::Parse("10.000s")); UNIT_ASSERT_VALUES_EQUAL(TDuration::MicroSeconds(4), TDuration::Parse("0.000004s")); diff --git a/util/draft/ip.h b/util/draft/ip.h index 29e5da2146..eb947cd2cd 100644 --- a/util/draft/ip.h +++ b/util/draft/ip.h @@ -30,10 +30,10 @@ struct TIp6 { bool operator==(const TIp6& rhs) const { return memcmp(Data, rhs.Data, sizeof(Data)) == 0; } - - bool operator<(const TIp6& rhs) const { - return memcmp(Data, rhs.Data, sizeof(Data)) < 0; - } + + bool operator<(const TIp6& rhs) const { + return memcmp(Data, rhs.Data, sizeof(Data)) < 0; + } }; template <> @@ -43,15 +43,15 @@ struct THash<TIp6> { } }; -static inline TIp6 Ip6FromIp4(TIp4 addr) { - TIp6 res; - memset(res.Data, 0, sizeof(res.Data)); +static inline TIp6 Ip6FromIp4(TIp4 addr) { + TIp6 res; + memset(res.Data, 0, sizeof(res.Data)); res.Data[10] = '\xFF'; res.Data[11] = '\xFF'; - memcpy(res.Data + 12, &addr, 4); - return res; -} - + memcpy(res.Data + 12, &addr, 4); + return res; +} + static inline TIp6 Ip6FromString(const char* ipStr) { TIp6 res; @@ -86,11 +86,11 @@ static inline TString Ip6ToString(const TIp6& ip) { return TString(Ip6ToString(ip, buf, sizeof(buf))); } -template <> +template <> inline void Out<TIp6>(IOutputStream& os, const TIp6& a) { - os << Ip6ToString(a); -} - + os << Ip6ToString(a); +} + using TIp4Or6 = std::variant<TIp4, TIp6>; static inline TIp4Or6 Ip4Or6FromString(const char* ipStr) { diff --git a/util/generic/refcount.h b/util/generic/refcount.h index 2f8ce6499a..966e853b77 100644 --- a/util/generic/refcount.h +++ b/util/generic/refcount.h @@ -89,17 +89,17 @@ using TSimpleCounter = TSimpleCounterTemplate<TCheckPolicy>; // Use this one if you do want to share the pointer between threads, omit thread checks and do the synchronization yourself using TExplicitSimpleCounter = TSimpleCounterTemplate<TNoCheckPolicy>; -template <class TCounterCheckPolicy> -struct TCommonLockOps<TSimpleCounterTemplate<TCounterCheckPolicy>> { +template <class TCounterCheckPolicy> +struct TCommonLockOps<TSimpleCounterTemplate<TCounterCheckPolicy>> { static inline void Acquire(TSimpleCounterTemplate<TCounterCheckPolicy>* t) noexcept { - t->Inc(); - } - + t->Inc(); + } + static inline void Release(TSimpleCounterTemplate<TCounterCheckPolicy>* t) noexcept { - t->Dec(); - } -}; - + t->Dec(); + } +}; + class TAtomicCounter { public: inline TAtomicCounter(long initial = 0) noexcept |