diff options
author | andrew-iv <andrew-iv@yandex-team.ru> | 2022-02-10 16:49:36 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:36 +0300 |
commit | cd33f9aa8461f8e2b0b9e68efbb6bc9856197dc9 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 | |
parent | a7c41f2d250ec4075eb32fb0da0fd5c85308c8f0 (diff) | |
download | ydb-cd33f9aa8461f8e2b0b9e68efbb6bc9856197dc9.tar.gz |
Restoring authorship annotation for <andrew-iv@yandex-team.ru>. Commit 2 of 2.
-rw-r--r-- | library/cpp/http/server/http_ex.cpp | 14 | ||||
-rw-r--r-- | library/cpp/http/server/http_ut.cpp | 84 | ||||
-rw-r--r-- | library/cpp/http/server/options.h | 16 | ||||
-rw-r--r-- | library/cpp/string_utils/base64/base64_decode_uneven_ut.cpp | 4 |
4 files changed, 59 insertions, 59 deletions
diff --git a/library/cpp/http/server/http_ex.cpp b/library/cpp/http/server/http_ex.cpp index ec82a3dee6..e07db22bfc 100644 --- a/library/cpp/http/server/http_ex.cpp +++ b/library/cpp/http/server/http_ex.cpp @@ -2,7 +2,7 @@ #include <util/generic/buffer.h> #include <util/generic/cast.h> -#include <util/stream/null.h> +#include <util/stream/null.h> bool THttpClientRequestExtension::Parse(char* req, TBaseServerRequestData& rd) { rd.SetSocket(Socket()); @@ -76,12 +76,12 @@ bool THttpClientRequestExtension::ProcessHeaders(TBaseServerRequestData& rd, TBl } if (!Input().ContentEncoded() && Input().GetContentLength(contentLength)) { - if (contentLength > HttpServ()->Options().MaxInputContentLength) { - Output() << "HTTP/1.1 413 Payload Too Large\r\nContent-Length:0\r\n\r\n"; - Output().Finish(); - return false; - } - + if (contentLength > HttpServ()->Options().MaxInputContentLength) { + Output() << "HTTP/1.1 413 Payload Too Large\r\nContent-Length:0\r\n\r\n"; + Output().Finish(); + return false; + } + TBuffer buf(SafeIntegerCast<size_t>(contentLength)); buf.Resize(Input().Load(buf.Data(), (size_t)contentLength)); postData = TBlob::FromBuffer(buf); diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp index 082a81caa2..cc62bb988e 100644 --- a/library/cpp/http/server/http_ut.cpp +++ b/library/cpp/http/server/http_ut.cpp @@ -574,22 +574,22 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { return input; } - THttpInput SendRequestWithBody(TSocket& socket, ui16 port, TString body) { - TSocketInput si(socket); - TSocketOutput so(socket); - THttpOutput out(&so); - out << "POST / HTTP/1.1" << CrLf; - out << "Host: localhost:" + ToString(port) << CrLf; - out << "Content-Length: " + ToString(body.size()) << CrLf; - out << CrLf; - out << body; - out.Flush(); - - THttpInput input(&si); - input.ReadAll(); - return input; - } - + THttpInput SendRequestWithBody(TSocket& socket, ui16 port, TString body) { + TSocketInput si(socket); + TSocketOutput so(socket); + THttpOutput out(&so); + out << "POST / HTTP/1.1" << CrLf; + out << "Host: localhost:" + ToString(port) << CrLf; + out << "Content-Length: " + ToString(body.size()) << CrLf; + out << CrLf; + out << body; + out.Flush(); + + THttpInput input(&si); + input.ReadAll(); + return input; + } + Y_UNIT_TEST(TTestExpirationTimeout) { TPortManager pm; const ui16 port = pm.GetPort(); @@ -616,32 +616,32 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { server.Stop(); } - Y_UNIT_TEST(TTestContentLengthTooLarge) { - TPortManager pm; - const ui16 port = pm.GetPort(); - - TEchoServer serverImpl("test_data"); - THttpServer::TOptions options(port); - options.nThreads = 1; - options.MaxQueueSize = 0; - options.MaxInputContentLength = 2_KB; - options.MaxConnections = 0; - options.KeepAliveEnabled = false; - options.ExpirationTimeout = TDuration::Seconds(1); - options.PollTimeout = TDuration::MilliSeconds(100); - THttpServer server(&serverImpl, options); - UNIT_ASSERT(server.Start()); - - TSocket socket(TNetworkAddress("localhost", port), TDuration::Seconds(5)); - UNIT_ASSERT_STRING_CONTAINS(SendRequestWithBody(socket, port, TString(1_KB, 'a')).FirstLine(), "HTTP/1.1 200 Ok"); - - TSocket socket2(TNetworkAddress("localhost", port), TDuration::Seconds(5)); - UNIT_ASSERT_STRING_CONTAINS(SendRequestWithBody(socket2, port, TString(10_KB, 'a')).FirstLine(), "HTTP/1.1 413 Payload Too Large"); - - server.Stop(); - } - - + Y_UNIT_TEST(TTestContentLengthTooLarge) { + TPortManager pm; + const ui16 port = pm.GetPort(); + + TEchoServer serverImpl("test_data"); + THttpServer::TOptions options(port); + options.nThreads = 1; + options.MaxQueueSize = 0; + options.MaxInputContentLength = 2_KB; + options.MaxConnections = 0; + options.KeepAliveEnabled = false; + options.ExpirationTimeout = TDuration::Seconds(1); + options.PollTimeout = TDuration::MilliSeconds(100); + THttpServer server(&serverImpl, options); + UNIT_ASSERT(server.Start()); + + TSocket socket(TNetworkAddress("localhost", port), TDuration::Seconds(5)); + UNIT_ASSERT_STRING_CONTAINS(SendRequestWithBody(socket, port, TString(1_KB, 'a')).FirstLine(), "HTTP/1.1 200 Ok"); + + TSocket socket2(TNetworkAddress("localhost", port), TDuration::Seconds(5)); + UNIT_ASSERT_STRING_CONTAINS(SendRequestWithBody(socket2, port, TString(10_KB, 'a')).FirstLine(), "HTTP/1.1 413 Payload Too Large"); + + server.Stop(); + } + + Y_UNIT_TEST(TTestCloseConnectionOnRequestLimit) { TPortManager pm; const ui16 port = pm.GetPort(); diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h index 72591c4f55..38eda0e5e7 100644 --- a/library/cpp/http/server/options.h +++ b/library/cpp/http/server/options.h @@ -3,7 +3,7 @@ #include <util/network/ip.h> #include <util/network/init.h> #include <util/network/address.h> -#include <util/generic/size_literals.h> +#include <util/generic/size_literals.h> #include <util/generic/string.h> #include <util/generic/vector.h> #include <util/datetime/base.h> @@ -112,12 +112,12 @@ public: return *this; } - inline THttpServerOptions& SetMaxInputContentLength(ui64 val) noexcept { - MaxInputContentLength = val; - - return *this; - } - + inline THttpServerOptions& SetMaxInputContentLength(ui64 val) noexcept { + MaxInputContentLength = val; + + return *this; + } + inline THttpServerOptions& SetMaxRequestsPerConnection(size_t val) noexcept { MaxRequestsPerConnection = val; @@ -163,7 +163,7 @@ public: int ListenBacklog = SOMAXCONN; TDuration ClientTimeout; size_t OutputBufferSize = 0; - ui64 MaxInputContentLength = sizeof(size_t) <= 4 ? 2_GB : 64_GB; + ui64 MaxInputContentLength = sizeof(size_t) <= 4 ? 2_GB : 64_GB; size_t MaxRequestsPerConnection = 0; // If keep-alive is enabled, request limit before connection is closed bool UseElasticQueues = false; diff --git a/library/cpp/string_utils/base64/base64_decode_uneven_ut.cpp b/library/cpp/string_utils/base64/base64_decode_uneven_ut.cpp index 62689c37f8..c3ed068a37 100644 --- a/library/cpp/string_utils/base64/base64_decode_uneven_ut.cpp +++ b/library/cpp/string_utils/base64/base64_decode_uneven_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/unittest/registar.h> - + #include <library/cpp/string_utils/base64/base64.h> Y_UNIT_TEST_SUITE(TBase64DecodeUneven) { @@ -16,7 +16,7 @@ Y_UNIT_TEST_SUITE(TBase64DecodeUneven) { "c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0" "aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdl" "LCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4="; - + UNIT_ASSERT_VALUES_EQUAL(encoded, Base64Encode(wikipedia_slogan)); UNIT_ASSERT_VALUES_EQUAL(wikipedia_slogan, Base64DecodeUneven(encoded)); |