Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DefaultWebClient ignores baseUrl when setting URI_TEMPLATE_ATTRIBUTE #30027

Closed
christophejan opened this issue Feb 20, 2023 · 2 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@christophejan
Copy link
Contributor

When a WebClient request is build using both :

  1. a baseUrl
  2. a URI template

then baseUrl path seems ignored in the provided metrics tags

Example :

baseUrl = https://github.com/spring-projects/spring-boot/releases
uriTemplate = /tag/v{version}

Actual metrics tags :
uri = /tag/v{version}
client.name = github.com

I think that metrics tags should not ignore baseUrl path (i.e. /spring-projects/spring-boot/releases)

I've not checked (so I may be wrong), but I don't think there is the same behavior with RestTemplate.

spring-boot version : 2.7.8 / OpenJDK 64-Bit Server VM Temurin-17.0.3+7

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 20, 2023
@wilkinsona
Copy link
Member

The provider uses the URI_TEMPLATE_ATTRIBUTE which is set by Framework's DefaultRequestBodyUriSpec. The baseUrl is configured on the UriBuilderFactory which the URI spec uses:

attribute(URI_TEMPLATE_ATTRIBUTE, uriTemplate);
return uri(uriBuilderFactory.expand(uriTemplate, uriVariables));

The base URL is applied as part of the expand call. As you can see, this call is made after the attribute has been set. Things are done in this order as we do not want variables to have been applied to the template before the attribute's set as it would result in an explosion of possible tag values. To fix this, I think the base URL would have to be applied, the attribute set, and then the variable expansion performed.

We'll transfer this issue to the Framework team for further consideration.

@bclozel bclozel transferred this issue from spring-projects/spring-boot Feb 24, 2023
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Feb 24, 2023
@rstoyanchev rstoyanchev self-assigned this Feb 28, 2023
@rstoyanchev rstoyanchev changed the title DefaultWebClientExchangeTagsProvider ignore baseUrl path for request using a URI template DefaultWebClient ignores baseUrl when setting URI_TEMPLATE_ATTRIBUTE Mar 6, 2023
@rstoyanchev
Copy link
Contributor

Currently UriTemplateHandler exposes only methods to expand. If we add a method similar to UriComponents#toUriString that returns a String with the concatenated components, then this issue would be easy to address along the lines of #30027 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants