From c3d65df2e0e3d7596995fff5726e0042b43976b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Thu, 8 Aug 2019 09:18:57 +0200 Subject: [PATCH] fix mutator() calls in URL building --- gradle.properties | 4 ++-- .../main/java/org/xbib/netty/http/client/Request.java | 11 +++++------ .../org/xbib/netty/http/server/test/EndpointTest.java | 5 +++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index 91f0e9e..c46baf6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,13 @@ group = org.xbib name = netty-http -version = 4.1.38.1 +version = 4.1.38.2 # main packages netty.version = 4.1.38.Final tcnative.version = 2.0.25.Final # common -xbib-net-url.version = 1.3.3 +xbib-net-url.version = 1.3.4 # server bouncycastle.version = 1.61 diff --git a/netty-http-client/src/main/java/org/xbib/netty/http/client/Request.java b/netty-http-client/src/main/java/org/xbib/netty/http/client/Request.java index 598e253..ddf513f 100644 --- a/netty-http-client/src/main/java/org/xbib/netty/http/client/Request.java +++ b/netty-http-client/src/main/java/org/xbib/netty/http/client/Request.java @@ -39,6 +39,7 @@ import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.CompletableFuture; /** @@ -520,9 +521,6 @@ public class Request { if (url == null) { throw new IllegalStateException("URL not set"); } - if (url.getHost() == null) { - throw new IllegalStateException("host in URL not defined: " + url); - } // form parameters if (!formParameters.isEmpty()) { try { @@ -533,9 +531,10 @@ public class Request { } } // attach user query parameters to URL - URL.Builder builder = url.newBuilder(); - uriParameters.forEach((k, v) -> v.forEach(value -> builder.queryParam(k, value))); - url = builder.build(); + URL.Builder mutator = url.mutator(); + uriParameters.forEach((k, v) -> v.forEach(value -> mutator.queryParam(k, value))); + url = mutator.build(); + Objects.requireNonNull(url.getHost()); // let Netty's query string decoder/encoder work over the URL to add parameters given implicitly in url() String path = url.getPath(); String query = url.getQuery(); diff --git a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/EndpointTest.java b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/EndpointTest.java index 0c2fee9..f8a8784 100644 --- a/netty-http-server/src/test/java/org/xbib/netty/http/server/test/EndpointTest.java +++ b/netty-http-server/src/test/java/org/xbib/netty/http/server/test/EndpointTest.java @@ -225,7 +225,7 @@ class EndpointTest { client.execute(request).get(); Request request1 = Request.get().setVersion(HttpVersion.HTTP_1_1) .url(server.getServerConfig().getAddress().base() - .resolve("/static1/test1.txt").newBuilder().fragment("frag").build()) + .resolve("/static1/test1.txt").mutator().fragment("frag").build()) .build() .setResponseListener(resp -> { if (resp.getStatus().getCode() == HttpResponseStatus.OK.code()) { @@ -237,7 +237,8 @@ class EndpointTest { }); client.execute(request1).get(); Request request2 = Request.get().setVersion(HttpVersion.HTTP_1_1) - .url(server.getServerConfig().getAddress().base().resolve("/static2/test2.txt")) + .url(server.getServerConfig().getAddress().base() + .resolve("/static2/test2.txt")) .content("{\"a\":\"b\"}","application/json") .build() .setResponseListener(resp -> {