The attached patch implements support for the http_proxy and https_proxy environment variables. This allows subversion to automatically make use of system-wide proxy configuration, rather than requiring subversion-specific proxy configuration; environment variables also make it easier to have network-specific configuration on machines that use more than one network. Subversion-specific configuration (in ~/.subversion/servers) will override the environment.
Written after observing some ChromeOS build system documentation that showed how to configure proxy environment variables, and then listed subversion as the one special case requiring its own configuration. - Josh Triplett
[[[ Add support for http_proxy and https_proxy environment variables. This allows subversion to automatically make use of system-wide proxy configuration, rather than requiring subversion-specific proxy configuration; environment variables also make it easier to have network-specific configuration on machines that use more than one network. Subversion-specific configuration (in ~/.subversion/servers) will override the environment. * subversion/libsvn_ra_serf/serf.c (load_config): Load proxy configuration from http_proxy or https_proxy depending on the URI scheme. Let subversion-specific configuration override the environment. ]]] Index: subversion/libsvn_ra_serf/serf.c =================================================================== --- subversion/libsvn_ra_serf/serf.c (revision 1384088) +++ subversion/libsvn_ra_serf/serf.c (working copy) @@ -139,6 +139,7 @@ load_config(svn_ra_serf__session_t *session, { svn_config_t *config, *config_client; const char *server_group; + const char *proxy_uri_env = NULL; const char *proxy_host = NULL; const char *port_str = NULL; const char *timeout_str = NULL; @@ -181,6 +182,25 @@ load_config(svn_ra_serf__session_t *session, } } + if (svn_cstring_casecmp(session->session_url.scheme, "http") == 0) + proxy_uri_env = getenv("http_proxy"); + else if (svn_cstring_casecmp(session->session_url.scheme, "https") == 0) + proxy_uri_env = getenv("https_proxy"); + if (proxy_uri_env) + { + apr_uri_t proxy_uri; + if (apr_uri_parse(pool, proxy_uri_env, &proxy_uri)) + { + return svn_error_createf(SVN_ERR_RA_ILLEGAL_URL, NULL, + _("Invalid proxy URL '%s'"), + proxy_uri_env); + } + proxy_host = proxy_uri.hostname; + port_str = proxy_uri.port_str; + session->proxy_username = proxy_uri.user; + session->proxy_password = proxy_uri.password; + } + /* Use the default proxy-specific settings if and only if "http-proxy-exceptions" is not set to exclude this host. */ svn_config_get(config, &exceptions, SVN_CONFIG_SECTION_GLOBAL, @@ -193,17 +213,31 @@ load_config(svn_ra_serf__session_t *session, } if (! is_exception) { - /* Load the global proxy server settings, if set. */ - svn_config_get(config, &proxy_host, SVN_CONFIG_SECTION_GLOBAL, + /* Load the global proxy server settings, if set. Override all settings + * from the environment if any are set; don't mix settings from config + * and environment. */ + const char *config_proxy_host; + const char *config_port_str; + const char *config_proxy_username; + const char *config_proxy_password; + svn_config_get(config, &config_proxy_host, SVN_CONFIG_SECTION_GLOBAL, SVN_CONFIG_OPTION_HTTP_PROXY_HOST, NULL); - svn_config_get(config, &port_str, SVN_CONFIG_SECTION_GLOBAL, + svn_config_get(config, &config_port_str, SVN_CONFIG_SECTION_GLOBAL, SVN_CONFIG_OPTION_HTTP_PROXY_PORT, NULL); - svn_config_get(config, &session->proxy_username, + svn_config_get(config, &config_proxy_username, SVN_CONFIG_SECTION_GLOBAL, SVN_CONFIG_OPTION_HTTP_PROXY_USERNAME, NULL); - svn_config_get(config, &session->proxy_password, + svn_config_get(config, &config_proxy_password, SVN_CONFIG_SECTION_GLOBAL, SVN_CONFIG_OPTION_HTTP_PROXY_PASSWORD, NULL); + if (config_proxy_host || config_port_str + || config_proxy_username || config_proxy_password) + { + proxy_host = config_proxy_host; + port_str = config_port_str; + session->proxy_username = config_proxy_username; + session->proxy_password = config_proxy_password; + } } /* Load the global ssl settings, if set. */