Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[icalendar] Add useragent parameter #17455

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bundles/org.openhab.binding.icalendar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Each `calendar` thing requires the following configuration parameters:
| `password` | The password for pulling the calendar. If set, the binding pulls the calendar using basic auth. Only valid in combination with `username`. | optional |
| `maxSize` | The maximum size of the iCal-file in Mebibytes. | mandatory (default available) |
| `authorizationCode` | The authorization code to permit the execution of embedded command tags. If set, the binding checks that the authorization code in the command tag matches before executing any commands. | optional |
| `userAgent` | Some providers require a specific user agent header. If left empty, the default Jetty header is used. | optional |

### Configuration for `eventfilter`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ public class ICalendarConfiguration {
public String url;
@Nullable
public String username;
@Nullable
public String userAgent;
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public void initialize() {
final int maxSize = maxSizeBD.intValue();
try {
regularPull = new PullJob(httpClient, new URI(currentConfiguration.url), currentConfiguration.username,
currentConfiguration.password, calendarFile, maxSize * 1048576, this);
currentConfiguration.password, calendarFile, maxSize * 1048576, this,
currentConfiguration.userAgent);
} catch (URISyntaxException e) {
throw new ConfigBrokenException(String.format(
"The URI '%s' for downloading the calendar contains syntax errors.", currentConfiguration.url));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class PullJob implements Runnable {
private final Logger logger = LoggerFactory.getLogger(PullJob.class);
private final int maxSize;
private final URI sourceURI;
private @Nullable final String userAgent;

/**
* Constructor of PullJob for creating a single pull of a calendar.
Expand All @@ -74,7 +75,7 @@ class PullJob implements Runnable {
* @param listener The listener that should be fired when update succeed.
*/
public PullJob(HttpClient httpClient, URI sourceURI, @Nullable String username, @Nullable String password,
File destination, int maxSize, CalendarUpdateListener listener) {
File destination, int maxSize, CalendarUpdateListener listener, @Nullable String userAgent) {
this.httpClient = httpClient;
this.sourceURI = sourceURI;
if (username != null && password != null) {
Expand All @@ -85,12 +86,16 @@ public PullJob(HttpClient httpClient, URI sourceURI, @Nullable String username,
this.destination = destination;
this.listener = listener;
this.maxSize = maxSize;
this.userAgent = userAgent;
}

@Override
public void run() {
final Request request = httpClient.newRequest(sourceURI).followRedirects(true).method(HttpMethod.GET)
.timeout(HTTP_TIMEOUT_SECS, TimeUnit.SECONDS);
if (userAgent != null && !userAgent.isBlank()) {
request.agent(userAgent);
}
final Authentication.Result currentAuthentication = authentication;
if (currentAuthentication != null) {
currentAuthentication.apply(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ thing-type.config.icalendar.calendar.refreshTime.label = Refresh Time
thing-type.config.icalendar.calendar.refreshTime.description = Frequency to scan for changes in minutes
thing-type.config.icalendar.calendar.url.label = URL
thing-type.config.icalendar.calendar.url.description = URL for downloading iCalendar events
thing-type.config.icalendar.calendar.userAgent.label = User Agent
thing-type.config.icalendar.calendar.userAgent.description = Some providers require a specific user agent header. If left empty, the default Jetty header is used.
thing-type.config.icalendar.calendar.username.label = User Name
thing-type.config.icalendar.calendar.username.description = User name for fetching the calendar (usable in combination with password in HTTP basic auth)
thing-type.config.icalendar.eventfilter.datetimeEnd.label = End
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<label>Command Authorization Code</label>
<description>Authorization Code to allow the execution of Command Tags (may be empty)</description>
</parameter>
<parameter name="userAgent" type="text" required="false">
<label>User Agent</label>
<description>Some providers require a specific user agent header. If left empty, the default Jetty header is used.</description>
<advanced>true</advanced>
</parameter>
</config-description>

</bridge-type>
Expand Down