diff --git a/Frameworks/network/src/download.cc b/Frameworks/network/src/download.cc index d3c155f6..24d210ec 100644 --- a/Frameworks/network/src/download.cc +++ b/Frameworks/network/src/download.cc @@ -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); diff --git a/Frameworks/network/src/download_tbz.cc b/Frameworks/network/src/download_tbz.cc index 0f8d0fcc..e28a75f6 100644 --- a/Frameworks/network/src/download_tbz.cc +++ b/Frameworks/network/src/download_tbz.cc @@ -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); diff --git a/Frameworks/network/src/post.cc b/Frameworks/network/src/post.cc index e9f1b88d..7f52035a 100644 --- a/Frameworks/network/src/post.cc +++ b/Frameworks/network/src/post.cc @@ -58,7 +58,7 @@ long post_to_server (std::string const& url, std::map // 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); diff --git a/Frameworks/network/src/proxy.cc b/Frameworks/network/src/proxy.cc index 198417d0..346efd5a 100644 --- a/Frameworks/network/src/proxy.cc +++ b/Frameworks/network/src/proxy.cc @@ -1,5 +1,6 @@ #include "proxy.h" #include +#include #include #include @@ -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); diff --git a/Frameworks/network/src/proxy.h b/Frameworks/network/src/proxy.h index 5246afca..ade85a00 100644 --- a/Frameworks/network/src/proxy.h +++ b/Frameworks/network/src/proxy.h @@ -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 */ diff --git a/Frameworks/network/target b/Frameworks/network/target index 6e2cd252..510169da 100644 --- a/Frameworks/network/target +++ b/Frameworks/network/target @@ -1,6 +1,6 @@ SOURCES = src/*.cc TEST_SOURCES = tests/*.cc -LINK += text cf io plist OakSystem +LINK += text cf io plist OakSystem regexp LIBS = curl crypto EXPORT = src/{constants,download{,_tbz},filter_*,key_chain,network,post,proxy,tbz}.h FRAMEWORKS = SystemConfiguration Security