Commit ffa218d0 authored by Gabriel Allaigre's avatar Gabriel Allaigre Committed by Tim Olshansky

- Add proxy support (#193)

parent 4b9fe8a2
......@@ -7,6 +7,7 @@ import org.gitlab.api.http.Query;
import org.gitlab.api.models.*;
import java.io.*;
import java.net.Proxy;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
......@@ -35,6 +36,7 @@ public class GitlabAPI {
private final TokenType tokenType;
private AuthMethod authMethod;
private boolean ignoreCertificateErrors = false;
private Proxy proxy;
private int requestTimeout = 0;
private String userAgent = GitlabAPI.class.getCanonicalName() + "/" + System.getProperty("java.version");
......@@ -69,6 +71,11 @@ public class GitlabAPI {
return this;
}
public GitlabAPI proxy(Proxy proxy) {
this.proxy = proxy;
return this;
}
public int getRequestTimeout() {
return requestTimeout;
}
......@@ -90,6 +97,10 @@ public class GitlabAPI {
return ignoreCertificateErrors;
}
public Proxy getProxy() {
return proxy;
}
public URL getAPIUrl(String tailAPIUrl) throws IOException {
if (!tailAPIUrl.startsWith("/")) {
tailAPIUrl = "/" + tailAPIUrl;
......
......@@ -358,7 +358,7 @@ public class GitlabHTTPRequestor {
url = new URL(urlWithAuth);
}
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
HttpURLConnection connection = root.getProxy() != null ? (HttpURLConnection) url.openConnection(root.getProxy()) : (HttpURLConnection) url.openConnection();
if (apiToken != null && authMethod == AuthMethod.HEADER) {
connection.setRequestProperty(tokenType.getTokenHeaderName(), String.format(tokenType.getTokenHeaderFormat(), apiToken));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment