aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/http/server
diff options
context:
space:
mode:
authorkulikov <kulikov@yandex-team.ru>2022-02-10 16:49:34 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:34 +0300
commitc707901605d7b7c6cba0998cd52e1ae619c97762 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/http/server
parent65e5266709e7ff94b14ae128309e229de714b0df (diff)
downloadydb-c707901605d7b7c6cba0998cd52e1ae619c97762.tar.gz
Restoring authorship annotation for <kulikov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/http/server')
-rw-r--r--library/cpp/http/server/conn.cpp16
-rw-r--r--library/cpp/http/server/http.cpp36
-rw-r--r--library/cpp/http/server/http_ut.cpp90
-rw-r--r--library/cpp/http/server/options.h18
-rw-r--r--library/cpp/http/server/response.h8
-rw-r--r--library/cpp/http/server/response_ut.cpp38
6 files changed, 103 insertions, 103 deletions
diff --git a/library/cpp/http/server/conn.cpp b/library/cpp/http/server/conn.cpp
index 37f82f9f7b..38a76c4c30 100644
--- a/library/cpp/http/server/conn.cpp
+++ b/library/cpp/http/server/conn.cpp
@@ -5,11 +5,11 @@
class THttpServerConn::TImpl {
public:
- inline TImpl(const TSocket& s, size_t outputBufferSize)
+ inline TImpl(const TSocket& s, size_t outputBufferSize)
: S_(s)
, SI_(S_)
, SO_(S_)
- , BO_(&SO_, outputBufferSize)
+ , BO_(&SO_, outputBufferSize)
, HI_(&SI_)
, HO_(&BO_, &HI_)
{
@@ -44,15 +44,15 @@ private:
};
THttpServerConn::THttpServerConn(const TSocket& s)
- : THttpServerConn(s, s.MaximumTransferUnit())
+ : THttpServerConn(s, s.MaximumTransferUnit())
+{
+}
+
+THttpServerConn::THttpServerConn(const TSocket& s, size_t outputBufferSize)
+ : Impl_(new TImpl(s, outputBufferSize))
{
}
-THttpServerConn::THttpServerConn(const TSocket& s, size_t outputBufferSize)
- : Impl_(new TImpl(s, outputBufferSize))
-{
-}
-
THttpServerConn::~THttpServerConn() {
}
diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp
index 3d21108b02..128583bdd7 100644
--- a/library/cpp/http/server/http.cpp
+++ b/library/cpp/http/server/http.cpp
@@ -1,5 +1,5 @@
#include "http.h"
-#include "http_ex.h"
+#include "http_ex.h"
#include <library/cpp/threading/equeue/equeue.h>
@@ -243,17 +243,17 @@ public:
}
void AddRequest(TAutoPtr<TClientRequest> req, bool fail) {
- struct TFailRequest: public THttpClientRequestEx {
+ struct TFailRequest: public THttpClientRequestEx {
inline TFailRequest(TAutoPtr<TClientRequest> parent) {
Conn_.Reset(parent->Conn_.Release());
HttpConn_.Reset(parent->HttpConn_.Release());
}
bool Reply(void*) override {
- if (!ProcessHeaders()) {
+ if (!ProcessHeaders()) {
return true;
- }
-
+ }
+
ProcessFailRequest(0);
return true;
}
@@ -558,11 +558,11 @@ TClientConnection::TClientConnection(const TSocket& s, THttpServer::TImpl* serv,
{
SetNoDelay(Socket_, true);
- const TDuration& clientTimeout = HttpServ_->Options().ClientTimeout;
- if (clientTimeout != TDuration::Zero()) {
+ const TDuration& clientTimeout = HttpServ_->Options().ClientTimeout;
+ if (clientTimeout != TDuration::Zero()) {
SetSocketTimeout(Socket_, (long)clientTimeout.Seconds(), clientTimeout.MilliSecondsOfSecond());
- }
-
+ }
+
HttpServ_->IncreaseConnections();
}
@@ -679,16 +679,16 @@ void TClientRequest::ResetConnection() {
void TClientRequest::Process(void* ThreadSpecificResource) {
THolder<TClientRequest> this_(this);
- auto* serverImpl = Conn_->HttpServ_;
-
+ auto* serverImpl = Conn_->HttpServ_;
+
try {
if (!HttpConn_) {
- const size_t outputBufferSize = HttpServ()->Options().OutputBufferSize;
- if (outputBufferSize) {
- HttpConn_.Reset(new THttpServerConn(Socket(), outputBufferSize));
- } else {
- HttpConn_.Reset(new THttpServerConn(Socket()));
- }
+ const size_t outputBufferSize = HttpServ()->Options().OutputBufferSize;
+ if (outputBufferSize) {
+ HttpConn_.Reset(new THttpServerConn(Socket(), outputBufferSize));
+ } else {
+ HttpConn_.Reset(new THttpServerConn(Socket()));
+ }
auto maxRequestsPerConnection = HttpServ()->Options().MaxRequestsPerConnection;
HttpConn_->Output()->EnableKeepAlive(HttpServ()->Options().KeepAliveEnabled && (!maxRequestsPerConnection || Conn_->ReceivedRequests < maxRequestsPerConnection));
@@ -715,7 +715,7 @@ void TClientRequest::Process(void* ThreadSpecificResource) {
return;
}
} catch (...) {
- serverImpl->Cb_->OnException();
+ serverImpl->Cb_->OnException();
throw;
}
diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp
index 42580906f6..cc62bb988e 100644
--- a/library/cpp/http/server/http_ut.cpp
+++ b/library/cpp/http/server/http_ut.cpp
@@ -456,31 +456,31 @@ Y_UNIT_TEST_SUITE(THttpServerTest) {
server.Stop();
}
- class TReleaseConnectionServer: public THttpServer::ICallBack {
- class TRequest: public THttpClientRequestEx {
- public:
- bool Reply(void* /*tsr*/) override {
- Output() << "HTTP/1.1 200 Ok\r\n\r\n";
- Output() << "reply";
- Output().Finish();
-
- ReleaseConnection();
-
- throw yexception() << "some error";
-
- return true;
- }
- };
-
- public:
- TClientRequest* CreateClient() override {
- return new TRequest();
- }
-
- void OnException() override {
- ExceptionMessage = CurrentExceptionMessage();
- }
-
+ class TReleaseConnectionServer: public THttpServer::ICallBack {
+ class TRequest: public THttpClientRequestEx {
+ public:
+ bool Reply(void* /*tsr*/) override {
+ Output() << "HTTP/1.1 200 Ok\r\n\r\n";
+ Output() << "reply";
+ Output().Finish();
+
+ ReleaseConnection();
+
+ throw yexception() << "some error";
+
+ return true;
+ }
+ };
+
+ public:
+ TClientRequest* CreateClient() override {
+ return new TRequest();
+ }
+
+ void OnException() override {
+ ExceptionMessage = CurrentExceptionMessage();
+ }
+
TString ExceptionMessage;
};
@@ -495,7 +495,7 @@ Y_UNIT_TEST_SUITE(THttpServerTest) {
}
};
- public:
+ public:
TClientRequest* CreateClient() override {
return new TRequest();
}
@@ -504,9 +504,9 @@ Y_UNIT_TEST_SUITE(THttpServerTest) {
ExceptionMessage = CurrentExceptionMessage();
}
- TString ExceptionMessage;
- };
-
+ TString ExceptionMessage;
+ };
+
class TListenerSockAddrReplyServer: public THttpServer::ICallBack {
class TRequest: public TClientRequest {
public:
@@ -542,22 +542,22 @@ Y_UNIT_TEST_SUITE(THttpServerTest) {
};
Y_UNIT_TEST(TTestReleaseConnection) {
- TPortManager pm;
- const ui16 port = pm.GetPort();
-
- TReleaseConnectionServer serverImpl;
- THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true));
- UNIT_ASSERT(server.Start());
-
- TTestRequest r(port, "request");
- r.KeepAliveConnection = true;
-
- UNIT_ASSERT_C(r.Execute() == "reply", "diff echo response for request:\n" + r.GetDescription());
-
- server.Stop();
-
- UNIT_ASSERT_STRINGS_EQUAL(serverImpl.ExceptionMessage, "(yexception) some error");
- };
+ TPortManager pm;
+ const ui16 port = pm.GetPort();
+
+ TReleaseConnectionServer serverImpl;
+ THttpServer server(&serverImpl, THttpServer::TOptions(port).EnableKeepAlive(true));
+ UNIT_ASSERT(server.Start());
+
+ TTestRequest r(port, "request");
+ r.KeepAliveConnection = true;
+
+ UNIT_ASSERT_C(r.Execute() == "reply", "diff echo response for request:\n" + r.GetDescription());
+
+ server.Stop();
+
+ UNIT_ASSERT_STRINGS_EQUAL(serverImpl.ExceptionMessage, "(yexception) some error");
+ };
THttpInput SendRequest(TSocket& socket, ui16 port) {
TSocketInput si(socket);
diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h
index 602649e430..38eda0e5e7 100644
--- a/library/cpp/http/server/options.h
+++ b/library/cpp/http/server/options.h
@@ -6,7 +6,7 @@
#include <util/generic/size_literals.h>
#include <util/generic/string.h>
#include <util/generic/vector.h>
-#include <util/datetime/base.h>
+#include <util/datetime/base.h>
class THttpServerOptions {
public:
@@ -93,10 +93,10 @@ public:
return *this;
}
-
+
inline THttpServerOptions& SetClientTimeout(const TDuration& timeout) noexcept {
ClientTimeout = timeout;
-
+
return *this;
}
@@ -107,11 +107,11 @@ public:
}
inline THttpServerOptions& SetOutputBufferSize(size_t val) noexcept {
- OutputBufferSize = val;
-
- return *this;
- }
-
+ OutputBufferSize = val;
+
+ return *this;
+ }
+
inline THttpServerOptions& SetMaxInputContentLength(ui64 val) noexcept {
MaxInputContentLength = val;
@@ -162,7 +162,7 @@ public:
ui32 MaxConnections = 100;
int ListenBacklog = SOMAXCONN;
TDuration ClientTimeout;
- size_t OutputBufferSize = 0;
+ 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
bool UseElasticQueues = false;
diff --git a/library/cpp/http/server/response.h b/library/cpp/http/server/response.h
index eed4afc7b6..a75cb85605 100644
--- a/library/cpp/http/server/response.h
+++ b/library/cpp/http/server/response.h
@@ -34,10 +34,10 @@ public:
THttpResponse& AddMultipleHeaders(const THttpHeaders& headers);
- const THttpHeaders& GetHeaders() const {
- return Headers;
- }
-
+ const THttpHeaders& GetHeaders() const {
+ return Headers;
+ }
+
THttpResponse& SetContentType(const TStringBuf& contentType);
/**
diff --git a/library/cpp/http/server/response_ut.cpp b/library/cpp/http/server/response_ut.cpp
index 8a142fb1ba..73e2112ad3 100644
--- a/library/cpp/http/server/response_ut.cpp
+++ b/library/cpp/http/server/response_ut.cpp
@@ -46,25 +46,25 @@ Y_UNIT_TEST_SUITE(TestHttpResponse) {
EXPECTED);
}
- Y_UNIT_TEST(TestGetHeaders) {
- THttpResponse resp(HTTP_FORBIDDEN);
-
- THttpHeaders headers;
- headers.AddHeader(THttpInputHeader("X-Header-1", "ValueOne"));
- headers.AddHeader(THttpInputHeader("X-Header-2", "ValueTwo"));
- headers.AddHeader(THttpInputHeader("X-Header-3", "ValueThree"));
- resp.AddMultipleHeaders(headers);
- resp.AddHeader("X-Header-4", "ValueFour");
-
- const THttpHeaders& gotHeaders = resp.GetHeaders();
- UNIT_ASSERT_VALUES_EQUAL(gotHeaders.Count(), 4);
- UNIT_ASSERT(gotHeaders.HasHeader("X-Header-1"));
- UNIT_ASSERT_STRINGS_EQUAL(gotHeaders.FindHeader("X-Header-1")->Value(), "ValueOne");
- UNIT_ASSERT(gotHeaders.HasHeader("X-Header-4"));
- UNIT_ASSERT_STRINGS_EQUAL(gotHeaders.FindHeader("X-Header-4")->Value(), "ValueFour");
- }
-
-
+ Y_UNIT_TEST(TestGetHeaders) {
+ THttpResponse resp(HTTP_FORBIDDEN);
+
+ THttpHeaders headers;
+ headers.AddHeader(THttpInputHeader("X-Header-1", "ValueOne"));
+ headers.AddHeader(THttpInputHeader("X-Header-2", "ValueTwo"));
+ headers.AddHeader(THttpInputHeader("X-Header-3", "ValueThree"));
+ resp.AddMultipleHeaders(headers);
+ resp.AddHeader("X-Header-4", "ValueFour");
+
+ const THttpHeaders& gotHeaders = resp.GetHeaders();
+ UNIT_ASSERT_VALUES_EQUAL(gotHeaders.Count(), 4);
+ UNIT_ASSERT(gotHeaders.HasHeader("X-Header-1"));
+ UNIT_ASSERT_STRINGS_EQUAL(gotHeaders.FindHeader("X-Header-1")->Value(), "ValueOne");
+ UNIT_ASSERT(gotHeaders.HasHeader("X-Header-4"));
+ UNIT_ASSERT_STRINGS_EQUAL(gotHeaders.FindHeader("X-Header-4")->Value(), "ValueFour");
+ }
+
+
Y_UNIT_TEST(TestSetContent) {
const char* EXPECTED = "HTTP/1.1 200 Ok\r\n"
"Content-Length: 10\r\n"