Skip to content

Commit fa4c120

Browse files
author
Vladimir Orekhov
committed
Add proxy
1 parent 423c515 commit fa4c120

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

libs/sparkpost-lib/src/main/java/com/sparkpost/Client.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
package com.sparkpost;
33

4+
import java.net.InetSocketAddress;
5+
import java.net.Proxy;
46
import java.util.ArrayList;
57
import java.util.List;
68

@@ -107,6 +109,16 @@ public int getHttpConnectTimeout() {
107109
return this.httpConnectTimeout;
108110
}
109111

112+
private Proxy proxy = null;
113+
114+
public void setProxy(String hostname, int port) {
115+
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(hostname, port));
116+
}
117+
118+
public Proxy getProxy() {
119+
return this.proxy;
120+
}
121+
110122
/**
111123
* Sets a specified timeout value, in milliseconds, to be used
112124
* when opening a communications link to the resource referenced

libs/sparkpost-lib/src/main/java/com/sparkpost/transport/RestConnection.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ private HttpURLConnection createConnectionObject(String path, Method method) thr
115115
// Retrieve the URLConnection object (but doesn't actually connect):
116116
// (HttpUrlConnection doesn't connect to the server until we've
117117
// got one of its streams)
118-
conn = (HttpURLConnection) url.openConnection();
118+
if(this.client.getProxy() != null) {
119+
System.out.println("Using proxy here!");
120+
conn = (HttpURLConnection) url.openConnection(this.client.getProxy());
121+
} else {
122+
conn = (HttpURLConnection) url.openConnection();
123+
}
119124

120125
conn.setConnectTimeout(this.client.getHttpConnectTimeout());
121126
conn.setReadTimeout(this.client.getHttpReadTimeout());

0 commit comments

Comments
 (0)