@@ -39,6 +39,7 @@ public class HttpRequest {
39
39
protected static final String CONTENT_LENGTH = "Content-Length" ;
40
40
41
41
private String url = null ;
42
+ private String proxyAuth = null ;
42
43
private MethodType method = null ;
43
44
protected FormatType httpContentType = null ;
44
45
protected byte [] httpContent = null ;
@@ -178,14 +179,20 @@ public HttpURLConnection buildHttpConnection() throws IOException, GeneralSecuri
178
179
HttpURLConnection httpConn = null ;
179
180
if (url .getProtocol ().equalsIgnoreCase ("https" )) {
180
181
if (sslSocketFactory != null ) {
181
- HttpsURLConnection httpsConn = (HttpsURLConnection )url .openConnection ();
182
+ Proxy proxy = getProxy ("HTTPS_PROXY" );
183
+ HttpsURLConnection httpsConn = (HttpsURLConnection )url .openConnection (proxy );
182
184
httpsConn .setSSLSocketFactory (sslSocketFactory );
183
185
httpConn = httpsConn ;
184
186
}
185
187
}
186
188
187
189
if (httpConn == null ) {
188
- httpConn = (HttpURLConnection )url .openConnection ();
190
+ Proxy proxy = getProxy ("HTTP_PROXY" );
191
+ httpConn = (HttpURLConnection )url .openConnection (proxy );
192
+ }
193
+
194
+ if (this .proxyAuth != null ) {
195
+ httpConn .setRequestProperty ("Proxy-Authorization" , proxyAuth );
189
196
}
190
197
191
198
httpConn .setRequestMethod (this .method .toString ());
@@ -231,6 +238,26 @@ private String getContentTypeValue(FormatType contentType, String encoding) {
231
238
return null ;
232
239
}
233
240
241
+ private Proxy getProxy (String env ) {
242
+ Proxy proxy = Proxy .NO_PROXY ;
243
+ String httpProxy = System .getenv (env );
244
+ if (httpProxy != null ) {
245
+ URL proxyUrl = new URL (httpProxy );
246
+ String userInfo = proxyUrl .getUserInfo ();
247
+ if (userInfo != null ) {
248
+ this .proxyAuth = "Basic " + Base64 .encode (userInfo );
249
+ }
250
+ String hostname = proxyUrl .getHost ();
251
+ int port = proxyUrl .getPort ();
252
+ if (port == -1 ) {
253
+ port = proxyUrl .getDefaultPort ();
254
+ }
255
+ SocketAddress addr = new InetSocketAddress (hostname , port );
256
+ proxy = new Proxy (Proxy .Type .HTTP , addr );
257
+ }
258
+ return proxy ;
259
+ }
260
+
234
261
public SSLSocketFactory getSslSocketFactory () {
235
262
return sslSocketFactory ;
236
263
}
0 commit comments