Merge branch 'master' into 'master'

Add timeout for Http request

The timeout of HttpURLConnection is 0, which means the request would never return if either connection or read timeouts, and the code would never catch these exceptions.

This patch set explicit timeout value (10s for connection timeout and 40s for read timeout), so the code would catch and handle timeout exceptions as you would expect.

Best,

See merge request !117
This commit is contained in:
Daniel Martí 2015-08-11 00:20:17 +00:00
commit e895d1f0d3

View File

@ -71,6 +71,8 @@ public class HttpDownloader extends Downloader {
} else { } else {
connection = (HttpURLConnection) sourceUrl.openConnection(); connection = (HttpURLConnection) sourceUrl.openConnection();
} }
connection.setConnectTimeout(10000);
connection.setReadTimeout(40000);
} }
protected void doDownload() throws IOException, InterruptedException { protected void doDownload() throws IOException, InterruptedException {