diff --git a/include/cpp_http/http_client.hpp b/include/cpp_http/http_client.hpp index a8c09dd..6fc42d3 100644 --- a/include/cpp_http/http_client.hpp +++ b/include/cpp_http/http_client.hpp @@ -63,7 +63,7 @@ namespace cpp_http protected: template - void do_execute_http_request(http_stream_type& http_stream, duration_type const& timeout_interval, std::shared_ptr& callback_called, callback_type& callback) + void do_execute_http_request(http_stream_type& http_stream, duration_type const& timeout_interval, std::shared_ptr& callback_called, http_request::shared_ptr request_ptr, callback_type& callback) { if (!_connected) { @@ -73,7 +73,7 @@ namespace cpp_http auto self = shared_from_this(); _strand.dispatch( - [this, self, &http_stream, callback_called, callback] + [this, self, &http_stream, callback_called, request_ptr, callback] () { if (!_connected) @@ -82,7 +82,7 @@ namespace cpp_http } boost::beast::http::async_write(http_stream, _http_request, cpp_http_asio::bind_executor(_strand, - [this, self, &http_stream, callback_called, callback] + [this, self, &http_stream, callback_called, request_ptr, callback] (boost::beast::error_code ec, size_t bytes_transferred) mutable { cpp_hpp_diagnostic_trace([&]() { std::stringstream ss; ss << "beast::async_write(http), ec: " << ec; return ss.str(); }); @@ -109,7 +109,7 @@ namespace cpp_http } boost::beast::http::async_read(http_stream, _flat_buffer, _http_response, cpp_http_asio::bind_executor(_strand, - [this, self, callback_called, callback] + [this, self, callback_called, request_ptr, callback] (boost::beast::error_code ec, size_t bytes_transferred) mutable { cpp_hpp_diagnostic_trace([&]() { std::stringstream ss; ss << "beast::async_read(http), ec: " << ec; return ss.str(); }); @@ -134,6 +134,8 @@ namespace cpp_http impl::from_beast_http_response(*response_ptr.get(), _http_response); + after_execute(*response_ptr.get(), *request_ptr.get(), _http_target_string); + debug_info([&]() { return cpp_http_format::format("http{} async response received:\n{}", (_uri_protocol_is_secure ? "s" : ""), response_ptr->to_string()); }); callback(response_ptr, {}); @@ -277,6 +279,8 @@ namespace cpp_http impl::from_beast_http_response(response, _http_response); + after_execute(response, request, _http_target_string); + debug_info([&]() { return cpp_http_format::format("http sync response received:\n{}", response.to_string()); }); return response; @@ -377,11 +381,11 @@ namespace cpp_http if (_uri_protocol_is_secure) { - do_execute_http_request(_https_stream, timeout_interval, callback_called, callback); + do_execute_http_request(_https_stream, timeout_interval, callback_called, request_ptr, callback); } else { - do_execute_http_request(_http_stream, timeout_interval, callback_called, callback); + do_execute_http_request(_http_stream, timeout_interval, callback_called, request_ptr, callback); } })); } diff --git a/include/cpp_http/impl/http_client_base.hpp b/include/cpp_http/impl/http_client_base.hpp index a557321..96e4259 100644 --- a/include/cpp_http/impl/http_client_base.hpp +++ b/include/cpp_http/impl/http_client_base.hpp @@ -68,7 +68,11 @@ namespace cpp_http } protected: - virtual void before_execute(http_request& request /* info */, std::string const& /* final_http_target_string */) + virtual void before_execute(http_request& /* request */, std::string const& /* final_http_target_string */) + { + } + + virtual void after_execute(http_response& /* response */, http_request const& /* request */, std::string const& /* final_http_target_string */) { }