Skip to content

Commit 39ad665

Browse files
author
Chris Deering
committed
Updates from code review. Adding new manual test cases for http_proxy and https_proxy
1 parent a20b669 commit 39ad665

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

Release/include/cpprest/details/http_client_impl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,10 @@ class _http_client_communicator
296296
// URI to connect to.
297297
const http::uri m_uri;
298298

299-
300-
http_client_config m_client_config;
301-
302299
private:
303300

301+
http_client_config m_client_config;
302+
304303
bool m_opened;
305304

306305
pplx::extensibility::critical_section_t m_open_lock;

Release/src/http/client/http_client_asio.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ class asio_client : public _http_client_communicator, public std::enable_shared_
329329
asio_client(http::uri address, http_client_config client_config)
330330
: _http_client_communicator(std::move(address), std::move(client_config))
331331
, m_pool(crossplat::threadpool::shared_instance().service(),
332-
base_uri().scheme() == "https" && !m_client_config.proxy().is_specified(),
332+
base_uri().scheme() == "https" && !_http_client_communicator::client_config().proxy().is_specified(),
333333
std::chrono::seconds(30), // Unused sockets are kept in pool for 30 seconds.
334334
this->client_config().get_ssl_context_callback())
335335
, m_resolver(crossplat::threadpool::shared_instance().service())
@@ -394,14 +394,14 @@ class asio_context : public request_context, public std::enable_shared_from_this
394394
const auto &base_uri = m_context->m_http_client->base_uri();
395395
const auto &host = base_uri.host();
396396

397-
std::ostream request_stream(&request_);
397+
std::ostream request_stream(&m_request);
398398
request_stream.imbue(std::locale::classic());
399399

400400
request_stream << "CONNECT " << host << ":" << 443 << " HTTP/1.1" << CRLF;
401401
request_stream << "Host: " << host << ":" << 443 << CRLF;
402402
request_stream << "Proxy-Connection: Keep-Alive" << CRLF;
403403

404-
if(!m_context->m_http_client->client_config().proxy().credentials().username().empty())
404+
if(m_context->m_http_client->client_config().proxy().credentials().is_set())
405405
{
406406
request_stream << m_context->generate_basic_proxy_auth_header() << CRLF;
407407
}
@@ -436,7 +436,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
436436
if (!ec)
437437
{
438438
m_context->m_timer.reset();
439-
m_context->m_connection->async_write(request_, boost::bind(&ssl_proxy_tunnel::handle_write_request, shared_from_this(), boost::asio::placeholders::error));
439+
m_context->m_connection->async_write(m_request, boost::bind(&ssl_proxy_tunnel::handle_write_request, shared_from_this(), boost::asio::placeholders::error));
440440
}
441441
else if (endpoints == tcp::resolver::iterator())
442442
{
@@ -460,7 +460,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
460460
if (!err)
461461
{
462462
m_context->m_timer.reset();
463-
m_context->m_connection->async_read_until(response_, CRLF + CRLF, boost::bind(&ssl_proxy_tunnel::handle_status_line, shared_from_this(), boost::asio::placeholders::error));
463+
m_context->m_connection->async_read_until(m_response, CRLF + CRLF, boost::bind(&ssl_proxy_tunnel::handle_status_line, shared_from_this(), boost::asio::placeholders::error));
464464
}
465465
else
466466
{
@@ -473,7 +473,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
473473
if (!ec)
474474
{
475475
m_context->m_timer.reset();
476-
std::istream response_stream(&response_);
476+
std::istream response_stream(&m_response);
477477
response_stream.imbue(std::locale::classic());
478478
std::string http_version;
479479
response_stream >> http_version;
@@ -531,8 +531,8 @@ class asio_context : public request_context, public std::enable_shared_from_this
531531
std::function<void(std::shared_ptr<asio_context>)> m_ssl_tunnel_established;
532532
std::shared_ptr<asio_context> m_context;
533533

534-
boost::asio::streambuf request_;
535-
boost::asio::streambuf response_;
534+
boost::asio::streambuf m_request;
535+
boost::asio::streambuf m_response;
536536
};
537537

538538

@@ -614,7 +614,7 @@ class asio_context : public request_context, public std::enable_shared_from_this
614614
utility::string_t extra_headers;
615615

616616
// Add header for basic proxy authentication
617-
if (proxy_type == http_proxy_type::http && !ctx->m_http_client->client_config().proxy().credentials().username().empty())
617+
if (proxy_type == http_proxy_type::http && ctx->m_http_client->client_config().proxy().credentials().is_set())
618618
{
619619
extra_headers.append(ctx->generate_basic_proxy_auth_header());
620620
}

Release/tests/functional/http/client/proxy_tests.cpp

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ TEST_FIXTURE(uri_address, no_proxy_options_on_winrt)
9090

9191
#ifndef __cplusplus_winrt
9292
// Can't specify a proxy with WinRT implementation.
93-
TEST_FIXTURE(uri_address, proxy_with_credentials)
93+
TEST_FIXTURE(uri_address, http_proxy_with_credentials)
9494
{
9595
uri u(U("http://netproxy.redmond.corp.microsoft.com"));
9696

@@ -124,6 +124,47 @@ TEST_FIXTURE(uri_address, proxy_with_credentials)
124124
throw;
125125
}
126126
}
127+
128+
TEST_FIXTURE(uri_address, http_proxy, "Ignore", "Manual")
129+
{
130+
// In order to run this test, replace this proxy uri with one that you have access to.
131+
uri u(U("http://netproxy.redmond.corp.microsoft.com"));
132+
133+
web_proxy proxy(u);
134+
VERIFY_IS_TRUE(proxy.is_specified());
135+
VERIFY_ARE_EQUAL(u, proxy.address());
136+
137+
http_client_config config;
138+
config.set_proxy(proxy);
139+
140+
http_client client(U("http://httpbin.org"), config);
141+
142+
http_response response = client.request(methods::GET).get();
143+
VERIFY_ARE_EQUAL(status_codes::OK, response.status_code());
144+
response.content_ready().wait();
145+
}
146+
147+
148+
TEST_FIXTURE(uri_address, https_proxy, "Ignore", "Manual")
149+
{
150+
// In order to run this test, replace this proxy uri with one that you have access to.
151+
uri u(U("http://netproxy.redmond.corp.microsoft.com"));
152+
153+
web_proxy proxy(u);
154+
VERIFY_IS_TRUE(proxy.is_specified());
155+
VERIFY_ARE_EQUAL(u, proxy.address());
156+
157+
http_client_config config;
158+
config.set_proxy(proxy);
159+
160+
http_client client(U("https://httpbin.org"), config);
161+
162+
http_response response = client.request(methods::GET).get();
163+
VERIFY_ARE_EQUAL(status_codes::OK, response.status_code());
164+
response.content_ready().wait();
165+
}
166+
167+
127168
#endif
128169

129170
} // SUITE(proxy_tests)

0 commit comments

Comments
 (0)