set user agent

This commit is contained in:
Jörg Prante 2021-02-03 14:53:08 +01:00
parent e66af3ab74
commit fb442a16fd
2 changed files with 8 additions and 1 deletions

View file

@ -1,6 +1,6 @@
group = org.xbib group = org.xbib
name = oai name = oai
version = 2.5.0 version = 2.5.1
gradle.wrapper.version = 6.6.1 gradle.wrapper.version = 6.6.1
xbib-content.version = 2.6.2 xbib-content.version = 2.6.2

View file

@ -39,6 +39,8 @@ public class OAIClient {
private final HttpClient httpClient; private final HttpClient httpClient;
private String userAgent;
public OAIClient(String baseURL) { public OAIClient(String baseURL) {
this.baseURL = baseURL; this.baseURL = baseURL;
this.httpClient = HttpClient.newBuilder() this.httpClient = HttpClient.newBuilder()
@ -46,6 +48,10 @@ public class OAIClient {
.build(); .build();
} }
void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}
/** /**
* This verb is used to retrieve information about a repository. * This verb is used to retrieve information about a repository.
* Some of the information returned is required as part of the OAI-PMH. * Some of the information returned is required as part of the OAI-PMH.
@ -61,6 +67,7 @@ public class OAIClient {
HttpRequest httpRequest = HttpRequest.newBuilder() HttpRequest httpRequest = HttpRequest.newBuilder()
.uri(URI.create(url.build().toExternalForm())) .uri(URI.create(url.build().toExternalForm()))
.header("accept", "utf-8") .header("accept", "utf-8")
.header("user-agent", userAgent != null ? userAgent : "xbib OAI client")
.GET() .GET()
.build(); .build();
HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString()); HttpResponse<String> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());