@@ -460,14 +460,14 @@ class asio_context : public request_context, public std::enable_shared_from_this
460460 ctx->m_timer .set_ctx (std::weak_ptr<asio_context>(ctx));
461461 return ctx;
462462 }
463-
463+
464464 class ssl_proxy_tunnel : public std ::enable_shared_from_this<ssl_proxy_tunnel>
465465 {
466466 public:
467467 ssl_proxy_tunnel (std::shared_ptr<asio_context> context, std::function<void (std::shared_ptr<asio_context>)> ssl_tunnel_established)
468468 : m_ssl_tunnel_established(ssl_tunnel_established), m_context(context)
469469 {}
470-
470+
471471 void start_proxy_connect ()
472472 {
473473 auto proxy = m_context->m_http_client ->client_config ().proxy ();
@@ -502,7 +502,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
502502 client->m_resolver .async_resolve (query, boost::bind (&ssl_proxy_tunnel::handle_resolve, shared_from_this (), boost::asio::placeholders::error, boost::asio::placeholders::iterator));
503503 }
504504
505- private:
505+ private:
506506 void handle_resolve (const boost::system::error_code& ec, tcp::resolver::iterator endpoints)
507507 {
508508 if (ec)
@@ -553,7 +553,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
553553 m_context->report_error (" Failed to send connect request to proxy." , err, httpclient_errorcode_context::writebody);
554554 }
555555 }
556-
556+
557557 void handle_status_line (const boost::system::error_code& ec)
558558 {
559559 if (!ec)
@@ -565,13 +565,13 @@ class asio_context : public request_context, public std::enable_shared_from_this
565565 response_stream >> http_version;
566566 status_code status_code;
567567 response_stream >> status_code;
568-
568+
569569 if (!response_stream || http_version.substr (0 , 5 ) != " HTTP/" )
570570 {
571571 m_context->report_error (" Invalid HTTP status line during proxy connection" , ec, httpclient_errorcode_context::readheader);
572572 return ;
573573 }
574-
574+
575575 if (status_code != 200 )
576576 {
577577 m_context->report_error (" Expected a 200 response from proxy, received: " + to_string (status_code), ec, httpclient_errorcode_context::readheader);
@@ -593,14 +593,14 @@ class asio_context : public request_context, public std::enable_shared_from_this
593593 // Failed to write to socket because connection was already closed while it was in the pool.
594594 // close() here ensures socket is closed in a robust way and prevents the connection from being put to the pool again.
595595 m_context->m_connection ->close ();
596-
596+
597597 // Create a new context and copy the request object, completion event and
598598 // cancellation registration to maintain the old state.
599599 // This also obtains a new connection from pool.
600600 auto new_ctx = m_context->create_request_context (m_context->m_http_client , m_context->m_request );
601601 new_ctx->m_request_completion = m_context->m_request_completion ;
602602 new_ctx->m_cancellationRegistration = m_context->m_cancellationRegistration ;
603-
603+
604604 auto client = std::static_pointer_cast<asio_client>(m_context->m_http_client );
605605 // Resend the request using the new context.
606606 client->send_request (new_ctx);
@@ -611,15 +611,15 @@ class asio_context : public request_context, public std::enable_shared_from_this
611611 }
612612 }
613613 }
614-
614+
615615 std::function<void (std::shared_ptr<asio_context>)> m_ssl_tunnel_established;
616616 std::shared_ptr<asio_context> m_context;
617-
617+
618618 boost::asio::streambuf m_request;
619619 boost::asio::streambuf m_response;
620620 };
621-
622-
621+
622+
623623 enum class http_proxy_type
624624 {
625625 none,
@@ -634,11 +634,11 @@ class asio_context : public request_context, public std::enable_shared_from_this
634634 request_context::report_error (make_error_code (std::errc::operation_canceled).value (), " Request canceled by user." );
635635 return ;
636636 }
637-
637+
638638 http_proxy_type proxy_type = http_proxy_type::none;
639639 std::string proxy_host;
640640 int proxy_port = -1 ;
641-
641+
642642 // There is no support for auto-detection of proxies on non-windows platforms, it must be specified explicitly from the client code.
643643 if (m_http_client->client_config ().proxy ().is_specified ())
644644 {
@@ -648,28 +648,28 @@ class asio_context : public request_context, public std::enable_shared_from_this
648648 proxy_port = proxy_uri.port () == -1 ? 8080 : proxy_uri.port ();
649649 proxy_host = utility::conversions::to_utf8string (proxy_uri.host ());
650650 }
651-
651+
652652 auto start_http_request_flow = [proxy_type, proxy_host, proxy_port AND_CAPTURE_MEMBER_FUNCTION_POINTERS](std::shared_ptr<asio_context> ctx)
653653 {
654654 if (ctx->m_request ._cancellation_token ().is_canceled ())
655655 {
656656 ctx->request_context ::report_error (make_error_code (std::errc::operation_canceled).value (), " Request canceled by user." );
657657 return ;
658658 }
659-
659+
660660 const auto &base_uri = ctx->m_http_client ->base_uri ();
661661 const auto full_uri = uri_builder (base_uri).append (ctx->m_request .relative_uri ()).to_uri ();
662-
662+
663663 // For a normal http proxy, we need to specify the full request uri, otherwise just specify the resource
664664 auto encoded_resource = proxy_type == http_proxy_type::http ? full_uri.to_string () : full_uri.resource ().to_string ();
665-
665+
666666 if (encoded_resource.empty ())
667667 {
668668 encoded_resource = U (" /" );
669669 }
670-
670+
671671 const auto &method = ctx->m_request .method ();
672-
672+
673673 // stop injection of headers via method
674674 // resource should be ok, since it's been encoded
675675 // and host won't resolve
@@ -678,20 +678,20 @@ class asio_context : public request_context, public std::enable_shared_from_this
678678 ctx->report_exception (http_exception (" The method string is invalid." ));
679679 return ;
680680 }
681-
681+
682682 std::ostream request_stream (&ctx->m_body_buf );
683683 request_stream.imbue (std::locale::classic ());
684684 const auto &host = utility::conversions::to_utf8string (base_uri.host ());
685-
685+
686686 request_stream << utility::conversions::to_utf8string (method) << " " << utility::conversions::to_utf8string (encoded_resource) << " " << " HTTP/1.1" << CRLF;
687-
687+
688688 int port = base_uri.port ();
689-
689+
690690 if (base_uri.is_port_default ())
691691 {
692692 port = (ctx->m_connection ->is_ssl () ? 443 : 80 );
693693 }
694-
694+
695695 // Add the Host header if user has not specified it explicitly
696696 if (!ctx->m_request .headers ().has (header_names::host))
697697 {
@@ -701,10 +701,10 @@ class asio_context : public request_context, public std::enable_shared_from_this
701701 }
702702 request_stream << CRLF;
703703 }
704-
704+
705705 // Extra request headers are constructed here.
706706 std::string extra_headers;
707-
707+
708708 // Add header for basic proxy authentication
709709 if (proxy_type == http_proxy_type::http && ctx->m_http_client ->client_config ().proxy ().credentials ().is_set ())
710710 {
@@ -716,7 +716,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
716716 extra_headers.append (ctx->generate_basic_auth_header ());
717717 }
718718
719- ctx->add_accept_encoding_header (extra_headers );
719+ extra_headers += utility::conversions::to_utf8string ( ctx->get_accept_encoding_header () );
720720
721721 // Check user specified transfer-encoding.
722722 std::string transferencoding;
@@ -740,25 +740,25 @@ class asio_context : public request_context, public std::enable_shared_from_this
740740 extra_headers.append (" Content-Length: 0\r\n " );
741741 }
742742 }
743-
743+
744744 if (proxy_type == http_proxy_type::http)
745745 {
746746 extra_headers.append (
747747 " Cache-Control: no-store, no-cache\r\n "
748748 " Pragma: no-cache\r\n " );
749749 }
750-
750+
751751 request_stream << utility::conversions::to_utf8string (::web::http::details::flatten_http_headers (ctx->m_request .headers ()));
752752 request_stream << extra_headers;
753753 // Enforce HTTP connection keep alive (even for the old HTTP/1.0 protocol).
754754 request_stream << " Connection: Keep-Alive" << CRLF << CRLF;
755-
755+
756756 // Start connection timeout timer.
757757 if (!ctx->m_timer .has_started ())
758758 {
759759 ctx->m_timer .start ();
760760 }
761-
761+
762762 if (ctx->m_connection ->is_reused () || proxy_type == http_proxy_type::ssl_tunnel)
763763 {
764764 // If socket is a reused connection or we're connected via an ssl-tunneling proxy, try to write the request directly. In both cases we have already established a tcp connection.
@@ -768,16 +768,16 @@ class asio_context : public request_context, public std::enable_shared_from_this
768768 {
769769 // If the connection is new (unresolved and unconnected socket), then start async
770770 // call to resolve first, leading eventually to request write.
771-
771+
772772 // For normal http proxies, we want to connect directly to the proxy server. It will relay our request.
773773 auto tcp_host = proxy_type == http_proxy_type::http ? proxy_host : host;
774774 auto tcp_port = proxy_type == http_proxy_type::http ? proxy_port : port;
775-
775+
776776 tcp::resolver::query query (tcp_host, to_string (tcp_port));
777777 auto client = std::static_pointer_cast<asio_client>(ctx->m_http_client );
778778 client->m_resolver .async_resolve (query, boost::bind (&asio_context::handle_resolve, ctx, boost::asio::placeholders::error, boost::asio::placeholders::iterator));
779779 }
780-
780+
781781 // Register for notification on cancellation to abort this request.
782782 if (ctx->m_request ._cancellation_token () != pplx::cancellation_token::none ())
783783 {
@@ -794,7 +794,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
794794 });
795795 }
796796 };
797-
797+
798798 if (proxy_type == http_proxy_type::ssl_tunnel)
799799 {
800800 // The ssl_tunnel_proxy keeps the context alive and then calls back once the ssl tunnel is established via 'start_http_request_flow'
@@ -1073,7 +1073,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
10731073 // Reuse error handling.
10741074 return handle_write_body (ec);
10751075 }
1076-
1076+
10771077 m_timer.reset ();
10781078 const auto &progress = m_request._get_impl ()->_progress_handler ();
10791079 if (progress)
@@ -1154,7 +1154,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
11541154 response_stream >> http_version;
11551155 status_code status_code;
11561156 response_stream >> status_code;
1157-
1157+
11581158 std::string status_message;
11591159 std::getline (response_stream, status_message);
11601160
@@ -1418,7 +1418,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
14181418 }
14191419 this_request->m_body_buf .consume (to_read + CRLF.size ()); // consume crlf
14201420 this_request->m_connection ->async_read_until (this_request->m_body_buf , CRLF, boost::bind (&asio_context::handle_chunk_header, this_request, boost::asio::placeholders::error));
1421- });
1421+ });
14221422 }
14231423 }
14241424 }
@@ -1471,7 +1471,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
14711471 if (m_decompressor)
14721472 {
14731473 auto decompressed = m_decompressor->decompress (boost::asio::buffer_cast<const uint8_t *>(m_body_buf.data ()), read_size);
1474-
1474+
14751475 if (m_decompressor->has_error ())
14761476 {
14771477 this_request->report_exception (std::runtime_error (" Failed to decompress the response body" ));
@@ -1646,7 +1646,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
16461646 timeout_timer m_timer;
16471647 boost::asio::streambuf m_body_buf;
16481648 std::shared_ptr<asio_connection> m_connection;
1649-
1649+
16501650#if defined(__APPLE__) || (defined(ANDROID) || defined(__ANDROID__))
16511651 bool m_openssl_failed;
16521652#endif
@@ -1668,7 +1668,7 @@ void asio_client::send_request(const std::shared_ptr<request_context> &request_c
16681668 {
16691669 client_config ().invoke_nativehandle_options (ctx->m_connection ->m_ssl_stream .get ());
16701670 }
1671- else
1671+ else
16721672 {
16731673 client_config ().invoke_nativehandle_options (&(ctx->m_connection ->m_socket ));
16741674 }
0 commit comments