@ -291,39 +291,45 @@ public class Main {
/ * *
* Configure the JRE ' s standard HTTP based on < code > http_proxy < / code > .
* < p >
* The popular libcurl library honors the < code > http_proxy < / code >
* environment variable as a means of specifying an HTTP proxy for requests
* made behind a firewall . This is not natively recognized by the JRE , so
* this method can be used by command line utilities to configure the JRE
* before the first request is sent .
* The popular libcurl library honors the < code > http_proxy < / code > ,
* < code > https_proxy < / code > environment variables as a means of specifying
* an HTTP / S proxy for requests made behind a firewall . This is not natively
* recognized by the JRE , so this method can be used by command line
* utilities to configure the JRE before the first request is sent .
*
* @throws MalformedURLException
* the value in < code > http_proxy < / code > is unsupportable .
* the value in < code > http_proxy < / code > or
* < code > https_proxy < / code > is unsupportable .
* /
private static void configureHttpProxy ( ) throws MalformedURLException {
final String s = System . getenv ( "http_proxy" ) ; //$NON-NLS-1$
if ( s = = null | | s . equals ( "" ) ) //$NON-NLS-1$
return ;
for ( String protocol : new String [ ] { "http" , "https" } ) { //$NON-NLS-1$ //$NON-NLS-2$
final String s = System . getenv ( protocol + "_proxy" ) ; //$NON-NLS-1$
if ( s = = null | | s . equals ( "" ) ) //$NON-NLS-1$
return ;
final URL u = new URL ( ( s . indexOf ( "://" ) = = - 1 ) ? "http://" + s : s ) ; //$NON-NLS-1$ //$NON-NLS-2$
if ( ! "http" . equals ( u . getProtocol ( ) ) ) //$NON-NLS-1$
throw new MalformedURLException ( MessageFormat . format ( CLIText . get ( ) . invalidHttpProxyOnlyHttpSupported , s ) ) ;
final URL u = new URL (
( s . indexOf ( "://" ) = = - 1 ) ? protocol + "://" + s : s ) ; //$NON-NLS-1$ //$NON-NLS-2$
if ( ! u . getProtocol ( ) . startsWith ( "http" ) ) //$NON-NLS-1$
throw new MalformedURLException ( MessageFormat . format (
CLIText . get ( ) . invalidHttpProxyOnlyHttpSupported , s ) ) ;
final String proxyHost = u . getHost ( ) ;
final int proxyPort = u . getPort ( ) ;
final String proxyHost = u . getHost ( ) ;
final int proxyPort = u . getPort ( ) ;
System . setProperty ( "http.proxyHost" , proxyHost ) ; //$NON-NLS-1$
if ( proxyPort > 0 )
System . setProperty ( "http.proxyPort" , String . valueOf ( proxyPort ) ) ; //$NON-NLS-1$
System . setProperty ( protocol + ".proxyHost" , proxyHost ) ; //$NON-NLS-1$
if ( proxyPort > 0 )
System . setProperty ( protocol + ".proxyPort" , //$NON-NLS-1$
String . valueOf ( proxyPort ) ) ;
final String userpass = u . getUserInfo ( ) ;
if ( userpass ! = null & & userpass . contains ( ":" ) ) { //$NON-NLS-1$
final int c = userpass . indexOf ( ':' ) ;
final String user = userpass . substring ( 0 , c ) ;
final String pass = userpass . substring ( c + 1 ) ;
CachedAuthenticator
. add ( new CachedAuthenticator . CachedAuthentication (
proxyHost , proxyPort , user , pass ) ) ;
final String userpass = u . getUserInfo ( ) ;
if ( userpass ! = null & & userpass . contains ( ":" ) ) { //$NON-NLS-1$
final int c = userpass . indexOf ( ':' ) ;
final String user = userpass . substring ( 0 , c ) ;
final String pass = userpass . substring ( c + 1 ) ;
CachedAuthenticator . add (
new CachedAuthenticator . CachedAuthentication ( proxyHost ,
proxyPort , user , pass ) ) ;
}
}
}
}