From 4606dbd85557fec53fba1ada50100a374810504c Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 16 Dec 2016 11:11:34 +0100 Subject: [PATCH] Fixes Client proxy requests. See #83 --- client_http.hpp | 4 ++++ client_https.hpp | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index f534762..e020fe6 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -13,6 +13,9 @@ #include namespace SimpleWeb { + template + class Client; + template class ClientBase { public: @@ -20,6 +23,7 @@ namespace SimpleWeb { class Response { friend class ClientBase; + friend class Client; //Based on http://www.boost.org/doc/libs/1_60_0/doc/html/unordered/hash_equality.html class iequal_to { diff --git a/client_https.hpp b/client_https.hpp index 2ad3406..67c9a19 100644 --- a/client_https.hpp +++ b/client_https.hpp @@ -84,7 +84,7 @@ namespace SimpleWeb { auto host_port=host+':'+std::to_string(port); write_stream << "CONNECT "+host_port+" HTTP/1.1\r\n" << "Host: " << host_port << "\r\n\r\n"; auto timer=get_timeout_timer(); - boost::asio::async_write(*socket, write_buffer, + boost::asio::async_write(socket->next_layer(), write_buffer, [this, timer](const boost::system::error_code &ec, size_t /*bytes_transferred*/) { if(timer) timer->cancel(); @@ -97,7 +97,21 @@ namespace SimpleWeb { io_service.reset(); io_service.run(); - auto response=request_read(); + std::shared_ptr response(new Response()); + timer=get_timeout_timer(); + boost::asio::async_read_until(socket->next_layer(), response->content_buffer, "\r\n\r\n", + [this, timer](const boost::system::error_code& ec, size_t /*bytes_transferred*/) { + if(timer) + timer->cancel(); + if(ec) { + std::lock_guard lock(socket_mutex); + socket=nullptr; + throw boost::system::system_error(ec); + } + }); + io_service.reset(); + io_service.run(); + parse_response_header(response); if (response->status_code.empty() || response->status_code.compare(0, 3, "200") != 0) { std::lock_guard lock(socket_mutex); socket=nullptr;