From e9ef98716f5c0b01da6f68180e4068d994ecc76c Mon Sep 17 00:00:00 2001 From: Athou Date: Tue, 31 Jul 2018 15:21:45 +0200 Subject: [PATCH] configurable user agent string (#825) --- config.dev.yml | 3 +++ config.yml.example | 3 +++ src/main/java/com/commafeed/CommaFeedConfiguration.java | 2 ++ src/main/java/com/commafeed/backend/HttpGetter.java | 5 ++++- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config.dev.yml b/config.dev.yml index a0d6d0e9..b8893b9b 100644 --- a/config.dev.yml +++ b/config.dev.yml @@ -67,6 +67,9 @@ app: # announcement string displayed on the main page announcement: + # user-agent string that will be used by the http client, leave empty for the default one + userAgent: + # Database connection # ------------------- # for MySQL diff --git a/config.yml.example b/config.yml.example index 65409954..0eb800df 100644 --- a/config.yml.example +++ b/config.yml.example @@ -68,6 +68,9 @@ app: # announcement string displayed on the main page announcement: + # user-agent string that will be used by the http client, leave empty for the default one + userAgent: + # Database connection # ------------------- # for MySQL diff --git a/src/main/java/com/commafeed/CommaFeedConfiguration.java b/src/main/java/com/commafeed/CommaFeedConfiguration.java index 14e5e17a..a18543c2 100644 --- a/src/main/java/com/commafeed/CommaFeedConfiguration.java +++ b/src/main/java/com/commafeed/CommaFeedConfiguration.java @@ -142,6 +142,8 @@ public class CommaFeedConfiguration extends Configuration { @Valid private String announcement; + private String userAgent; + public Date getUnreadThreshold() { int keepStatusDays = getKeepStatusDays(); return keepStatusDays > 0 ? DateUtils.addDays(new Date(), -1 * keepStatusDays) : null; diff --git a/src/main/java/com/commafeed/backend/HttpGetter.java b/src/main/java/com/commafeed/backend/HttpGetter.java index 66ea790b..03f4502a 100644 --- a/src/main/java/com/commafeed/backend/HttpGetter.java +++ b/src/main/java/com/commafeed/backend/HttpGetter.java @@ -70,7 +70,10 @@ public class HttpGetter { @Inject public HttpGetter(CommaFeedConfiguration config) { - this.userAgent = String.format("CommaFeed/%s (https://github.com/Athou/commafeed)", config.getVersion()); + this.userAgent = config.getApplicationSettings().getUserAgent(); + if (this.userAgent == null) { + this.userAgent = String.format("CommaFeed/%s (https://github.com/Athou/commafeed)", config.getVersion()); + } } public HttpResult getBinary(String url, int timeout) throws ClientProtocolException, IOException, NotModifiedException {