diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:23 +0300 |
commit | 706b83ed7de5a473436620367af31fc0ceecde07 (patch) | |
tree | 103305d30dec77e8f6367753367f59b3cd68f9f1 /library/cpp/http/server | |
parent | 918e8a1574070d0ec733f0b76cfad8f8892ad2e5 (diff) | |
download | ydb-706b83ed7de5a473436620367af31fc0ceecde07.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/http/server')
-rw-r--r-- | library/cpp/http/server/conn.cpp | 12 | ||||
-rw-r--r-- | library/cpp/http/server/conn.h | 12 | ||||
-rw-r--r-- | library/cpp/http/server/http.cpp | 32 | ||||
-rw-r--r-- | library/cpp/http/server/http.h | 16 | ||||
-rw-r--r-- | library/cpp/http/server/http_ut.cpp | 46 | ||||
-rw-r--r-- | library/cpp/http/server/options.cpp | 8 | ||||
-rw-r--r-- | library/cpp/http/server/options.h | 30 | ||||
-rw-r--r-- | library/cpp/http/server/response.cpp | 2 | ||||
-rw-r--r-- | library/cpp/http/server/response.h | 12 |
9 files changed, 85 insertions, 85 deletions
diff --git a/library/cpp/http/server/conn.cpp b/library/cpp/http/server/conn.cpp index 38a76c4c30..4e285874ed 100644 --- a/library/cpp/http/server/conn.cpp +++ b/library/cpp/http/server/conn.cpp @@ -15,14 +15,14 @@ public: { } - inline ~TImpl() { + inline ~TImpl() { } - inline THttpInput* Input() noexcept { + inline THttpInput* Input() noexcept { return &HI_; } - inline THttpOutput* Output() noexcept { + inline THttpOutput* Output() noexcept { return &HO_; } @@ -53,14 +53,14 @@ THttpServerConn::THttpServerConn(const TSocket& s, size_t outputBufferSize) { } -THttpServerConn::~THttpServerConn() { +THttpServerConn::~THttpServerConn() { } -THttpInput* THttpServerConn::Input() noexcept { +THttpInput* THttpServerConn::Input() noexcept { return Impl_->Input(); } -THttpOutput* THttpServerConn::Output() noexcept { +THttpOutput* THttpServerConn::Output() noexcept { return Impl_->Output(); } diff --git a/library/cpp/http/server/conn.h b/library/cpp/http/server/conn.h index 3aa5329af4..44d6f8be28 100644 --- a/library/cpp/http/server/conn.h +++ b/library/cpp/http/server/conn.h @@ -10,22 +10,22 @@ class THttpServerConn { public: explicit THttpServerConn(const TSocket& s); THttpServerConn(const TSocket& s, size_t outputBufferSize); - ~THttpServerConn(); + ~THttpServerConn(); - THttpInput* Input() noexcept; - THttpOutput* Output() noexcept; + THttpInput* Input() noexcept; + THttpOutput* Output() noexcept; - inline const THttpInput* Input() const noexcept { + inline const THttpInput* Input() const noexcept { return const_cast<THttpServerConn*>(this)->Input(); } - inline const THttpOutput* Output() const noexcept { + inline const THttpOutput* Output() const noexcept { return const_cast<THttpServerConn*>(this)->Output(); } /// Проверяет, можно ли установить режим, при котором соединение с сервером /// не завершается после окончания транзакции. - inline bool CanBeKeepAlive() const noexcept { + inline bool CanBeKeepAlive() const noexcept { return Output()->CanBeKeepAlive(); } diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp index 128583bdd7..4a122d1a0a 100644 --- a/library/cpp/http/server/http.cpp +++ b/library/cpp/http/server/http.cpp @@ -31,7 +31,7 @@ using namespace NAddr; namespace { class IPollAble { public: - inline IPollAble() noexcept { + inline IPollAble() noexcept { } virtual ~IPollAble() { @@ -53,7 +53,7 @@ namespace { class TClientConnection: public IPollAble, public TIntrusiveListItem<TClientConnection> { public: TClientConnection(const TSocket& s, THttpServer::TImpl* serv, NAddr::IRemoteAddrRef listenerSockAddrRef); - ~TClientConnection() override; + ~TClientConnection() override; void OnPollEvent(TInstant now) override; @@ -81,10 +81,10 @@ public: { } - inline ~TConnections() { + inline ~TConnections() { } - inline void Add(TClientConnection* c) noexcept { + inline void Add(TClientConnection* c) noexcept { TGuard<TMutex> g(Mutex_); Conns_.PushBack(c); @@ -99,7 +99,7 @@ public: } } - inline void Clear() noexcept { + inline void Clear() noexcept { TGuard<TMutex> g(Mutex_); Conns_.Clear(); @@ -297,7 +297,7 @@ public: { } - ~TListenSocket() override { + ~TListenSocket() override { } void OnPollEvent(TInstant) override { @@ -310,7 +310,7 @@ public: Server_->AddRequestFromSocket(s, TInstant::Now(), SockAddrRef_); } - SOCKET GetSocket() const noexcept { + SOCKET GetSocket() const noexcept { return S_; } @@ -345,7 +345,7 @@ public: ListenerRunningOK = true; ListenStartEvent.Signal(); - TVector<void*> events; + TVector<void*> events; events.resize(1); TInstant now = TInstant::Now(); @@ -422,15 +422,15 @@ public: } } - inline const TOptions& Options() const noexcept { + inline const TOptions& Options() const noexcept { return Options_; } - inline void DecreaseConnections() noexcept { + inline void DecreaseConnections() noexcept { AtomicDecrement(ConnectionCount); } - inline void IncreaseConnections() noexcept { + inline void IncreaseConnections() noexcept { AtomicIncrement(ConnectionCount); } @@ -527,7 +527,7 @@ void THttpServer::RestartRequestThreads(ui32 n, ui32 queue) { Impl_->RestartRequestThreads(n, queue); } -const THttpServer::TOptions& THttpServer::Options() const noexcept { +const THttpServer::TOptions& THttpServer::Options() const noexcept { return Impl_->Options(); } @@ -566,7 +566,7 @@ TClientConnection::TClientConnection(const TSocket& s, THttpServer::TImpl* serv, HttpServ_->IncreaseConnections(); } -TClientConnection::~TClientConnection() { +TClientConnection::~TClientConnection() { HttpServ_->DecreaseConnections(); } @@ -730,7 +730,7 @@ void TClientRequest::ProcessFailRequest(int failstate) { "\r\n" "Service Unavailable\r\n"; - TString url; + TString url; if (!strnicmp(RequestString.data(), "GET ", 4)) { // Trying to extract url... @@ -764,11 +764,11 @@ void TClientRequest::ProcessFailRequest(int failstate) { Output().Flush(); } -THttpServer* TClientRequest::HttpServ() const noexcept { +THttpServer* TClientRequest::HttpServ() const noexcept { return Conn_->HttpServ_->Parent_; } -const TSocket& TClientRequest::Socket() const noexcept { +const TSocket& TClientRequest::Socket() const noexcept { return Conn_->Socket_; } diff --git a/library/cpp/http/server/http.h b/library/cpp/http/server/http.h index b292d38f27..e36a27ca25 100644 --- a/library/cpp/http/server/http.h +++ b/library/cpp/http/server/http.h @@ -23,7 +23,7 @@ public: public: struct TFailLogData { int failstate; - TString url; + TString url; }; virtual ~ICallBack() { @@ -80,7 +80,7 @@ public: int GetErrorCode(); const char* GetError(); void RestartRequestThreads(ui32 nTh, ui32 maxQS); - const TOptions& Options() const noexcept; + const TOptions& Options() const noexcept; i64 GetClientCount() const; class TImpl; @@ -109,16 +109,16 @@ public: TClientRequest(); ~TClientRequest() override; - inline THttpInput& Input() noexcept { + inline THttpInput& Input() noexcept { return *HttpConn_->Input(); } - inline THttpOutput& Output() noexcept { + inline THttpOutput& Output() noexcept { return *HttpConn_->Output(); } - THttpServer* HttpServ() const noexcept; - const TSocket& Socket() const noexcept; + THttpServer* HttpServ() const noexcept; + const TSocket& Socket() const noexcept; NAddr::IRemoteAddrRef GetListenerSockAddrRef() const noexcept; TInstant AcceptMoment() const noexcept; @@ -140,8 +140,8 @@ private: void Process(void* ThreadSpecificResource) override; public: - TVector<std::pair<TString, TString>> ParsedHeaders; - TString RequestString; + TVector<std::pair<TString, TString>> ParsedHeaders; + TString RequestString; private: THolder<TClientConnection> Conn_; diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp index cc62bb988e..f72fde0cc2 100644 --- a/library/cpp/http/server/http_ut.cpp +++ b/library/cpp/http/server/http_ut.cpp @@ -40,7 +40,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { }; public: - inline TEchoServer(const TString& res) + inline TEchoServer(const TString& res) : Res_(res) { } @@ -50,7 +50,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } private: - TString Res_; + TString Res_; }; class TSleepingServer: public THttpServer::ICallBack { @@ -136,7 +136,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { THolder<TAtomicCounter> MaxConns; }; - static const TString CrLf = "\r\n"; + static const TString CrLf = "\r\n"; struct TTestRequest { TTestRequest(ui16 port, TString content = TString()) @@ -148,10 +148,10 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { void CheckContinue(TSocketInput& si) { if (Expect100Continue) { TStringStream ss; - TString firstLine; + TString firstLine; si.ReadLine(firstLine); for (;;) { - TString buf; + TString buf; si.ReadLine(buf); if (buf.size() == 0) { break; @@ -162,7 +162,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } } - TString Execute() { + TString Execute() { TSocket* s = nullptr; THolder<TSocket> singleReqSocket; if (KeepAliveConnection) { @@ -239,7 +239,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { s->Send(r.Data(), r.Size()); CheckContinue(si); Hdr = r.Str(); - TString tosend = compressedContent.Str(); + TString tosend = compressedContent.Str(); s->Send(tosend.data(), tosend.size()); } else { if (isPost) { @@ -264,7 +264,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { return ss.Str(); } - TString GetDescription() const { + TString GetDescription() const { if (UseHttpOutput) { TStringStream ss; ss << (KeepAliveConnection ? "keep-alive " : "") << Type; @@ -279,13 +279,13 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { ui16 Port = 0; bool UseHttpOutput = true; - TString Type = "GET"; - TString ContentEncoding; - TString Content; + TString Type = "GET"; + TString ContentEncoding; + TString Content; bool KeepAliveConnection = false; THolder<TSocket> KeepAlivedSocket; bool EnableResponseEncoding = false; - TString Hdr; + TString Hdr; bool Expect100Continue = false; }; @@ -311,8 +311,8 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } }; - TString TestData(size_t size = 5 * 4096) { - TString res; + TString TestData(size_t size = 5 * 4096) { + TString res; for (size_t i = 0; i < size; ++i) { res += (char)i; @@ -321,7 +321,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } Y_UNIT_TEST(TestEchoServer) { - TString res = TestData(); + TString res = TestData(); TPortManager pm; const ui16 port = pm.GetPort(); const bool trueFalse[] = {true, false}; @@ -345,17 +345,17 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { for (bool enableResponseEncoding : trueFalse) { r.EnableResponseEncoding = enableResponseEncoding; - const TString reqTypes[] = {"GET", "POST"}; - for (const TString& reqType : reqTypes) { + const TString reqTypes[] = {"GET", "POST"}; + for (const TString& reqType : reqTypes) { r.Type = reqType; - const TString encoders[] = {"", "deflate"}; - for (const TString& encoder : encoders) { + const TString encoders[] = {"", "deflate"}; + for (const TString& encoder : encoders) { r.ContentEncoding = encoder; for (bool expect100Continue : trueFalse) { r.Expect100Continue = expect100Continue; - TString resp = r.Execute(); + TString resp = r.Execute(); UNIT_ASSERT_C(resp == res, "diff echo response for request:\n" + r.GetDescription()); } } @@ -377,7 +377,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { const ui16 port = pm.GetPort(); TEchoServer serverImpl(res); - TVector<THolder<THttpServer>> servers; + TVector<THolder<THttpServer>> servers; for (ui32 i = 0; i < 10; i++) { servers.push_back(MakeHolder<THttpServer>(&serverImpl, THttpServer::TOptions(port).EnableReusePort(true))); } @@ -427,7 +427,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { * Emulate request processing failures * Data should be large enough not to fit into socket buffer **/ - TString res = TestData(10 * 1024 * 1024); + TString res = TestData(10 * 1024 * 1024); TPortManager portManager; const ui16 port = portManager.GetPort(); TEchoServer serverImpl(res); @@ -446,7 +446,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { TTestRequest r(port); r.Content = res; r.Type = "POST"; - TString resp = r.Execute(); + TString resp = r.Execute(); if (i == 1) { UNIT_ASSERT(resp.Contains("Service Unavailable")); } else { diff --git a/library/cpp/http/server/options.cpp b/library/cpp/http/server/options.cpp index 05c954384a..e1f85d22c3 100644 --- a/library/cpp/http/server/options.cpp +++ b/library/cpp/http/server/options.cpp @@ -9,11 +9,11 @@ using TAddr = THttpServerOptions::TAddr; -static inline TString AddrToString(const TAddr& addr) { +static inline TString AddrToString(const TAddr& addr) { return addr.Addr + ":" + ToString(addr.Port); } -static inline TNetworkAddress ToNetworkAddr(const TString& address, ui16 port) { +static inline TNetworkAddress ToNetworkAddr(const TString& address, ui16 port) { if (address.empty() || address == TStringBuf("*")) { return TNetworkAddress(port); } @@ -22,14 +22,14 @@ static inline TNetworkAddress ToNetworkAddr(const TString& address, ui16 port) { } void THttpServerOptions::BindAddresses(TBindAddresses& ret) const { - THashSet<TString> check; + THashSet<TString> check; for (auto addr : BindSockaddr) { if (!addr.Port) { addr.Port = Port; } - const TString straddr = AddrToString(addr); + const TString straddr = AddrToString(addr); if (check.find(straddr) == check.end()) { check.insert(straddr); diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h index 38eda0e5e7..3354578db2 100644 --- a/library/cpp/http/server/options.h +++ b/library/cpp/http/server/options.h @@ -4,18 +4,18 @@ #include <util/network/init.h> #include <util/network/address.h> #include <util/generic/size_literals.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/vector.h> #include <util/datetime/base.h> class THttpServerOptions { public: - inline THttpServerOptions(ui16 port = 17000) noexcept + inline THttpServerOptions(ui16 port = 17000) noexcept : Port(port) { } - using TBindAddresses = TVector<TNetworkAddress>; + using TBindAddresses = TVector<TNetworkAddress>; void BindAddresses(TBindAddresses& ret) const; inline THttpServerOptions& AddBindAddress(const TString& address, ui16 port) { @@ -32,13 +32,13 @@ public: return AddBindAddress(address, 0); } - inline THttpServerOptions& EnableKeepAlive(bool enable) noexcept { + inline THttpServerOptions& EnableKeepAlive(bool enable) noexcept { KeepAliveEnabled = enable; return *this; } - inline THttpServerOptions& EnableCompression(bool enable) noexcept { + inline THttpServerOptions& EnableCompression(bool enable) noexcept { CompressionEnabled = enable; return *this; @@ -62,51 +62,51 @@ public: return *this; } - inline THttpServerOptions& SetThreads(ui32 threads) noexcept { + inline THttpServerOptions& SetThreads(ui32 threads) noexcept { nThreads = threads; return *this; } /// Default interface name to bind the server. Used when none of BindAddress are provided. - inline THttpServerOptions& SetHost(const TString& host) noexcept { + inline THttpServerOptions& SetHost(const TString& host) noexcept { Host = host; return *this; } /// Default port to bind the server. Used when none of BindAddress are provided. - inline THttpServerOptions& SetPort(ui16 port) noexcept { + inline THttpServerOptions& SetPort(ui16 port) noexcept { Port = port; return *this; } - inline THttpServerOptions& SetMaxConnections(ui32 mc = 0) noexcept { + inline THttpServerOptions& SetMaxConnections(ui32 mc = 0) noexcept { MaxConnections = mc; return *this; } - inline THttpServerOptions& SetMaxQueueSize(ui32 mqs = 0) noexcept { + inline THttpServerOptions& SetMaxQueueSize(ui32 mqs = 0) noexcept { MaxQueueSize = mqs; return *this; } - inline THttpServerOptions& SetClientTimeout(const TDuration& timeout) noexcept { + inline THttpServerOptions& SetClientTimeout(const TDuration& timeout) noexcept { ClientTimeout = timeout; return *this; } - inline THttpServerOptions& SetListenBacklog(int val) noexcept { + inline THttpServerOptions& SetListenBacklog(int val) noexcept { ListenBacklog = val; return *this; } - inline THttpServerOptions& SetOutputBufferSize(size_t val) noexcept { + inline THttpServerOptions& SetOutputBufferSize(size_t val) noexcept { OutputBufferSize = val; return *this; @@ -140,11 +140,11 @@ public: } struct TAddr { - TString Addr; + TString Addr; ui16 Port; }; - typedef TVector<TAddr> TAddrs; + typedef TVector<TAddr> TAddrs; bool KeepAliveEnabled = true; bool CompressionEnabled = false; diff --git a/library/cpp/http/server/response.cpp b/library/cpp/http/server/response.cpp index 52d64c91ce..64ad7fceb3 100644 --- a/library/cpp/http/server/response.cpp +++ b/library/cpp/http/server/response.cpp @@ -18,7 +18,7 @@ THttpResponse& THttpResponse::SetContentType(const TStringBuf& contentType) { } void THttpResponse::OutTo(IOutputStream& os) const { - TVector<IOutputStream::TPart> parts; + TVector<IOutputStream::TPart> parts; const size_t FIRST_LINE_PARTS = 3; const size_t HEADERS_PARTS = Headers.Count() * 4; const size_t CONTENT_PARTS = 5; diff --git a/library/cpp/http/server/response.h b/library/cpp/http/server/response.h index a75cb85605..a6a92c89d0 100644 --- a/library/cpp/http/server/response.h +++ b/library/cpp/http/server/response.h @@ -11,18 +11,18 @@ class IOutputStream; class THttpResponse { public: - THttpResponse() noexcept + THttpResponse() noexcept : Code(HTTP_OK) { } - explicit THttpResponse(HttpCodes code) noexcept + explicit THttpResponse(HttpCodes code) noexcept : Code(code) { } template <typename ValueType> - THttpResponse& AddHeader(const TString& name, const ValueType& value) { + THttpResponse& AddHeader(const TString& name, const ValueType& value) { return AddHeader(THttpInputHeader(name, ToString(value))); } @@ -45,7 +45,7 @@ public: * "Content-Length" header during output to IOutputStream. * @see IOutputStream& operator << (IOutputStream&, const THttpResponse&) */ - THttpResponse& SetContent(const TString& content) { + THttpResponse& SetContent(const TString& content) { Content = content; return *this; @@ -60,7 +60,7 @@ public: * "Content-Length" header during output to IOutputStream. * @see IOutputStream& operator << (IOutputStream&, const THttpResponse&) */ - THttpResponse& SetContent(const TString& content, const TStringBuf& contentType) { + THttpResponse& SetContent(const TString& content, const TStringBuf& contentType) { return SetContent(content).SetContentType(contentType); } @@ -78,5 +78,5 @@ public: private: HttpCodes Code; THttpHeaders Headers; - TString Content; + TString Content; }; |