Skip to content

Commit de995c1

Browse files
authored
chore: http clean-up (#289)
Made http client pool compilable. Signed-off-by: Roman Gershman <roman@dragonflydb.io>
1 parent deb4c1a commit de995c1

10 files changed

+60
-714
lines changed

util/http/CMakeLists.txt

+1-13
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,7 @@ cxx_link(http_server_lib absl::strings absl::time base http_beast_prebuilt http_
1010

1111
add_executable(http_main http_main.cc)
1212

13-
add_library(http_client_lib http_client.cc)
13+
add_library(http_client_lib http_client.cc https_client_pool.cc)
1414

1515
cxx_link(http_client_lib fibers2 http_beast_prebuilt http_utils tls_lib)
1616
cxx_link(http_main fibers2 html_lib http_server_lib TRDP::mimalloc)
17-
18-
19-
#add_library(https_client_lib https_client.cc https_client_pool.cc ssl_stream.cc)
20-
#cxx_link(https_client_lib proactor_lib absl_variant http_beast_prebuilt)
21-
22-
# TODO: to fix it
23-
# cxx_test(ssl_stream_test https_client_lib LABELS CI)
24-
25-
# add_library(http_test_lib http_testing.cc)
26-
# cxx_link(http_test_lib http_v2 gaia_gtest_main TRDP::rapidjson)
27-
28-
# cxx_test(http_test http_v2 http_client_lib http_test_lib LABELS CI)

util/http/beast_rj_utils.h

-127
This file was deleted.

util/http/http_client.h

+14-5
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,26 @@ class Client {
7474
on_connect_cb_ = std::move(cb);
7575
}
7676

77+
void set_retry_count(uint32_t cnt) { retry_cnt_ = cnt; }
78+
79+
auto native_handle() const {
80+
return socket_->native_handle();
81+
}
82+
7783
protected:
7884
std::unique_ptr<FiberSocketBase> socket_;
7985

8086
private:
8187
static bool IsIoError(BoostError ec) {
82-
return bool(ec); // TODO: currently all errors are io errors
88+
using err = ::boost::beast::http::error;
89+
return ec && ec != err::need_buffer;
8390
}
8491

85-
static BoostError HandleError(BoostError ec) {
86-
return ec; // TODO: a hook to print warning errors, change state etc.
92+
BoostError HandleError(BoostError ec) {
93+
if (IsIoError(ec)) {
94+
socket_->Close();
95+
}
96+
return ec;
8797
}
8898

8999
fb2::ProactorBase* proactor_;
@@ -98,8 +108,7 @@ class Client {
98108

99109
template <typename Req, typename Resp> auto Client::Send(const Req& req, Resp* resp) -> BoostError {
100110
namespace h2 = ::boost::beast::http;
101-
BoostError ec;
102-
::boost::system::error_code read_ec;
111+
BoostError ec, read_ec;
103112
AsioStreamAdapter<> adapter(*socket_);
104113

105114
for (uint32_t i = 0; i < retry_cnt_; ++i) {

util/http/http_test.cc

-90
This file was deleted.

util/http/http_testing.cc

-31
This file was deleted.

util/http/http_testing.h

-23
This file was deleted.

0 commit comments

Comments
 (0)