Skip to content

Commit 02119a1

Browse files
committed
have BingRequest honour http_proxy environment variable
1 parent 943aa0b commit 02119a1

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Release/samples/BingRequest/bingrequest.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ using namespace web::http;
3030
using namespace web::http::client;
3131
using namespace concurrency::streams;
3232

33+
/* Can pass proxy information via environment variable http_proxy.
34+
Example:
35+
Linux: export http_proxy=http://192.1.8.1:8080
36+
*/
37+
web::http::client::http_client_config client_config_for_proxy()
38+
{
39+
web::http::client::http_client_config client_config;
40+
41+
if(const char* env_http_proxy = std::getenv("http_proxy")) {
42+
web::web_proxy proxy(env_http_proxy);
43+
client_config.set_proxy(proxy);
44+
}
45+
46+
return client_config;
47+
}
48+
49+
3350
#ifdef _WIN32
3451
int wmain(int argc, wchar_t *args[])
3552
#else
@@ -52,7 +69,7 @@ int main(int argc, char *args[])
5269

5370
// Create an HTTP request.
5471
// Encode the URI query since it could contain special characters like spaces.
55-
http_client client(U("http://www.bing.com/"));
72+
http_client client(U("http://www.bing.com/"), client_config_for_proxy());
5673
return client.request(methods::GET, uri_builder(U("/search")).append_query(U("q"), searchTerm).to_string());
5774
})
5875

@@ -74,4 +91,4 @@ int main(int argc, char *args[])
7491
.wait();
7592

7693
return 0;
77-
}
94+
}

0 commit comments

Comments
 (0)