Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ private boolean cancel(Http1Client client) {
// DELETE {baseUri}/v2/apps/{appName}/{id}
private boolean cancel(Http1Client client, String appName, String id) {
try (var response = client
.delete("/v2/apps/" + Objects.requireNonNull(appName, "appName") + "/" + Objects.requireNonNull(id, "id"))
.delete()
.path("/v2/apps/" + Objects.requireNonNull(appName, "appName") + "/" + Objects.requireNonNull(id, "id"))
.request()) {
if (response.status().family() == SUCCESSFUL) {
if (LOGGER.isLoggable(DEBUG)) {
Expand Down Expand Up @@ -358,7 +359,8 @@ private Http1ClientResponse heartbeat(String appName,
String status,
Long lastDirtyTimestamp) {
var request = this.client // volatile read
.put("/v2/apps/" + Objects.requireNonNull(appName, "appName") + "/" + Objects.requireNonNull(id, "id"))
.put()
.path("/v2/apps/" + Objects.requireNonNull(appName, "appName") + "/" + Objects.requireNonNull(id, "id"))
.accept(APPLICATION_JSON);
if (status != null) {
request.queryParam("status", status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ void test() throws InterruptedException {
assertThat(this.ws.isRunning(), is(true));
Thread.sleep(500L); // wait for the registration/renewal attempt to happen in the background
try (var response = this.wc
.get("/v2/apps/" + ((EurekaRegistrationServerFeature)this.ws.prototype()
.get()
.path("/v2/apps/" + ((EurekaRegistrationServerFeature)this.ws.prototype()
.features()
.get(0))
.prototype()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@
*/
public interface ClientRequest<T extends ClientRequest<T>> {
/**
* Configure URI.
* Configure URI. A properly encoded URI is expected to be provided.
*
* @param uri uri to resolve against base URI, or to use if absolute
* @return updated request
*/
default T uri(String uri) {
return uri(URI.create(UriEncoding.encodeUri(uri)));
return uri(URI.create(uri));
}

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ default T path(String uri) {
T proxy(Proxy proxy);

/**
* Configure URI.
* Configure URI. A properly encoded URI is expected to be provided.
*
* @param uri uri to resolve against base URI, or to use if absolute
* @return updated request
Expand All @@ -91,6 +91,7 @@ default T path(String uri) {

/**
* Configure request URI. This always replaces the existing URI (even if base URI is configured).
* A properly encoded URI is expected to be provided.
*
* @param uri uri to resolve against base URI, or to use if absolute
* @return updated request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public T uri(String uri) {
if (uri.indexOf('{') > -1) {
this.uriTemplate = uri;
} else {
uri(URI.create(UriEncoding.encodeUri(uri)));
uri(URI.create(uri));
}

return identity();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -186,6 +186,8 @@ public ClientUri resolve(URI uri) {
}
if (uri.getHost() != null) {
uriBuilder.host(uri.getHost());
} else if (uri.getAuthority() != null) {
throw new IllegalArgumentException("Invalid authority: " + uri.getAuthority());
}
if (uri.getPort() != -1) {
uriBuilder.port(uri.getPort());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -59,7 +59,7 @@ default REQ get() {
}

/**
* Shortcut for post method with a path.
* Shortcut for post method with a path. A properly encoded URI is expected to be provided.
*
* @param uri path to resolve against base URI, or full URI
* @return a new request (not thread safe)
Expand All @@ -78,7 +78,7 @@ default REQ post() {
}

/**
* Shortcut for put method with a path.
* Shortcut for put method with a path. A properly encoded URI is expected to be provided.
*
* @param uri path to resolve against base URI, or full URI
* @return a new request (not thread safe)
Expand All @@ -97,7 +97,7 @@ default REQ put() {
}

/**
* Shortcut for delete method with a path.
* Shortcut for delete method with a path. A properly encoded URI is expected to be provided.
*
* @param uri path to resolve against base URI, or full URI
* @return a new request (not thread safe)
Expand All @@ -116,7 +116,7 @@ default REQ delete() {
}

/**
* Shortcut for head method with a path.
* Shortcut for head method with a path. A properly encoded URI is expected to be provided.
*
* @param uri path to resolve against base URI, or full URI
* @return a new request (not thread safe)
Expand All @@ -135,7 +135,7 @@ default REQ head() {
}

/**
* Shortcut for options method with a path.
* Shortcut for options method with a path. A properly encoded URI is expected to be provided.
*
* @param uri path to resolve against base URI, or full URI
* @return a new request (not thread safe)
Expand All @@ -154,7 +154,7 @@ default REQ options() {
}

/**
* Shortcut for trace method with a path.
* Shortcut for trace method with a path. A properly encoded URI is expected to be provided.
*
* @param uri path to resolve against base URI, or full URI
* @return a new request (not thread safe)
Expand All @@ -173,7 +173,7 @@ default REQ trace() {
}

/**
* Shortcut for patch method with a path.
* Shortcut for patch method with a path. A properly encoded URI is expected to be provided.
*
* @param uri path to resolve against base URI, or full URI
* @return a new request (not thread safe)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import io.helidon.http.media.MediaContextConfig;
import io.helidon.webclient.api.ClientConnection;
import io.helidon.webclient.api.ClientResponseTyped;
import io.helidon.webclient.api.ClientUri;
import io.helidon.webclient.api.HttpClientRequest;
import io.helidon.webclient.api.HttpClientResponse;
import io.helidon.webclient.api.Proxy;
Expand Down Expand Up @@ -119,6 +120,34 @@ void testRequestHeadersUpdated() {
client.closeResource();
}

@Test
void testInvalidHost() {
var client = WebClient.builder()
.baseUri(baseURI)
.build();
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> client.get("http://invalid_host:80/foo"));
assertThat(exception.getMessage(), startsWith("Invalid authority"));
}

@Test
void testUriMethodEncoding() {
var client = WebClient.builder()
.baseUri(baseURI)
.build();

//This query is intentionally invalid. We are testing if uri is not encoded by the client.
//It is expected to receive already properly encoded uri.
ClientUri uri = client.get("http://test.com/foo?test=value?").uri();
assertThat(uri.toString(), is("http://test.com:80/foo?test=value?"));

//Here query should be properly encoded, since query specific method was used.
uri = client.get("http://test.com/foo")
.queryParam("test", "value?")
.uri();
assertThat(uri.toString(), is("http://test.com:80/foo?test=value%3F"));
}

@Test
void testMaxHeaderSizeFail() {
Http1Client client = Http1Client.create(clientConfig -> clientConfig.baseUri(baseURI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static void multiHandler(ServerRequest req, ServerResponse res) {

@Test
void testRouteWithSpace() {
try (Http1ClientResponse response = client.get("/my path").request()) {
try (Http1ClientResponse response = client.get().path("/my path").request()) {

assertThat(response.status(), is(Status.OK_200));

Expand Down
Loading