From ab71516ca6760fe71bedeb59108e98b75da1c41b Mon Sep 17 00:00:00 2001 From: kulikov Date: Sun, 28 Jun 2026 20:01:43 +0300 Subject: Allow custom socket streams in library/cpp/http/server Prepare to use external coroutine/fiber/etc pool with non-blocking read/writes instead of plain blocking system threads. We already can replace system thread pool with something else, allow to inject different streams around connection socket: - move common part of http connection (http streams and output buffer) directly into it; - replace connection Impl with socket streams provider; - add TClientRequest::CreateHttpConnection factory; - check that we are able to override socket streams in unittest. commit_hash:afe39ce57ee1d10673f4c36a12e01b467d9f77b0 --- library/cpp/http/server/http.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'library/cpp/http/server/http.cpp') diff --git a/library/cpp/http/server/http.cpp b/library/cpp/http/server/http.cpp index 13088f5e442..79a1194c770 100644 --- a/library/cpp/http/server/http.cpp +++ b/library/cpp/http/server/http.cpp @@ -725,6 +725,10 @@ void TClientRequest::ResetConnection() { } } +THolder TClientRequest::CreateHttpConnection(const TSocket& s, size_t outputBufferSize) { + return MakeHolder(s, outputBufferSize); +} + void TClientRequest::Process(void* ThreadSpecificResource) { THolder this_(this); @@ -733,11 +737,7 @@ void TClientRequest::Process(void* ThreadSpecificResource) { try { if (!HttpConn_) { const size_t outputBufferSize = HttpServ()->Options().OutputBufferSize; - if (outputBufferSize) { - HttpConn_.Reset(new THttpServerConn(Socket(), outputBufferSize)); - } else { - HttpConn_.Reset(new THttpServerConn(Socket())); - } + HttpConn_ = CreateHttpConnection(Socket(), outputBufferSize ? outputBufferSize : Socket().MaximumTransferUnit()); auto maxRequestsPerConnection = HttpServ()->Options().MaxRequestsPerConnection; HttpConn_->Output()->EnableKeepAlive(HttpServ()->Options().KeepAliveEnabled && (!maxRequestsPerConnection || Conn_->ReceivedRequests < maxRequestsPerConnection)); -- cgit v1.3