Skip to content

Commit

Permalink
Webclient uses relative uri in request instead of full uri (#2309)
Browse files Browse the repository at this point in the history
Webclient uses relative uri in request instead of full uri

Signed-off-by: David Kral <david.k.kral@oracle.com>
  • Loading branch information
Verdent authored Sep 3, 2020
1 parent 5f40767 commit 38e3fe8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void testTracingSuccess() throws ExecutionException, InterruptedException {
assertThat(wsSpan.operationName(), is("HTTP Request"));
tags = wsSpan.tags();
assertThat(tags.get(Tags.HTTP_METHOD.getKey()), is("GET"));
assertThat(tags.get(Tags.HTTP_URL.getKey()), is(uri));
assertThat(tags.get(Tags.HTTP_URL.getKey()), is("/greet"));
assertThat(tags.get(Tags.HTTP_STATUS.getKey()), is(200));
assertThat(tags.get(Tags.COMPONENT.getKey()), is("helidon-webserver"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,8 @@ private <T> Single<T> invokeWithEntity(Flow.Publisher<DataChunk> requestEntity,

private Single<WebClientResponse> invoke(Flow.Publisher<DataChunk> requestEntity) {
this.uri = prepareFinalURI();
//Relative URI is used in request if no proxy set
URI requestURI = proxy == Proxy.noProxy() ? prepareRelativeURI() : uri;
if (requestId == null) {
requestId = REQUEST_NUMBER.incrementAndGet();
}
Expand All @@ -519,7 +521,7 @@ private Single<WebClientResponse> invoke(Flow.Publisher<DataChunk> requestEntity
HttpHeaders headers = toNettyHttpHeaders();
DefaultHttpRequest request = new DefaultHttpRequest(toNettyHttpVersion(httpVersion),
toNettyMethod(method),
uri.toASCIIString(),
requestURI.toASCIIString(),
headers);
HttpUtil.isKeepAlive(request);

Expand Down Expand Up @@ -631,6 +633,29 @@ private URI prepareFinalURI() {
return this.uri;
}

private URI prepareRelativeURI() {
try {
String path = this.path.toString();
String query = this.uri.getQuery();
String fragment = this.uri.getFragment();
if (skipUriEncoding) {
StringBuilder sb = new StringBuilder();
sb.append(path);
if (query != null) {
sb.append('?');
sb.append(query);
} else if (fragment != null) {
sb.append('#');
sb.append(fragment);
}
return URI.create(sb.toString());
}
return new URI(null, null, null, -1, path, query, fragment);
} catch (URISyntaxException e) {
throw new WebClientException("Could not create URI instance for the request.", e);
}
}

private String resolveQuery() {
String queries = "";
for (Map.Entry<String, List<String>> entry : queryParams.toMap().entrySet()) {
Expand Down

0 comments on commit 38e3fe8

Please sign in to comment.