forked from Archives/Athou_commafeed
dynamic user agent string
This commit is contained in:
@@ -175,7 +175,7 @@ public class CommaFeedApplication extends Application<CommaFeedConfiguration> {
|
|||||||
OPMLExporter opmlExporter = new OPMLExporter(feedCategoryDAO, feedSubscriptionDAO);
|
OPMLExporter opmlExporter = new OPMLExporter(feedCategoryDAO, feedSubscriptionDAO);
|
||||||
|
|
||||||
// Feed fetching/parsing
|
// Feed fetching/parsing
|
||||||
HttpGetter httpGetter = new HttpGetter();
|
HttpGetter httpGetter = new HttpGetter(applicationPropertiesService);
|
||||||
FeedParser feedParser = new FeedParser();
|
FeedParser feedParser = new FeedParser();
|
||||||
FaviconFetcher faviconFetcher = new FaviconFetcher(httpGetter);
|
FaviconFetcher faviconFetcher = new FaviconFetcher(httpGetter);
|
||||||
FeedFetcher feedFetcher = new FeedFetcher(feedParser, httpGetter);
|
FeedFetcher feedFetcher = new FeedFetcher(feedParser, httpGetter);
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ import org.apache.http.impl.client.HttpClients;
|
|||||||
import org.apache.http.protocol.HttpContext;
|
import org.apache.http.protocol.HttpContext;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import com.commafeed.backend.service.ApplicationPropertiesService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Smart HTTP getter: handles gzip, ssl, last modified and etag headers
|
* Smart HTTP getter: handles gzip, ssl, last modified and etag headers
|
||||||
*
|
*
|
||||||
@@ -51,7 +53,6 @@ import org.apache.http.util.EntityUtils;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class HttpGetter {
|
public class HttpGetter {
|
||||||
|
|
||||||
private static final String USER_AGENT = "CommaFeed/1.0 (http://www.commafeed.com)";
|
|
||||||
private static final String ACCEPT_LANGUAGE = "en";
|
private static final String ACCEPT_LANGUAGE = "en";
|
||||||
private static final String PRAGMA_NO_CACHE = "No-cache";
|
private static final String PRAGMA_NO_CACHE = "No-cache";
|
||||||
private static final String CACHE_CONTROL_NO_CACHE = "no-cache";
|
private static final String CACHE_CONTROL_NO_CACHE = "no-cache";
|
||||||
@@ -92,6 +93,12 @@ public class HttpGetter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final String userAgent;
|
||||||
|
|
||||||
|
public HttpGetter(ApplicationPropertiesService applicationPropertiesService) {
|
||||||
|
this.userAgent = String.format("CommaFeed/%s (https://www.commafeed.com)", applicationPropertiesService.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
public HttpResult getBinary(String url, int timeout) throws ClientProtocolException, IOException, NotModifiedException {
|
public HttpResult getBinary(String url, int timeout) throws ClientProtocolException, IOException, NotModifiedException {
|
||||||
return getBinary(url, null, null, timeout);
|
return getBinary(url, null, null, timeout);
|
||||||
}
|
}
|
||||||
@@ -124,7 +131,7 @@ public class HttpGetter {
|
|||||||
httpget.addHeader(HttpHeaders.ACCEPT_LANGUAGE, ACCEPT_LANGUAGE);
|
httpget.addHeader(HttpHeaders.ACCEPT_LANGUAGE, ACCEPT_LANGUAGE);
|
||||||
httpget.addHeader(HttpHeaders.PRAGMA, PRAGMA_NO_CACHE);
|
httpget.addHeader(HttpHeaders.PRAGMA, PRAGMA_NO_CACHE);
|
||||||
httpget.addHeader(HttpHeaders.CACHE_CONTROL, CACHE_CONTROL_NO_CACHE);
|
httpget.addHeader(HttpHeaders.CACHE_CONTROL, CACHE_CONTROL_NO_CACHE);
|
||||||
httpget.addHeader(HttpHeaders.USER_AGENT, USER_AGENT);
|
httpget.addHeader(HttpHeaders.USER_AGENT, userAgent);
|
||||||
|
|
||||||
if (lastModified != null) {
|
if (lastModified != null) {
|
||||||
httpget.addHeader(HttpHeaders.IF_MODIFIED_SINCE, lastModified);
|
httpget.addHeader(HttpHeaders.IF_MODIFIED_SINCE, lastModified);
|
||||||
|
|||||||
Reference in New Issue
Block a user