Skip to content

Instantly share code, notes, and snippets.

@jeroen
Last active August 29, 2015 14:26
Show Gist options
  • Save jeroen/1250e73f93acfffb0e9a to your computer and use it in GitHub Desktop.
Save jeroen/1250e73f93acfffb0e9a to your computer and use it in GitHub Desktop.
Test curl proxy conf

Test IE proxy settings with curl

The goal is to correctly test the various possible proxy configurations under windows and use those settings in the curl package.

Install the latest version of the curl package:

install.packages("curl")
stopifnot(packageVersion("curl") >= "0.9.2")

The ie_proxy_info function looks up your current proxy settings as configured in IE under Internet Options > Tab: Connections > LAN Settings.

ie_proxy_info()

Confirm that the settings correspond to your settings in IE.

screenshot

Lookup proxy for a given URL

The ie_get_proxy_for_url function determines if and which proxy should be used to connect to a particular URL. If your settings have an "automatic configuration script" this involves downloading and executing a PAC file, which can take a while.

ie_get_proxy_for_url("http://www.google.com/test")
ie_get_proxy_for_url("http://localhost/test")
ie_get_proxy_for_url("http://foo/test")

The ie_get_proxy_for_url function either returns a URL of a proxy, or NULL if no proxy should be used for this target host.

Try connecting

Test if you can connect to various servers that you are able to connect to with internet explorer.

connect_with_proxy <- function(url){
  proxy_server <- ie_get_proxy_for_url(url)
  h <- new_handle(verbose = TRUE, proxy = proxy_server)
  readLines(curl(url, handle = h))
}

connect_with_proxy("http://httpbin.org/get")
@imanuelcostigan
Copy link

For completeness, you should include a library(curl) call after installation.

@imanuelcostigan
Copy link

All good at my end. Using auto config URL, no auto-detect. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment