Skip to content

Commit 8833a2b

Browse files
authored
Merge pull request #494 from vadz/fix-sample-proxy
Improve http_proxy handling in BingRequest sample
2 parents fc20c17 + 065d075 commit 8833a2b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Release/samples/BingRequest/bingrequest.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ web::http::client::http_client_config client_config_for_proxy()
2626
{
2727
web::http::client::http_client_config client_config;
2828
#ifdef _WIN32
29-
wchar_t* pValue;
30-
size_t len;
29+
wchar_t* pValue = nullptr;
30+
std::unique_ptr<wchar_t, void(*)(wchar_t*)> holder(nullptr, [](wchar_t* p) { free(p); });
31+
size_t len = 0;
3132
auto err = _wdupenv_s(&pValue, &len, L"http_proxy");
32-
if (!err) {
33-
std::unique_ptr<wchar_t, void(*)(wchar_t*)> holder(pValue, [](wchar_t* p) { free(p); });
34-
uri proxy_uri(std::wstring(pValue, len));
33+
if (pValue)
34+
holder.reset(pValue);
35+
if (!err && pValue && len) {
36+
std::wstring env_http_proxy_string(pValue, len - 1);
3537
#else
3638
if(const char* env_http_proxy = std::getenv("http_proxy")) {
37-
uri proxy_uri(utility::conversions::to_string_t(env_http_proxy));
39+
std::string env_http_proxy_string(env_http_proxy);
3840
#endif
39-
web::web_proxy proxy(proxy_uri);
40-
client_config.set_proxy(proxy);
41+
if (env_http_proxy_string == U("auto"))
42+
client_config.set_proxy(web::web_proxy::use_auto_discovery);
43+
else
44+
client_config.set_proxy(web::web_proxy(env_http_proxy_string));
4145
}
4246

4347
return client_config;

0 commit comments

Comments
 (0)