From 51eda57618098fda2c6de9f33565cf6f5c6f4bd8 Mon Sep 17 00:00:00 2001 From: Athou Date: Thu, 14 Aug 2014 16:19:06 +0200 Subject: [PATCH] dynamic user agent string --- src/main/java/com/commafeed/CommaFeedApplication.java | 2 +- src/main/java/com/commafeed/backend/HttpGetter.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/commafeed/CommaFeedApplication.java b/src/main/java/com/commafeed/CommaFeedApplication.java index e727445b..8d6b19da 100644 --- a/src/main/java/com/commafeed/CommaFeedApplication.java +++ b/src/main/java/com/commafeed/CommaFeedApplication.java @@ -175,7 +175,7 @@ public class CommaFeedApplication extends Application { OPMLExporter opmlExporter = new OPMLExporter(feedCategoryDAO, feedSubscriptionDAO); // Feed fetching/parsing - HttpGetter httpGetter = new HttpGetter(); + HttpGetter httpGetter = new HttpGetter(applicationPropertiesService); FeedParser feedParser = new FeedParser(); FaviconFetcher faviconFetcher = new FaviconFetcher(httpGetter); FeedFetcher feedFetcher = new FeedFetcher(feedParser, httpGetter); diff --git a/src/main/java/com/commafeed/backend/HttpGetter.java b/src/main/java/com/commafeed/backend/HttpGetter.java index abdfcf38..83466c13 100644 --- a/src/main/java/com/commafeed/backend/HttpGetter.java +++ b/src/main/java/com/commafeed/backend/HttpGetter.java @@ -44,6 +44,8 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.protocol.HttpContext; import org.apache.http.util.EntityUtils; +import com.commafeed.backend.service.ApplicationPropertiesService; + /** * Smart HTTP getter: handles gzip, ssl, last modified and etag headers * @@ -51,7 +53,6 @@ import org.apache.http.util.EntityUtils; @Slf4j 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 PRAGMA_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 { return getBinary(url, null, null, timeout); } @@ -124,7 +131,7 @@ public class HttpGetter { httpget.addHeader(HttpHeaders.ACCEPT_LANGUAGE, ACCEPT_LANGUAGE); httpget.addHeader(HttpHeaders.PRAGMA, PRAGMA_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) { httpget.addHeader(HttpHeaders.IF_MODIFIED_SINCE, lastModified);