diff options
author | mvel <mvel@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:41 +0300 |
commit | bd30392c4cc92487950adc375c07adf52da1d592 (patch) | |
tree | e8d1a3f19b7fc890bcef6e4cc5de41f1d88c9ac3 /library/cpp/http | |
parent | 5d50718e66d9c037dc587a0211110b7d25a66185 (diff) | |
download | ydb-bd30392c4cc92487950adc375c07adf52da1d592.tar.gz |
Restoring authorship annotation for <mvel@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/http')
-rw-r--r-- | library/cpp/http/fetch/httpheader.h | 4 | ||||
-rw-r--r-- | library/cpp/http/io/compression_ut.cpp | 8 | ||||
-rw-r--r-- | library/cpp/http/io/stream.cpp | 26 | ||||
-rw-r--r-- | library/cpp/http/io/stream_ut.cpp | 124 | ||||
-rw-r--r-- | library/cpp/http/io/ut/ya.make | 6 | ||||
-rw-r--r-- | library/cpp/http/io/ya.make | 6 | ||||
-rw-r--r-- | library/cpp/http/misc/httpreqdata.h | 10 | ||||
-rw-r--r-- | library/cpp/http/misc/httpreqdata_ut.cpp | 38 | ||||
-rw-r--r-- | library/cpp/http/misc/ya.make | 6 | ||||
-rw-r--r-- | library/cpp/http/server/http.cpp | 30 | ||||
-rw-r--r-- | library/cpp/http/server/http.h | 2 | ||||
-rw-r--r-- | library/cpp/http/server/http_ut.cpp | 102 | ||||
-rw-r--r-- | library/cpp/http/server/options.h | 14 | ||||
-rw-r--r-- | library/cpp/http/server/ya.make | 4 |
14 files changed, 190 insertions, 190 deletions
diff --git a/library/cpp/http/fetch/httpheader.h b/library/cpp/http/fetch/httpheader.h index b2810bbd41..f14cabe1c8 100644 --- a/library/cpp/http/fetch/httpheader.h +++ b/library/cpp/http/fetch/httpheader.h @@ -8,8 +8,8 @@ #include <util/system/compat.h> #include <util/generic/string.h> #include <util/generic/ylimits.h> -#include <util/system/maxlen.h> - +#include <util/system/maxlen.h> + #include <ctime> #include <cstdio> #include <cstdlib> diff --git a/library/cpp/http/io/compression_ut.cpp b/library/cpp/http/io/compression_ut.cpp index 2f3d131f8c..c7568f4eb3 100644 --- a/library/cpp/http/io/compression_ut.cpp +++ b/library/cpp/http/io/compression_ut.cpp @@ -9,14 +9,14 @@ Y_UNIT_TEST_SUITE(THttpCompressionTest) { static const TString DATA = "I'm a teapot"; - + Y_UNIT_TEST(TestGetBestCodecs) { UNIT_ASSERT(TCompressionCodecFactory::Instance().GetBestCodecs().size() > 0); } - + Y_UNIT_TEST(TestEncoder) { TStringStream buffer; - + { auto encoder = TCompressionCodecFactory::Instance().FindEncoder("gzip"); UNIT_ASSERT(encoder); @@ -27,7 +27,7 @@ Y_UNIT_TEST_SUITE(THttpCompressionTest) { TZLibDecompress decompressor(&buffer); UNIT_ASSERT_EQUAL(decompressor.ReadAll(), DATA); - } + } Y_UNIT_TEST(TestDecoder) { TStringStream buffer; diff --git a/library/cpp/http/io/stream.cpp b/library/cpp/http/io/stream.cpp index 6689be684f..358af13259 100644 --- a/library/cpp/http/io/stream.cpp +++ b/library/cpp/http/io/stream.cpp @@ -228,15 +228,15 @@ private: } struct TParsedHeaders { - bool Chunked = false; - bool KeepAlive = false; + bool Chunked = false; + bool KeepAlive = false; TStringBuf LZipped; }; struct TTrEnc { inline void operator()(const TStringBuf& s) { if (s == TStringBuf("chunked")) { - p->Chunked = true; + p->Chunked = true; } } @@ -318,9 +318,9 @@ private: HEADERCMP(header, "connection") { // accept header "Connection: Keep-Alive, TE" if (strnicmp(header.Value().data(), "keep-alive", 10) == 0) { - p.KeepAlive = true; + p.KeepAlive = true; } else if (stricmp(header.Value().data(), "close") == 0) { - p.KeepAlive = false; + p.KeepAlive = false; } } [[fallthrough]]; @@ -336,7 +336,7 @@ private: } } - if (p.Chunked) { + if (p.Chunked) { ChunkedInput_ = Streams_.Add(new TChunkedInput(&Buffered_, &Trailers_)); Input_ = ChunkedInput_; } else { @@ -357,7 +357,7 @@ private: Input_ = Streams_.Add((*decoder)(Input_).Release()); } - KeepAlive_ = p.KeepAlive; + KeepAlive_ = p.KeepAlive; } private: @@ -474,7 +474,7 @@ class THttpOutput::TImpl { } private: - size_t Length_ = 0; + size_t Length_ = 0; }; enum TState { @@ -564,7 +564,7 @@ public: inline void Flush() { TFlush f; Streams_.ForEach(f); - Slave_->Flush(); // see SEARCH-1030 + Slave_->Flush(); // see SEARCH-1030 } inline void Finish() { @@ -574,7 +574,7 @@ public: TFinish f; Streams_.ForEach(f); - Slave_->Finish(); // see SEARCH-1030 + Slave_->Finish(); // see SEARCH-1030 Finished_ = true; } @@ -806,10 +806,10 @@ private: } inline void RebuildStream() { - bool keepAlive = false; + bool keepAlive = false; const TCompressionCodecFactory::TEncoderConstructor* encoder = nullptr; bool chunked = false; - bool haveContentLength = false; + bool haveContentLength = false; for (THttpHeaders::TConstIterator h = Headers_.Begin(); h != Headers_.End(); ++h) { const THttpInputHeader& header = *h; @@ -822,7 +822,7 @@ private: } else if (hl == TStringBuf("transfer-encoding")) { chunked = to_lower(header.Value()) == TStringBuf("chunked"); } else if (hl == TStringBuf("content-length")) { - haveContentLength = true; + haveContentLength = true; } } diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp index 1ea35df675..51e8177676 100644 --- a/library/cpp/http/io/stream_ut.cpp +++ b/library/cpp/http/io/stream_ut.cpp @@ -15,84 +15,84 @@ #include <util/stream/null.h> Y_UNIT_TEST_SUITE(THttpStreamTest) { - class TTestHttpServer: public THttpServer::ICallBack { - class TRequest: public THttpClientRequestEx { - public: - inline TRequest(TTestHttpServer* parent) - : Parent_(parent) - { - } - + class TTestHttpServer: public THttpServer::ICallBack { + class TRequest: public THttpClientRequestEx { + public: + inline TRequest(TTestHttpServer* parent) + : Parent_(parent) + { + } + bool Reply(void* /*tsr*/) override { - if (!ProcessHeaders()) { + if (!ProcessHeaders()) { return true; - } + } // Check that function will not hang on Input().ReadAll(); - // "lo" is for "local" - if (RD.ServerName() == "yandex.lo") { - // do redirect + // "lo" is for "local" + if (RD.ServerName() == "yandex.lo") { + // do redirect Output() << "HTTP/1.1 301 Moved permanently\r\n" "Location: http://www.yandex.lo\r\n" "\r\n"; - } else if (RD.ServerName() == "www.yandex.lo") { + } else if (RD.ServerName() == "www.yandex.lo") { Output() << "HTTP/1.1 200 Ok\r\n" "\r\n"; - } else { - Output() << "HTTP/1.1 200 Ok\r\n\r\n"; + } else { + Output() << "HTTP/1.1 200 Ok\r\n\r\n"; if (Buf.Size()) { Output().Write(Buf.AsCharPtr(), Buf.Size()); - } else { - Output() << Parent_->Res_; - } - } - Output().Finish(); - + } else { + Output() << Parent_->Res_; + } + } + Output().Finish(); + Parent_->LastRequestSentSize_ = Output().SentSize(); - return true; - } - - private: - TTestHttpServer* Parent_ = nullptr; - }; - - public: + return true; + } + + private: + TTestHttpServer* Parent_ = nullptr; + }; + + public: inline TTestHttpServer(const TString& res) - : Res_(res) - { - } - + : Res_(res) + { + } + TClientRequest* CreateClient() override { - return new TRequest(this); - } - + return new TRequest(this); + } + size_t LastRequestSentSize() const { return LastRequestSentSize_; } - private: + private: TString Res_; size_t LastRequestSentSize_ = 0; - }; - + }; + Y_UNIT_TEST(TestCodings1) { UNIT_ASSERT(SupportedCodings().size() > 0); } - + Y_UNIT_TEST(TestHttpInput) { TString res = "I'm a teapot"; TPortManager pm; const ui16 port = pm.GetPort(); - - TTestHttpServer serverImpl(res); - THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); - - UNIT_ASSERT(server.Start()); - - TNetworkAddress addr("localhost", port); + + TTestHttpServer serverImpl(res); + THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); + + UNIT_ASSERT(server.Start()); + + TNetworkAddress addr("localhost", port); TSocket s(addr); //TDebugOutput dbg; @@ -109,7 +109,7 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { TString r; r += "GET / HTTP/1.1"; r += "\r\n"; - r += "Host: yandex.lo"; + r += "Host: yandex.lo"; r += "\r\n"; r += "\r\n"; @@ -125,8 +125,8 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { TransferData(&input, &dbg); } - server.Stop(); - } + server.Stop(); + } Y_UNIT_TEST(TestHttpInputDelete) { TString res = "I'm a teapot"; @@ -240,26 +240,26 @@ Y_UNIT_TEST_SUITE(THttpStreamTest) { TString res = "qqqqqq"; TPortManager pm; const ui16 port = pm.GetPort(); - - TTestHttpServer serverImpl(res); - THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); - - UNIT_ASSERT(server.Start()); - - TNetworkAddress addr("localhost", port); - + + TTestHttpServer serverImpl(res); + THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true).EnableCompression(true)); + + UNIT_ASSERT(server.Start()); + + TNetworkAddress addr("localhost", port); + TSocket s(addr); TNullOutput dbg; - SendMinimalHttpRequest(s, "www.yandex.lo", "/"); + SendMinimalHttpRequest(s, "www.yandex.lo", "/"); TSocketInput si(s); THttpInput input(&si); - unsigned httpCode = ParseHttpRetCode(input.FirstLine()); + unsigned httpCode = ParseHttpRetCode(input.FirstLine()); UNIT_ASSERT_VALUES_EQUAL(httpCode, 200u); TransferData(&input, &dbg); - server.Stop(); + server.Stop(); } Y_UNIT_TEST(TestResponseWithBlanks) { diff --git a/library/cpp/http/io/ut/ya.make b/library/cpp/http/io/ut/ya.make index 84f6949db3..de9aee8fb7 100644 --- a/library/cpp/http/io/ut/ya.make +++ b/library/cpp/http/io/ut/ya.make @@ -2,10 +2,10 @@ UNITTEST_FOR(library/cpp/http/io) OWNER(g:util) -PEERDIR( +PEERDIR( library/cpp/http/server -) - +) + SRCS( chunk_ut.cpp compression_ut.cpp diff --git a/library/cpp/http/io/ya.make b/library/cpp/http/io/ya.make index dcfbd79885..d28fe909e3 100644 --- a/library/cpp/http/io/ya.make +++ b/library/cpp/http/io/ya.make @@ -1,9 +1,9 @@ LIBRARY() -OWNER( +OWNER( g:util - mvel -) + mvel +) PEERDIR( library/cpp/blockcodecs diff --git a/library/cpp/http/misc/httpreqdata.h b/library/cpp/http/misc/httpreqdata.h index 16e59c4d78..c8d6e66dc7 100644 --- a/library/cpp/http/misc/httpreqdata.h +++ b/library/cpp/http/misc/httpreqdata.h @@ -10,7 +10,7 @@ #include <util/network/address.h> #include <util/network/socket.h> #include <util/generic/hash.h> -#include <util/system/yassert.h> +#include <util/system/yassert.h> #include <util/generic/string.h> #include <util/datetime/base.h> #include <util/generic/buffer.h> @@ -47,9 +47,9 @@ public: return Search; } - TStringBuf QueryStringBuf() const { - return TStringBuf(Search, SearchLength); - } + TStringBuf QueryStringBuf() const { + return TStringBuf(Search, SearchLength); + } TStringBuf OrigQueryStringBuf() const { return OrigSearch; @@ -93,7 +93,7 @@ private: TString Port; char* Path; char* Search; - size_t SearchLength; // length of Search + size_t SearchLength; // length of Search TStringBuf OrigSearch; THttpHeadersContainer HeadersIn_; mutable char AddrData[INET6_ADDRSTRLEN]; diff --git a/library/cpp/http/misc/httpreqdata_ut.cpp b/library/cpp/http/misc/httpreqdata_ut.cpp index e7f16ef27c..e1d7156656 100644 --- a/library/cpp/http/misc/httpreqdata_ut.cpp +++ b/library/cpp/http/misc/httpreqdata_ut.cpp @@ -1,7 +1,7 @@ -#include "httpreqdata.h" - +#include "httpreqdata.h" + #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(TRequestServerDataTest) { Y_UNIT_TEST(Headers) { TServerRequestData sd; @@ -44,13 +44,13 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { Y_UNIT_TEST(ParseScan) { TServerRequestData rd; - + // Parse parses url without host UNIT_ASSERT(!rd.Parse(" http://yandex.ru/yandsearch?>a=fake&haha=da HTTP 1.1 OK")); - + // This should work UNIT_ASSERT(rd.Parse(" /yandsearch?>a=fake&haha=da HTTP 1.1 OK")); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), ">a=fake&haha=da"); UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), rd.OrigQueryStringBuf()); @@ -58,10 +58,10 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { UNIT_ASSERT(rd.CgiParam.Has("gta", "fake")); UNIT_ASSERT(rd.CgiParam.Has("haha", "da")); UNIT_ASSERT(!rd.CgiParam.Has("no-param")); - + rd.Clear(); } - + Y_UNIT_TEST(Ctor) { const TString qs("gta=fake&haha=da"); TServerRequestData rd(qs.c_str()); @@ -73,14 +73,14 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { UNIT_ASSERT(rd.CgiParam.Has("haha")); UNIT_ASSERT(!rd.CgiParam.Has("no-param")); } - + Y_UNIT_TEST(HashCut) { const TString qs(">a=fake&haha=da"); const TString header = " /yandsearch?" + qs + "#&uberParam=yes&q=? HTTP 1.1 OK"; TServerRequestData rd; rd.Parse(header.c_str()); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), qs); UNIT_ASSERT_STRINGS_EQUAL(rd.OrigQueryStringBuf(), qs); @@ -89,36 +89,36 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { UNIT_ASSERT(rd.CgiParam.Has("haha")); UNIT_ASSERT(!rd.CgiParam.Has("uberParam")); } - + Y_UNIT_TEST(MisplacedHashCut) { TServerRequestData rd; rd.Parse(" /y#ndsearch?>a=fake&haha=da&uberParam=yes&q=? HTTP 1.1 OK"); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), ""); UNIT_ASSERT_STRINGS_EQUAL(rd.OrigQueryStringBuf(), ""); rd.Scan(); UNIT_ASSERT(rd.CgiParam.empty()); } - + Y_UNIT_TEST(CornerCase) { TServerRequestData rd; rd.Parse(" /yandsearch?#"); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), ""); UNIT_ASSERT_STRINGS_EQUAL(rd.OrigQueryStringBuf(), ""); rd.Scan(); UNIT_ASSERT(rd.CgiParam.empty()); } - + Y_UNIT_TEST(AppendQueryString) { const TString qs("gta=fake&haha=da"); TServerRequestData rd(qs.c_str()); - + UNIT_ASSERT(rd.CgiParam.Has("gta", "fake")); UNIT_ASSERT(rd.CgiParam.Has("haha", "da")); - + UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), qs); UNIT_ASSERT_STRINGS_EQUAL(rd.QueryStringBuf(), rd.OrigQueryStringBuf()); @@ -129,7 +129,7 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { UNIT_ASSERT_STRINGS_EQUAL(rd.OrigQueryStringBuf(), qs); rd.Scan(); - + UNIT_ASSERT(rd.CgiParam.Has("gta", "true")); UNIT_ASSERT(rd.CgiParam.Has("gta", "new")); } @@ -151,4 +151,4 @@ Y_UNIT_TEST_SUITE(TRequestServerDataTest) { } } -} // TRequestServerDataTest +} // TRequestServerDataTest diff --git a/library/cpp/http/misc/ya.make b/library/cpp/http/misc/ya.make index fceb3cf79c..298be41adc 100644 --- a/library/cpp/http/misc/ya.make +++ b/library/cpp/http/misc/ya.make @@ -1,9 +1,9 @@ LIBRARY() -OWNER( +OWNER( g:util - mvel -) + mvel +) GENERATE_ENUM_SERIALIZATION(httpcodes.h) diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp index 128583bdd7..6980ccd035 100644 --- a/library/cpp/http/server/http.cpp +++ b/library/cpp/http/server/http.cpp @@ -8,7 +8,7 @@ #include <util/generic/intrlist.h> #include <util/generic/yexception.h> #include <util/network/address.h> -#include <util/network/socket.h> +#include <util/network/socket.h> #include <util/network/poller.h> #include <util/system/atomic.h> #include <util/system/compat.h> // stricmp, strnicmp, strlwr, strupr, stpcpy @@ -64,7 +64,7 @@ public: public: TSocket Socket_; NAddr::IRemoteAddrRef ListenerSockAddrRef_; - THttpServer::TImpl* HttpServ_ = nullptr; + THttpServer::TImpl* HttpServ_ = nullptr; bool Reject_ = false; TInstant LastUsed; TInstant AcceptMoment; @@ -131,7 +131,7 @@ public: public: TMutex Mutex_; TIntrusiveListWithAutoDelete<TClientConnection, TDelete> Conns_; - TSocketPoller* Poller_ = nullptr; + TSocketPoller* Poller_ = nullptr; const THttpServerOptions& Options; }; @@ -184,7 +184,7 @@ public: Poller.Reset(new TSocketPoller()); Connections.Reset(new TConnections(Poller.Get(), Options_)); - // Start the listener thread + // Start the listener thread ListenerRunningOK = false; // throws on error @@ -204,7 +204,7 @@ public: return false; } - // Wait until the thread has completely started and return the success indicator + // Wait until the thread has completely started and return the success indicator ListenStartEvent.Wait(); return ListenerRunningOK; @@ -271,15 +271,15 @@ public: } } } - + size_t GetRequestQueueSize() const { return Requests->Size(); } - + size_t GetFailQueueSize() const { return FailRequests->Size(); } - + const IThreadPool& GetRequestQueue() const { return *Requests; } @@ -316,7 +316,7 @@ public: private: TSocket S_; - TImpl* Server_ = nullptr; + TImpl* Server_ = nullptr; NAddr::IRemoteAddrRef SockAddrRef_; }; @@ -407,7 +407,7 @@ public: } TImpl(THttpServer* parent, ICallBack* cb, const TOptions& options, IThreadFactory* factory) - : TImpl( + : TImpl( parent, cb, MakeThreadPool<TSimpleThreadPool>(factory, options.UseElasticQueues, cb, options.RequestsThreadName), @@ -448,14 +448,14 @@ public: TSystemEvent ListenStartEvent; TMtpQueueRef Requests; TMtpQueueRef FailRequests; - TAtomic ConnectionCount = 0; + TAtomic ConnectionCount = 0; THolder<TSocketPoller> Poller; THolder<TConnections> Connections; - bool ListenerRunningOK = false; + bool ListenerRunningOK = false; int ErrorCode = 0; TOptions Options_; - ICallBack* Cb_ = nullptr; - THttpServer* Parent_ = nullptr; + ICallBack* Cb_ = nullptr; + THttpServer* Parent_ = nullptr; TWakeupPollAble WakeupPollAble; TMutex StopMutex; @@ -630,7 +630,7 @@ bool TClientRequest::Reply(void* /*ThreadSpecificResource*/) { } bool TClientRequest::IsLocal() const { - return HasLocalAddress(Socket()); + return HasLocalAddress(Socket()); } bool TClientRequest::CheckLoopback() { diff --git a/library/cpp/http/server/http.h b/library/cpp/http/server/http.h index b292d38f27..37a3dc6146 100644 --- a/library/cpp/http/server/http.h +++ b/library/cpp/http/server/http.h @@ -73,7 +73,7 @@ public: // shutdown a.s.a.p. void Stop(); - // graceful shutdown with serving all already open connections + // graceful shutdown with serving all already open connections void Shutdown(); void Wait(); diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp index cc62bb988e..64a62cc889 100644 --- a/library/cpp/http/server/http_ut.cpp +++ b/library/cpp/http/server/http_ut.cpp @@ -36,7 +36,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } private: - TEchoServer* Parent_ = nullptr; + TEchoServer* Parent_ = nullptr; }; public: @@ -163,7 +163,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } TString Execute() { - TSocket* s = nullptr; + TSocket* s = nullptr; THolder<TSocket> singleReqSocket; if (KeepAliveConnection) { if (!KeepAlivedSocket) { @@ -277,48 +277,48 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } } - ui16 Port = 0; - bool UseHttpOutput = true; + ui16 Port = 0; + bool UseHttpOutput = true; TString Type = "GET"; TString ContentEncoding; TString Content; - bool KeepAliveConnection = false; + bool KeepAliveConnection = false; THolder<TSocket> KeepAlivedSocket; - bool EnableResponseEncoding = false; + bool EnableResponseEncoding = false; TString Hdr; bool Expect100Continue = false; }; class TFailingMtpQueue: public TSimpleThreadPool { - private: - bool FailOnAdd_ = false; + private: + bool FailOnAdd_ = false; - public: - void SetFailOnAdd(bool fail = true) { - FailOnAdd_ = fail; - } + public: + void SetFailOnAdd(bool fail = true) { + FailOnAdd_ = fail; + } [[nodiscard]] bool Add(IObjectInQueue* pObj) override { - if (FailOnAdd_) { - return false; - } - + if (FailOnAdd_) { + return false; + } + return TSimpleThreadPool::Add(pObj); - } - TFailingMtpQueue() = default; + } + TFailingMtpQueue() = default; TFailingMtpQueue(IThreadFactory* pool) : TSimpleThreadPool(pool) - { - } - }; - + { + } + }; + TString TestData(size_t size = 5 * 4096) { TString res; - for (size_t i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { res += (char)i; } - return res; - } + return res; + } Y_UNIT_TEST(TestEchoServer) { TString res = TestData(); @@ -338,7 +338,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { for (bool keepAlive : trueFalse) { r.KeepAliveConnection = keepAlive; - // THttpOutput use chunked stream, else use Content-Length + // THttpOutput use chunked stream, else use Content-Length for (bool useHttpOutput : trueFalse) { r.UseHttpOutput = useHttpOutput; @@ -367,7 +367,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { server.Stop(); } } - + Y_UNIT_TEST(TestReusePortEnabled) { if (!IsReusePortAvailable()) { return; // skip test @@ -423,38 +423,38 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } Y_UNIT_TEST(TestFailServer) { - /** - * Emulate request processing failures - * Data should be large enough not to fit into socket buffer - **/ + /** + * Emulate request processing failures + * Data should be large enough not to fit into socket buffer + **/ TString res = TestData(10 * 1024 * 1024); TPortManager portManager; const ui16 port = portManager.GetPort(); - TEchoServer serverImpl(res); - THttpServer::TOptions options(port); - options.EnableKeepAlive(true); - options.EnableCompression(true); + TEchoServer serverImpl(res); + THttpServer::TOptions options(port); + options.EnableKeepAlive(true); + options.EnableCompression(true); using TFailingServerMtpQueue = TThreadPoolBinder<TFailingMtpQueue, THttpServer::ICallBack>; THttpServer::TMtpQueueRef mainWorkers = new TFailingServerMtpQueue(&serverImpl, SystemThreadFactory()); THttpServer::TMtpQueueRef failWorkers = new TThreadPool(SystemThreadFactory()); - THttpServer server(&serverImpl, mainWorkers, failWorkers, options); - - UNIT_ASSERT(server.Start()); - for (size_t i = 0; i < 3; ++i) { - // should fail on 2nd request - static_cast<TFailingMtpQueue*>(mainWorkers.Get())->SetFailOnAdd(i == 1); - TTestRequest r(port); - r.Content = res; - r.Type = "POST"; + THttpServer server(&serverImpl, mainWorkers, failWorkers, options); + + UNIT_ASSERT(server.Start()); + for (size_t i = 0; i < 3; ++i) { + // should fail on 2nd request + static_cast<TFailingMtpQueue*>(mainWorkers.Get())->SetFailOnAdd(i == 1); + TTestRequest r(port); + r.Content = res; + r.Type = "POST"; TString resp = r.Execute(); - if (i == 1) { + if (i == 1) { UNIT_ASSERT(resp.Contains("Service Unavailable")); - } else { - UNIT_ASSERT_C(resp == res, "diff echo response for request:\n" + r.GetDescription()); - } - } - server.Stop(); - } + } else { + UNIT_ASSERT_C(resp == res, "diff echo response for request:\n" + r.GetDescription()); + } + } + server.Stop(); + } class TReleaseConnectionServer: public THttpServer::ICallBack { class TRequest: public THttpClientRequestEx { diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h index 38eda0e5e7..6ff69defd7 100644 --- a/library/cpp/http/server/options.h +++ b/library/cpp/http/server/options.h @@ -11,7 +11,7 @@ class THttpServerOptions { public: inline THttpServerOptions(ui16 port = 17000) noexcept - : Port(port) + : Port(port) { } @@ -146,8 +146,8 @@ public: typedef TVector<TAddr> TAddrs; - bool KeepAliveEnabled = true; - bool CompressionEnabled = false; + bool KeepAliveEnabled = true; + bool CompressionEnabled = false; bool RejectExcessConnections = false; bool ReusePort = false; // set SO_REUSEPORT socket option bool ReuseAddress = true; // set SO_REUSEADDR socket option @@ -157,10 +157,10 @@ public: const char* ServerName = "YWS/1.0"; // The Web server name to return in HTTP headers ui32 nThreads = 0; // Thread count for requests processing ui32 MaxQueueSize = 0; // Max allowed request count in queue - ui32 nFThreads = 1; - ui32 MaxFQueueSize = 0; - ui32 MaxConnections = 100; - int ListenBacklog = SOMAXCONN; + ui32 nFThreads = 1; + ui32 MaxFQueueSize = 0; + ui32 MaxConnections = 100; + int ListenBacklog = SOMAXCONN; TDuration ClientTimeout; size_t OutputBufferSize = 0; ui64 MaxInputContentLength = sizeof(size_t) <= 4 ? 2_GB : 64_GB; diff --git a/library/cpp/http/server/ya.make b/library/cpp/http/server/ya.make index bae6f33306..a8cf9f2c0e 100644 --- a/library/cpp/http/server/ya.make +++ b/library/cpp/http/server/ya.make @@ -2,8 +2,8 @@ LIBRARY() OWNER( pg - mvel - kulikov + mvel + kulikov g:base g:middle ) |