@@ -325,32 +325,53 @@ class asio_connection_pool
325
325
boost::asio::io_service& m_io_service;
326
326
const int m_timeout_secs;
327
327
const bool m_start_with_ssl;
328
- const std::function<void (boost::asio::ssl::context&)>& m_ssl_context_callback;
328
+ std::function<void (boost::asio::ssl::context&)> m_ssl_context_callback;
329
329
std::vector<std::shared_ptr<asio_connection> > m_connections;
330
330
std::mutex m_connections_mutex;
331
331
};
332
332
333
333
334
-
335
334
class asio_client : public _http_client_communicator
336
335
{
337
336
public:
338
337
asio_client (http::uri address, http_client_config client_config)
339
338
: _http_client_communicator(std::move(address), std::move(client_config))
340
- , m_pool(crossplat::threadpool::shared_instance().service(),
341
- base_uri ().scheme() == "https" && !_http_client_communicator::client_config().proxy().is_specified(),
342
- std::chrono::seconds(30 ), // Unused sockets are kept in pool for 30 seconds.
343
- this->client_config().get_ssl_context_callback())
344
339
, m_resolver(crossplat::threadpool::shared_instance().service())
345
- {}
340
+ {
341
+ std::string host = base_uri ().to_string ();
342
+
343
+ auto &credentials = _http_client_communicator::client_config ().credentials ();
344
+ if (credentials.is_set ())
345
+ {
346
+ host.append (credentials.username ());
347
+ }
348
+
349
+ auto &proxy = _http_client_communicator::client_config ().proxy ();
350
+ if (proxy.is_specified ())
351
+ {
352
+ host.append (proxy.address ().to_string ());
353
+ if (proxy.credentials ().is_set ())
354
+ {
355
+ host.append (proxy.credentials ().username ());
356
+ }
357
+ }
358
+
359
+ m_pool = crossplat::threadpool::shared_instance ().obtain_connection_pool (host, [this ]()
360
+ {
361
+ return std::make_shared<asio_connection_pool>(crossplat::threadpool::shared_instance ().service (),
362
+ base_uri ().scheme () == " https" && !_http_client_communicator::client_config ().proxy ().is_specified (),
363
+ std::chrono::seconds (30 ), // Unused sockets are kept in pool for 30 seconds.
364
+ this ->client_config ().get_ssl_context_callback ());
365
+ });
366
+ }
346
367
347
368
void send_request (const std::shared_ptr<request_context> &request_ctx) override ;
348
369
349
370
unsigned long open () override { return 0 ; }
350
371
351
372
virtual pplx::task<http_response> propagate (http_request request) override ;
352
373
353
- asio_connection_pool m_pool;
374
+ std::shared_ptr< asio_connection_pool> m_pool;
354
375
tcp::resolver m_resolver;
355
376
};
356
377
@@ -375,13 +396,13 @@ class asio_context : public request_context, public std::enable_shared_from_this
375
396
{
376
397
m_timer.stop ();
377
398
// Release connection back to the pool. If connection was not closed, it will be put to the pool for reuse.
378
- std::static_pointer_cast<asio_client>(m_http_client)->m_pool . release (m_connection);
399
+ std::static_pointer_cast<asio_client>(m_http_client)->m_pool -> release (m_connection);
379
400
}
380
401
381
402
static std::shared_ptr<request_context> create_request_context (std::shared_ptr<_http_client_communicator> &client, http_request &request)
382
403
{
383
404
auto client_cast (std::static_pointer_cast<asio_client>(client));
384
- auto connection (client_cast->m_pool . obtain ());
405
+ auto connection (client_cast->m_pool -> obtain ());
385
406
auto ctx = std::make_shared<asio_context>(client, request, connection);
386
407
ctx->m_timer .set_ctx (std::weak_ptr<asio_context>(ctx));
387
408
return ctx;
@@ -458,7 +479,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
458
479
m_context->m_timer .reset ();
459
480
// // Replace the connection. This causes old connection object to go out of scope.
460
481
auto client = std::static_pointer_cast<asio_client>(m_context->m_http_client );
461
- m_context->m_connection = client->m_pool . obtain ();
482
+ m_context->m_connection = client->m_pool -> obtain ();
462
483
463
484
auto endpoint = *endpoints;
464
485
m_context->m_connection ->async_connect (endpoint, boost::bind (&ssl_proxy_tunnel::handle_tcp_connect, shared_from_this (), boost::asio::placeholders::error, ++endpoints));
@@ -811,7 +832,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
811
832
{
812
833
// Replace the connection. This causes old connection object to go out of scope.
813
834
auto client = std::static_pointer_cast<asio_client>(m_http_client);
814
- m_connection = client->m_pool . obtain ();
835
+ m_connection = client->m_pool -> obtain ();
815
836
816
837
auto endpoint = *endpoints;
817
838
m_connection->async_connect (endpoint, boost::bind (&asio_context::handle_connect, shared_from_this (), boost::asio::placeholders::error, ++endpoints));
0 commit comments