From fb442a16fdce8a50c58b9702f77b7aa05e7b5cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Wed, 3 Feb 2021 14:53:08 +0100 Subject: [PATCH] set user agent --- gradle.properties | 2 +- .../src/main/java/org/xbib/oai/client/OAIClient.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index e450cfe..b27d144 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib name = oai -version = 2.5.0 +version = 2.5.1 gradle.wrapper.version = 6.6.1 xbib-content.version = 2.6.2 diff --git a/oai-client/src/main/java/org/xbib/oai/client/OAIClient.java b/oai-client/src/main/java/org/xbib/oai/client/OAIClient.java index d6ac1a4..015a018 100644 --- a/oai-client/src/main/java/org/xbib/oai/client/OAIClient.java +++ b/oai-client/src/main/java/org/xbib/oai/client/OAIClient.java @@ -39,6 +39,8 @@ public class OAIClient { private final HttpClient httpClient; + private String userAgent; + public OAIClient(String baseURL) { this.baseURL = baseURL; this.httpClient = HttpClient.newBuilder() @@ -46,6 +48,10 @@ public class OAIClient { .build(); } + void setUserAgent(String userAgent) { + this.userAgent = userAgent; + } + /** * This verb is used to retrieve information about a repository. * Some of the information returned is required as part of the OAI-PMH. @@ -61,6 +67,7 @@ public class OAIClient { HttpRequest httpRequest = HttpRequest.newBuilder() .uri(URI.create(url.build().toExternalForm())) .header("accept", "utf-8") + .header("user-agent", userAgent != null ? userAgent : "xbib OAI client") .GET() .build(); HttpResponse httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());