Skip to content

Commit

Permalink
Use default timeouts for URLConnections
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Dec 1, 2015
1 parent 52727de commit 832e4f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/kohsuke/github/GitHubBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ public GitHubBuilder withRateLimitHandler(RateLimitHandler handler) {
public GitHubBuilder withProxy(final Proxy p) {
return withConnector(new HttpConnector() {
public HttpURLConnection connect(URL url) throws IOException {
return (HttpURLConnection) url.openConnection(p);
HttpURLConnection con = (HttpURLConnection) url.openConnection(p);
con.setConnectTimeout(HttpConnector.HTTP_CONNECT_TIMEOUT);
con.setReadTimeout(HttpConnector.HTTP_READ_TIMEOUT);
return con;
}
});
}
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/org/kohsuke/github/HttpConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.TimeUnit;

/**
* Pluggability for customizing HTTP request behaviors or using altogether different library.
Expand All @@ -23,7 +24,13 @@ public interface HttpConnector {
*/
HttpConnector DEFAULT = new HttpConnector() {
public HttpURLConnection connect(URL url) throws IOException {
return (HttpURLConnection) url.openConnection();
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setConnectTimeout(HTTP_CONNECT_TIMEOUT);
con.setReadTimeout(HTTP_READ_TIMEOUT);
return con;
}
};

int HTTP_CONNECT_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10);
int HTTP_READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(10);
}

0 comments on commit 832e4f3

Please sign in to comment.