diff options
author | cherenkov-p-a <cherenkov-p-a@yandex-team.ru> | 2022-02-10 16:49:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:39 +0300 |
commit | 9011d1fa16370ec024d20180d440f7ae6fd0e1c8 (patch) | |
tree | cd688a9e90e30e02212a6ecaf664209db01c4c36 /library/cpp/http/server | |
parent | 9700ce2289436b557831d64eb47682c8c2a30ee2 (diff) | |
download | ydb-9011d1fa16370ec024d20180d440f7ae6fd0e1c8.tar.gz |
Restoring authorship annotation for <cherenkov-p-a@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/http/server')
-rw-r--r-- | library/cpp/http/server/http.cpp | 8 | ||||
-rw-r--r-- | library/cpp/http/server/http_ut.cpp | 40 | ||||
-rw-r--r-- | library/cpp/http/server/options.h | 14 |
3 files changed, 31 insertions, 31 deletions
diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp index 128583bdd7..12bf48a354 100644 --- a/library/cpp/http/server/http.cpp +++ b/library/cpp/http/server/http.cpp @@ -68,7 +68,7 @@ public: bool Reject_ = false; TInstant LastUsed; TInstant AcceptMoment; - size_t ReceivedRequests = 0; + size_t ReceivedRequests = 0; }; class THttpServer::TImpl { @@ -597,7 +597,7 @@ void TClientConnection::OnPollEvent(TInstant now) { void TClientConnection::Activate(TInstant now) noexcept { HttpServ_->Connections->Erase(this, now); LastUsed = now; - ++ReceivedRequests; + ++ReceivedRequests; } void TClientConnection::DeActivate() { @@ -690,8 +690,8 @@ void TClientRequest::Process(void* ThreadSpecificResource) { HttpConn_.Reset(new THttpServerConn(Socket())); } - auto maxRequestsPerConnection = HttpServ()->Options().MaxRequestsPerConnection; - HttpConn_->Output()->EnableKeepAlive(HttpServ()->Options().KeepAliveEnabled && (!maxRequestsPerConnection || Conn_->ReceivedRequests < maxRequestsPerConnection)); + auto maxRequestsPerConnection = HttpServ()->Options().MaxRequestsPerConnection; + HttpConn_->Output()->EnableKeepAlive(HttpServ()->Options().KeepAliveEnabled && (!maxRequestsPerConnection || Conn_->ReceivedRequests < maxRequestsPerConnection)); HttpConn_->Output()->EnableCompression(HttpServ()->Options().CompressionEnabled); } diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp index cc62bb988e..3216aab0ad 100644 --- a/library/cpp/http/server/http_ut.cpp +++ b/library/cpp/http/server/http_ut.cpp @@ -559,7 +559,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { UNIT_ASSERT_STRINGS_EQUAL(serverImpl.ExceptionMessage, "(yexception) some error"); }; - THttpInput SendRequest(TSocket& socket, ui16 port) { + THttpInput SendRequest(TSocket& socket, ui16 port) { TSocketInput si(socket); TSocketOutput so(socket); THttpOutput out(&so); @@ -571,7 +571,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { THttpInput input(&si); input.ReadAll(); - return input; + return input; } THttpInput SendRequestWithBody(TSocket& socket, ui16 port, TString body) { @@ -642,24 +642,24 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } - Y_UNIT_TEST(TTestCloseConnectionOnRequestLimit) { - TPortManager pm; - const ui16 port = pm.GetPort(); - - TEchoServer serverImpl("test_data"); - THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).SetMaxRequestsPerConnection(2)); - UNIT_ASSERT(server.Start()); - - TSocket socket(TNetworkAddress("localhost", port), TDuration::Seconds(10)); - - UNIT_ASSERT(SendRequest(socket, port).IsKeepAlive()); - UNIT_ASSERT(!SendRequest(socket, port).IsKeepAlive()); - - UNIT_ASSERT_EXCEPTION(SendRequest(socket, port), THttpReadException); - - server.Stop(); - } - + Y_UNIT_TEST(TTestCloseConnectionOnRequestLimit) { + TPortManager pm; + const ui16 port = pm.GetPort(); + + TEchoServer serverImpl("test_data"); + THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).SetMaxRequestsPerConnection(2)); + UNIT_ASSERT(server.Start()); + + TSocket socket(TNetworkAddress("localhost", port), TDuration::Seconds(10)); + + UNIT_ASSERT(SendRequest(socket, port).IsKeepAlive()); + UNIT_ASSERT(!SendRequest(socket, port).IsKeepAlive()); + + UNIT_ASSERT_EXCEPTION(SendRequest(socket, port), THttpReadException); + + server.Stop(); + } + Y_UNIT_TEST(TTestListenerSockAddrConnection) { TPortManager pm; const ui16 port1 = pm.GetPort(); diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h index 38eda0e5e7..864f7c09e5 100644 --- a/library/cpp/http/server/options.h +++ b/library/cpp/http/server/options.h @@ -118,12 +118,12 @@ public: return *this; } - inline THttpServerOptions& SetMaxRequestsPerConnection(size_t val) noexcept { - MaxRequestsPerConnection = val; - - return *this; - } - + inline THttpServerOptions& SetMaxRequestsPerConnection(size_t val) noexcept { + MaxRequestsPerConnection = val; + + return *this; + } + /// Use TElasticQueue instead of TThreadPool for request queues inline THttpServerOptions& EnableElasticQueues(bool enable) noexcept { UseElasticQueues = enable; @@ -164,7 +164,7 @@ public: TDuration ClientTimeout; size_t OutputBufferSize = 0; 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 + size_t MaxRequestsPerConnection = 0; // If keep-alive is enabled, request limit before connection is closed bool UseElasticQueues = false; TDuration PollTimeout; // timeout of TSocketPoller::WaitT call |