[Rd] Changing HTTP proxy configurations at run time

Moritz Gerstung mg14 at sanger.ac.uk
Thu Apr 4 11:56:55 CEST 2013


DeaR developers,

I was recently moving with my laptop between two environments with and without a HTTP proxy server. As the internal proxy configuration is read only once from the environment variables http_proxy/HTTP_PROXY at the first call of download.file(), the proxy configurations couldn't be adjusted at a later stage. (See also the comment in ?download.file). This caused some frustration as I wasn't able to use http functionality in a running R session after moving to an environment with a different/no proxy server.

After some digging I found that this behaviour was caused by RxmlNanoHTTPInit() in src/modules/internet/nanohttp.c, which after its first call refuses to reinitialise the proxy configuration. It does so by setting a variable 'initialized' to 1, and checking whether the string 'proxy' is non-NULL.

I have made a small modification to have RxmlNanoHTTPInit() ignore these variables and to read in the proxy configuration at each call.

$ svn diff
Index: src/modules/internet/nanohttp.c
===================================================================
--- src/modules/internet/nanohttp.c	(revision 62488)
+++ src/modules/internet/nanohttp.c	(working copy)
@@ -255,15 +255,12 @@
     WSADATA wsaData;
 #endif

-    if (initialized)
-	return;
-
 #ifdef _WINSOCKAPI_
     if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0)
 	return;
 #endif

-    if (proxy == NULL) {
+    proxy = NULL;
 	proxyPort = 80;
 	env = getenv("no_proxy");
 	if (env && ((env[0] == '*') && (env[1] == 0)))
@@ -287,7 +284,7 @@
 #endif
 	    proxyUser = xmlMemStrdup(env);
 	}
-    }
+
  done:
     initialized = 1;
 }


This works fine for me (on a Mac) and I can simply use Sys.setenv(http_proxy=) to adjust the proxy server at run time.

I think this doesn't really cause overhead as the number of calls do download.file() is typically small and parsing the environment variables is simple. On the other hand, if a user alters the proxy environment variables, he/she probably does so for a reason. Googling around I found a few posts of R users demanding this.

A cleaner solution would of course be to write a function that resets the internal proxy configuration, but this would be a bit of an effort to make it user visible.

What are your thoughts?

Best wishes,

Moritz

-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE.



More information about the R-devel mailing list