Fixes Client<HTTPS> proxy requests. See #83
This commit is contained in:
parent
dc74f7739e
commit
4606dbd855
2 changed files with 20 additions and 2 deletions
|
|
@ -13,6 +13,9 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace SimpleWeb {
|
namespace SimpleWeb {
|
||||||
|
template <class socket_type>
|
||||||
|
class Client;
|
||||||
|
|
||||||
template <class socket_type>
|
template <class socket_type>
|
||||||
class ClientBase {
|
class ClientBase {
|
||||||
public:
|
public:
|
||||||
|
|
@ -20,6 +23,7 @@ namespace SimpleWeb {
|
||||||
|
|
||||||
class Response {
|
class Response {
|
||||||
friend class ClientBase<socket_type>;
|
friend class ClientBase<socket_type>;
|
||||||
|
friend class Client<socket_type>;
|
||||||
|
|
||||||
//Based on http://www.boost.org/doc/libs/1_60_0/doc/html/unordered/hash_equality.html
|
//Based on http://www.boost.org/doc/libs/1_60_0/doc/html/unordered/hash_equality.html
|
||||||
class iequal_to {
|
class iequal_to {
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ namespace SimpleWeb {
|
||||||
auto host_port=host+':'+std::to_string(port);
|
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";
|
write_stream << "CONNECT "+host_port+" HTTP/1.1\r\n" << "Host: " << host_port << "\r\n\r\n";
|
||||||
auto timer=get_timeout_timer();
|
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*/) {
|
[this, timer](const boost::system::error_code &ec, size_t /*bytes_transferred*/) {
|
||||||
if(timer)
|
if(timer)
|
||||||
timer->cancel();
|
timer->cancel();
|
||||||
|
|
@ -97,7 +97,21 @@ namespace SimpleWeb {
|
||||||
io_service.reset();
|
io_service.reset();
|
||||||
io_service.run();
|
io_service.run();
|
||||||
|
|
||||||
auto response=request_read();
|
std::shared_ptr<Response> 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<std::mutex> 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) {
|
if (response->status_code.empty() || response->status_code.compare(0, 3, "200") != 0) {
|
||||||
std::lock_guard<std::mutex> lock(socket_mutex);
|
std::lock_guard<std::mutex> lock(socket_mutex);
|
||||||
socket=nullptr;
|
socket=nullptr;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue