mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
set different http timeouts based on what we are fetching
This commit is contained in:
@@ -59,9 +59,9 @@ public class HttpGetter {
|
|||||||
|
|
||||||
private static final X509HostnameVerifier VERIFIER = new DefaultHostnameVerifier();
|
private static final X509HostnameVerifier VERIFIER = new DefaultHostnameVerifier();
|
||||||
|
|
||||||
public HttpResult getBinary(String url) throws ClientProtocolException,
|
public HttpResult getBinary(String url, int timeout) throws ClientProtocolException,
|
||||||
IOException, NotModifiedException {
|
IOException, NotModifiedException {
|
||||||
return getBinary(url, null, null);
|
return getBinary(url, null, null, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,12 +78,12 @@ public class HttpGetter {
|
|||||||
* @throws NotModifiedException
|
* @throws NotModifiedException
|
||||||
* if the url hasn't changed since we asked for it last time
|
* if the url hasn't changed since we asked for it last time
|
||||||
*/
|
*/
|
||||||
public HttpResult getBinary(String url, String lastModified, String eTag)
|
public HttpResult getBinary(String url, String lastModified, String eTag, int timeout)
|
||||||
throws ClientProtocolException, IOException, NotModifiedException {
|
throws ClientProtocolException, IOException, NotModifiedException {
|
||||||
HttpResult result = null;
|
HttpResult result = null;
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
HttpClient client = newClient();
|
HttpClient client = newClient(timeout);
|
||||||
try {
|
try {
|
||||||
HttpGet httpget = new HttpGet(url);
|
HttpGet httpget = new HttpGet(url);
|
||||||
httpget.addHeader(HttpHeaders.ACCEPT_LANGUAGE, "en");
|
httpget.addHeader(HttpHeaders.ACCEPT_LANGUAGE, "en");
|
||||||
@@ -191,7 +191,7 @@ public class HttpGetter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HttpClient newClient() {
|
public static HttpClient newClient(int timeout) {
|
||||||
DefaultHttpClient client = new SystemDefaultHttpClient();
|
DefaultHttpClient client = new SystemDefaultHttpClient();
|
||||||
|
|
||||||
SSLSocketFactory ssf = new SSLSocketFactory(SSL_CONTEXT, VERIFIER);
|
SSLSocketFactory ssf = new SSLSocketFactory(SSL_CONTEXT, VERIFIER);
|
||||||
@@ -202,8 +202,8 @@ public class HttpGetter {
|
|||||||
HttpParams params = client.getParams();
|
HttpParams params = client.getParams();
|
||||||
HttpClientParams.setCookiePolicy(params, CookiePolicy.IGNORE_COOKIES);
|
HttpClientParams.setCookiePolicy(params, CookiePolicy.IGNORE_COOKIES);
|
||||||
HttpProtocolParams.setContentCharset(params, "UTF-8");
|
HttpProtocolParams.setContentCharset(params, "UTF-8");
|
||||||
HttpConnectionParams.setConnectionTimeout(params, 20000);
|
HttpConnectionParams.setConnectionTimeout(params, timeout);
|
||||||
HttpConnectionParams.setSoTimeout(params, 20000);
|
HttpConnectionParams.setSoTimeout(params, timeout);
|
||||||
client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0,
|
client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0,
|
||||||
false));
|
false));
|
||||||
return new DecompressingHttpClient(client);
|
return new DecompressingHttpClient(client);
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class FaviconFetcher {
|
|||||||
|
|
||||||
private static long MIN_ICON_LENGTH = 100;
|
private static long MIN_ICON_LENGTH = 100;
|
||||||
private static long MAX_ICON_LENGTH = 20000;
|
private static long MAX_ICON_LENGTH = 20000;
|
||||||
|
private static int TIMEOUT = 4000;
|
||||||
|
|
||||||
protected static List<String> ICON_MIMETYPES = Arrays.asList(
|
protected static List<String> ICON_MIMETYPES = Arrays.asList(
|
||||||
"image/x-icon", "image/vnd.microsoft.icon", "image/ico",
|
"image/x-icon", "image/vnd.microsoft.icon", "image/ico",
|
||||||
@@ -70,7 +71,7 @@ public class FaviconFetcher {
|
|||||||
try {
|
try {
|
||||||
url = FeedUtils.removeTrailingSlash(url) + "/favicon.ico";
|
url = FeedUtils.removeTrailingSlash(url) + "/favicon.ico";
|
||||||
log.debug("getting root icon at {}", url);
|
log.debug("getting root icon at {}", url);
|
||||||
HttpResult result = getter.getBinary(url);
|
HttpResult result = getter.getBinary(url, TIMEOUT);
|
||||||
bytes = result.getContent();
|
bytes = result.getContent();
|
||||||
contentType = result.getContentType();
|
contentType = result.getContentType();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -118,7 +119,7 @@ public class FaviconFetcher {
|
|||||||
|
|
||||||
Document doc = null;
|
Document doc = null;
|
||||||
try {
|
try {
|
||||||
HttpResult result = getter.getBinary(url);
|
HttpResult result = getter.getBinary(url, TIMEOUT);
|
||||||
doc = Jsoup.parse(new String(result.getContent()), url);
|
doc = Jsoup.parse(new String(result.getContent()), url);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug("Failed to retrieve page to find icon");
|
log.debug("Failed to retrieve page to find icon");
|
||||||
@@ -144,7 +145,7 @@ public class FaviconFetcher {
|
|||||||
byte[] bytes = null;
|
byte[] bytes = null;
|
||||||
String contentType = null;
|
String contentType = null;
|
||||||
try {
|
try {
|
||||||
HttpResult result = getter.getBinary(href);
|
HttpResult result = getter.getBinary(href, TIMEOUT);
|
||||||
bytes = result.getContent();
|
bytes = result.getContent();
|
||||||
contentType = result.getContentType();
|
contentType = result.getContentType();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -37,12 +37,13 @@ public class FeedFetcher {
|
|||||||
log.debug("Fetching feed {}", feedUrl);
|
log.debug("Fetching feed {}", feedUrl);
|
||||||
FetchedFeed fetchedFeed = null;
|
FetchedFeed fetchedFeed = null;
|
||||||
|
|
||||||
HttpResult result = getter.getBinary(feedUrl, lastModified, eTag);
|
int timeout = 20000;
|
||||||
|
HttpResult result = getter.getBinary(feedUrl, lastModified, eTag, timeout);
|
||||||
if (extractFeedUrlFromHtml) {
|
if (extractFeedUrlFromHtml) {
|
||||||
String extractedUrl = extractFeedUrl(
|
String extractedUrl = extractFeedUrl(
|
||||||
StringUtils.newStringUtf8(result.getContent()), feedUrl);
|
StringUtils.newStringUtf8(result.getContent()), feedUrl);
|
||||||
if (org.apache.commons.lang.StringUtils.isNotBlank(extractedUrl)) {
|
if (org.apache.commons.lang.StringUtils.isNotBlank(extractedUrl)) {
|
||||||
result = getter.getBinary(extractedUrl, lastModified, eTag);
|
result = getter.getBinary(extractedUrl, lastModified, eTag, timeout);
|
||||||
feedUrl = extractedUrl;
|
feedUrl = extractedUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class SubscriptionHandler {
|
|||||||
post.setHeader(HttpHeaders.CONTENT_TYPE,
|
post.setHeader(HttpHeaders.CONTENT_TYPE,
|
||||||
MediaType.APPLICATION_FORM_URLENCODED);
|
MediaType.APPLICATION_FORM_URLENCODED);
|
||||||
|
|
||||||
HttpClient client = HttpGetter.newClient();
|
HttpClient client = HttpGetter.newClient(20000);
|
||||||
try {
|
try {
|
||||||
post.setEntity(new UrlEncodedFormEntity(nvp));
|
post.setEntity(new UrlEncodedFormEntity(nvp));
|
||||||
HttpResponse response = client.execute(post);
|
HttpResponse response = client.execute(post);
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class ServerREST extends AbstractResourceREST {
|
|||||||
|
|
||||||
url = FeedUtils.imageProxyDecoder(url);
|
url = FeedUtils.imageProxyDecoder(url);
|
||||||
try {
|
try {
|
||||||
HttpResult result = httpGetter.getBinary(url);
|
HttpResult result = httpGetter.getBinary(url, 20000);
|
||||||
return Response.ok(result.getContent()).build();
|
return Response.ok(result.getContent()).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Response.status(Status.SERVICE_UNAVAILABLE)
|
return Response.status(Status.SERVICE_UNAVAILABLE)
|
||||||
|
|||||||
Reference in New Issue
Block a user