Extend control over HttpUtils.Request headers
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Johannes Frohnmeyer 2023-02-26 11:32:47 +01:00
parent b92f9c3d4f
commit d388ca8052
Signed by: Johannes
GPG Key ID: E76429612C2929F4

View File

@ -68,9 +68,9 @@ public class HttpUtils {
public Request(Method method, String url) throws URISyntaxException {
this.url = url.replace(" ", "%20");
this.builder = HttpRequest.newBuilder()
.uri(new URI(this.url))
.header("User-Agent", userAgent);
.uri(new URI(this.url));
this.method = method;
userAgent(userAgent);
}
public Request bearer(String token) {
@ -84,6 +84,15 @@ public class HttpUtils {
return this;
}
public Request setHeader(String name, String value) {
builder.setHeader(name, value);
return this;
}
public Request userAgent(String value) {
return setHeader("User-Agent", value);
}
public Request bodyString(String string) {
builder.header("Content-Type", "text/plain");
builder.method(method.name(), HttpRequest.BodyPublishers.ofString(string));