diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-04-16 09:11:59 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-04-16 09:11:59 +0000 |
commit | 25de1d521ca218e2b040739fea77a39e9fc543e9 (patch) | |
tree | 21521d8866cf1462dbd52c071cf369974c29650e /library/cpp/http | |
parent | bf444b8ed4d0f6bf17fd753e2cf88f9440012e87 (diff) | |
parent | 0a63d9ddc516f206f2b8745ce5e5dfa60190d755 (diff) | |
download | ydb-25de1d521ca218e2b040739fea77a39e9fc543e9.tar.gz |
Merge branch 'rightlib' into mergelibs-240416-0910
Diffstat (limited to 'library/cpp/http')
-rw-r--r-- | library/cpp/http/io/compression.h | 1 | ||||
-rw-r--r-- | library/cpp/http/io/headers.cpp | 7 | ||||
-rw-r--r-- | library/cpp/http/io/headers.h | 9 | ||||
-rw-r--r-- | library/cpp/http/io/headers_ut.cpp | 22 | ||||
-rw-r--r-- | library/cpp/http/server/options.cpp | 16 | ||||
-rw-r--r-- | library/cpp/http/server/options.h | 4 | ||||
-rw-r--r-- | library/cpp/http/server/response.cpp | 1 |
7 files changed, 58 insertions, 2 deletions
diff --git a/library/cpp/http/io/compression.h b/library/cpp/http/io/compression.h index f16c4a18eb..038ac47629 100644 --- a/library/cpp/http/io/compression.h +++ b/library/cpp/http/io/compression.h @@ -4,6 +4,7 @@ #include <util/generic/deque.h> #include <util/generic/hash.h> +#include <util/generic/vector.h> class TCompressionCodecFactory { public: diff --git a/library/cpp/http/io/headers.cpp b/library/cpp/http/io/headers.cpp index f2baf64021..3f3a5a2d07 100644 --- a/library/cpp/http/io/headers.cpp +++ b/library/cpp/http/io/headers.cpp @@ -66,6 +66,13 @@ THttpHeaders::THttpHeaders(IInputStream* stream) { } } +THttpHeaders::THttpHeaders(TArrayRef<const THttpInputHeader> headers) { + for (const auto& header : headers) { + AddHeader(header); + } +} + + bool THttpHeaders::HasHeader(const TStringBuf header) const { return FindHeader(header); } diff --git a/library/cpp/http/io/headers.h b/library/cpp/http/io/headers.h index cfb4a9c054..3ae40683e2 100644 --- a/library/cpp/http/io/headers.h +++ b/library/cpp/http/io/headers.h @@ -1,9 +1,10 @@ #pragma once +#include <util/generic/array_ref.h> +#include <util/generic/deque.h> #include <util/generic/string.h> #include <util/generic/strbuf.h> -#include <util/generic/deque.h> -#include <util/generic/vector.h> +#include <util/generic/vector.h> // XXX unused - remove after fixing transitive includes. #include <util/string/cast.h> class IInputStream; @@ -65,6 +66,10 @@ public: /// Добавляет каждую строку из потока в контейнер, считая ее правильным заголовком. THttpHeaders(IInputStream* stream); + /// Создаёт контейнер из initializer-list'а или массива/вектора хедеров. + /// Пример: `THttpHeaders headers({{"Host", "example.com"}});` + THttpHeaders(TArrayRef<const THttpInputHeader> headers); + /// Стандартный итератор. inline TConstIterator Begin() const noexcept { return Headers_.begin(); diff --git a/library/cpp/http/io/headers_ut.cpp b/library/cpp/http/io/headers_ut.cpp index 1d23ef8fdc..6205efb154 100644 --- a/library/cpp/http/io/headers_ut.cpp +++ b/library/cpp/http/io/headers_ut.cpp @@ -44,6 +44,7 @@ bool operator==(const THttpHeaders& lhs, const THeadersExistence& rhs) { class THttpHeadersTest: public TTestBase { UNIT_TEST_SUITE(THttpHeadersTest); + UNIT_TEST(TestConstructorFromArrayRef); UNIT_TEST(TestAddOperation1Arg); UNIT_TEST(TestAddOperation2Args); UNIT_TEST(TestAddOrReplaceOperation1Arg); @@ -57,6 +58,7 @@ private: typedef void (*TAddOrReplaceHeaderFunction)(THttpHeaders&, TStringBuf name, TStringBuf value); public: + void TestConstructorFromArrayRef(); void TestAddOperation1Arg(); void TestAddOperation2Args(); void TestAddOrReplaceOperation1Arg(); @@ -87,6 +89,26 @@ private: UNIT_TEST_SUITE_REGISTRATION(THttpHeadersTest); +void THttpHeadersTest::TestConstructorFromArrayRef() { + THeadersExistence expected; + expected.Add("h1", "v1"); + expected.Add("h2", "v2"); + + // Construct from vector + TVector<THttpInputHeader> headerVec{ + {"h1", "v1"}, + {"h2", "v2"} + }; + THttpHeaders h1(headerVec); + UNIT_ASSERT(expected == h1); + + // Construct from initializer list + THttpHeaders h2({ + {"h1", "v1"}, + {"h2", "v2"} + }); + UNIT_ASSERT(expected == h2); +} void THttpHeadersTest::TestAddOperation1Arg() { DoTestAddOperation(AddHeaderImpl1Arg); } diff --git a/library/cpp/http/server/options.cpp b/library/cpp/http/server/options.cpp index 05c954384a..5f10c42b8a 100644 --- a/library/cpp/http/server/options.cpp +++ b/library/cpp/http/server/options.cpp @@ -1,5 +1,6 @@ #include "options.h" +#include <util/stream/output.h> #include <util/string/cast.h> #include <util/digest/numeric.h> #include <util/network/ip.h> @@ -41,3 +42,18 @@ void THttpServerOptions::BindAddresses(TBindAddresses& ret) const { ret.push_back(Host ? TNetworkAddress(Host, Port) : TNetworkAddress(Port)); } } + +void THttpServerOptions::DebugPrint(IOutputStream& stream) const noexcept { + stream << "Port: " << Port << "\n"; + stream << "Host: " << Host << "\n"; + stream << "KeepAliveEnabled: " << KeepAliveEnabled << "\n"; + stream << "CompressionEnabled: " << CompressionEnabled << "\n"; + stream << "nThreads: " << nThreads << "\n"; + stream << "nListenerThreads: " << nListenerThreads << "\n"; + stream << "MaxQueueSize: " << MaxQueueSize << "\n"; + stream << "nFThreads: " << nFThreads << "\n"; + stream << "MaxFQueueSize: " << MaxFQueueSize << "\n"; + stream << "MaxConnections: " << MaxConnections << "\n"; + stream << "MaxRequestsPerConnection: " << MaxRequestsPerConnection << "\n"; + stream << "ClientTimeout(ms): " << ClientTimeout.MilliSeconds() << "\n"; +} diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h index cacd7ebeda..f03bd5250e 100644 --- a/library/cpp/http/server/options.h +++ b/library/cpp/http/server/options.h @@ -8,6 +8,8 @@ #include <util/generic/vector.h> #include <util/datetime/base.h> +class IOutputStream; + class THttpServerOptions { public: inline THttpServerOptions(ui16 port = 17000) noexcept @@ -151,6 +153,8 @@ public: return *this; } + void DebugPrint(IOutputStream& stream) const noexcept; + struct TAddr { TString Addr; ui16 Port; diff --git a/library/cpp/http/server/response.cpp b/library/cpp/http/server/response.cpp index 52d64c91ce..ff4d3e07f3 100644 --- a/library/cpp/http/server/response.cpp +++ b/library/cpp/http/server/response.cpp @@ -1,5 +1,6 @@ #include "response.h" +#include <util/generic/vector.h> #include <util/stream/output.h> #include <util/stream/mem.h> #include <util/string/cast.h> |