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 | 43f5a35593ebc9f6bcea619bb170394ea7ae468e (patch) | |
tree | e98df59de24d2ef7c77baed9f41e4875a2fef972 /library/cpp/http/io | |
parent | bd30392c4cc92487950adc375c07adf52da1d592 (diff) | |
download | ydb-43f5a35593ebc9f6bcea619bb170394ea7ae468e.tar.gz |
Restoring authorship annotation for <mvel@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/http/io')
-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 |
5 files changed, 85 insertions, 85 deletions
diff --git a/library/cpp/http/io/compression_ut.cpp b/library/cpp/http/io/compression_ut.cpp index c7568f4eb3..2f3d131f8c 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 358af13259..6689be684f 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 51e8177676..1ea35df675 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 de9aee8fb7..84f6949db3 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 d28fe909e3..dcfbd79885 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 |