4444#endif
4545
4646#include " http_client_impl.h"
47+ #include " cpprest/base_uri.h"
4748#include " cpprest/details/x509_cert_utilities.h"
4849#include < unordered_set>
4950
5051using boost::asio::ip::tcp;
5152
53+ #define CRLF std::string (" \r\n " )
54+
5255namespace web { namespace http
5356{
5457namespace client
@@ -227,8 +230,6 @@ class asio_connection
227230 m_is_reused = true ;
228231 }
229232
230- void handle_pool_timer (const boost::system::error_code& ec);
231-
232233 // Guards concurrent access to socket/ssl::stream. This is necessary
233234 // because timeouts and cancellation can touch the socket at the same time
234235 // as normal message processing.
@@ -331,7 +332,7 @@ class asio_connection_pool
331332
332333
333334
334- class asio_client : public _http_client_communicator , public std ::enable_shared_from_this<asio_client>
335+ class asio_client : public _http_client_communicator
335336{
336337public:
337338 asio_client (http::uri address, http_client_config client_config)
@@ -347,6 +348,8 @@ class asio_client : public _http_client_communicator, public std::enable_shared_
347348
348349 unsigned long open () override { return 0 ; }
349350
351+ virtual pplx::task<http_response> propagate (http_request request) override ;
352+
350353 asio_connection_pool m_pool;
351354 tcp::resolver m_resolver;
352355};
@@ -656,7 +659,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
656659 extra_headers.append (" : no-cache" + CRLF);
657660 }
658661
659- request_stream << flatten_http_headers (ctx->m_request .headers ());
662+ request_stream << :: web::http::details:: flatten_http_headers (ctx->m_request .headers ());
660663 request_stream << extra_headers;
661664 // Enforce HTTP connection keep alive (even for the old HTTP/1.0 protocol).
662665 request_stream << " Connection: Keep-Alive" << CRLF << CRLF;
@@ -1446,22 +1449,9 @@ class asio_context : public request_context, public std::enable_shared_from_this
14461449};
14471450
14481451
1449-
1450- http_network_handler::http_network_handler (const uri &base_uri, const http_client_config &client_config) :
1451- m_http_client_impl(std::make_shared<asio_client>(base_uri, client_config))
1452- {}
1453-
1454- pplx::task<http_response> http_network_handler::propagate (http_request request)
1452+ std::shared_ptr<_http_client_communicator> create_platform_final_pipeline_stage (uri base_uri, const http_client_config& client_config)
14551453{
1456- auto context = details::asio_context::create_request_context (m_http_client_impl, request);
1457-
1458- // Use a task to externally signal the final result and completion of the task.
1459- auto result_task = pplx::create_task (context->m_request_completion );
1460-
1461- // Asynchronously send the response with the HTTP client implementation.
1462- m_http_client_impl->async_send_request (context);
1463-
1464- return result_task;
1454+ return std::make_shared<asio_client>(base_uri, client_config);
14651455}
14661456
14671457void asio_client::send_request (const std::shared_ptr<request_context> &request_ctx)
@@ -1488,4 +1478,18 @@ void asio_client::send_request(const std::shared_ptr<request_context> &request_c
14881478 ctx->start_request ();
14891479}
14901480
1481+ pplx::task<http_response> asio_client::propagate (http_request request)
1482+ {
1483+ auto self = std::static_pointer_cast<_http_client_communicator>(shared_from_this ());
1484+ auto context = details::asio_context::create_request_context (self, request);
1485+
1486+ // Use a task to externally signal the final result and completion of the task.
1487+ auto result_task = pplx::create_task (context->m_request_completion );
1488+
1489+ // Asynchronously send the response with the HTTP client implementation.
1490+ this ->async_send_request (context);
1491+
1492+ return result_task;
1493+ }
1494+
14911495}}}} // namespaces
0 commit comments