Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use default timeouts for URLConnections #237

Merged
merged 1 commit into from
Dec 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}