Make proxy setup URL specific

We now bypass the global proxy if trying to connect to localhost (as some of our tests do) and we also hand the actual target URL to the potential proxy auto configuration (PAC) script.
This commit is contained in:
Allan Odgaard
2012-08-13 20:30:47 +02:00
parent 25071ce6e5
commit f370ee13e4
6 changed files with 10 additions and 7 deletions

View File

@@ -175,7 +175,7 @@ namespace network
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
}
if(auto proxySettings = get_proxy_settings())
if(auto proxySettings = get_proxy_settings(request._url))
{
curl_easy_setopt(handle, CURLOPT_PROXY, proxySettings.server.c_str());
curl_easy_setopt(handle, CURLOPT_PROXYPORT, proxySettings.port);

View File

@@ -148,7 +148,7 @@ namespace network
curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
}
if(auto proxySettings = get_proxy_settings())
if(auto proxySettings = get_proxy_settings(url))
{
curl_easy_setopt(handle, CURLOPT_PROXY, proxySettings.server.c_str());
curl_easy_setopt(handle, CURLOPT_PROXYPORT, proxySettings.port);

View File

@@ -58,7 +58,7 @@ long post_to_server (std::string const& url, std::map<std::string, std::string>
// curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &receive_data);
// curl_easy_setopt(handle, CURLOPT_WRITEDATA, &body);
if(proxy_settings_t const& proxySettings = get_proxy_settings())
if(proxy_settings_t const& proxySettings = get_proxy_settings(url))
{
curl_easy_setopt(handle, CURLOPT_PROXY, proxySettings.server.c_str());
curl_easy_setopt(handle, CURLOPT_PROXYPORT, proxySettings.port);

View File

@@ -1,5 +1,6 @@
#include "proxy.h"
#include <plist/plist.h>
#include <regexp/regexp.h>
#include <oak/debug.h>
#include <cf/cf.h>
@@ -106,9 +107,11 @@ static void pac_proxy_callback (void* client, CFArrayRef proxyList, CFErrorRef e
}
#endif
proxy_settings_t get_proxy_settings ()
proxy_settings_t get_proxy_settings (std::string const& url)
{
proxy_settings_t res(false);
if(regexp::search("^https?://localhost[:/]", url.data(), url.data() + url.size()))
return res;
CFDictionaryRef tmp = SCDynamicStoreCopyProxies(NULL);
plist::dictionary_t const& plist = plist::convert(tmp);
@@ -133,7 +136,7 @@ proxy_settings_t get_proxy_settings ()
CFStreamClientContext context = { 0, &res, NULL, NULL, NULL };
CFURLRef pacURL = CFURLCreateWithString(kCFAllocatorDefault, cf::wrap(pacString), NULL);
CFURLRef targetURL = CFURLCreateWithString(kCFAllocatorDefault, CFSTR("http://macromates.com/"), NULL);
CFURLRef targetURL = CFURLCreateWithString(kCFAllocatorDefault, cf::wrap(url), NULL);
CFRunLoopSourceRef runLoopSource = CFNetworkExecuteProxyAutoConfigurationURL(pacURL, targetURL, &pac_proxy_callback, &context);
CFRelease(targetURL);
CFRelease(pacURL);

View File

@@ -15,6 +15,6 @@ struct proxy_settings_t
std::string password;
};
PUBLIC proxy_settings_t get_proxy_settings ();
PUBLIC proxy_settings_t get_proxy_settings (std::string const& url);
#endif /* end of include guard: PROXY_H_S8ZWZPU8 */