Skip to content

Commit 9d4370d

Browse files
authored
Merge pull request #1 from christolis/rss-fix-agent
Add client user headers to RSS client
2 parents f809cb4 + 777a367 commit 9d4370d

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

application/config.json.template

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@
173173
}
174174
],
175175
"fallbackChannelPattern": "java-news-and-changes",
176-
"pollIntervalInMinutes": 10
176+
"pollIntervalInMinutes": 10,
177+
"clientRequestHeaders": {
178+
"User-Agent": "Mozilla/5.0",
179+
"Accept": "application/xhtml+xml,application/xml;",
180+
"Accept-Language": "en-US,en;"
181+
}
177182
},
178183
"memberCountCategoryPattern": "Info"
179184
}

application/src/main/java/org/togetherjava/tjbot/config/RSSFeedsConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44

55
import java.util.List;
6+
import java.util.Map;
67
import java.util.Objects;
78

89
/**
@@ -16,7 +17,8 @@
1617
public record RSSFeedsConfig(@JsonProperty(value = "feeds", required = true) List<RSSFeed> feeds,
1718
@JsonProperty(value = "fallbackChannelPattern",
1819
required = true) String fallbackChannelPattern,
19-
@JsonProperty(value = "pollIntervalInMinutes", required = true) int pollIntervalInMinutes) {
20+
@JsonProperty(value = "pollIntervalInMinutes", required = true) int pollIntervalInMinutes,
21+
@JsonProperty(value = "clientRequestHeaders") Map<String, String> clientRequestHeaders) {
2022

2123
/**
2224
* Constructs a new {@link RSSFeedsConfig}.

application/src/main/java/org/togetherjava/tjbot/features/rss/RSSHandlerRoutine.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ public RSSHandlerRoutine(Config config, Database database) {
103103
});
104104

105105
this.rssReader = new RssReader();
106-
this.rssReader.setUserAgent("Mozilla/5.0");
107-
this.rssReader.addHeader("Accept", "application/xhtml+xml,application/xml;");
108-
this.rssReader.addHeader("Accept-Language", "en-US,en;");
106+
this.config.clientRequestHeaders().forEach(this.rssReader::addHeader);
109107
}
110108

111109
@Override

0 commit comments

Comments
 (0)