spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

Provide a way to disable URL Encoding for PathVariables in HttpExchange clients

Open krzyk opened this issue 5 months ago • 1 comments

I have a HttpExchange client for e.g. BitBucket server, where the client looks like this:

public interface BitbucketClient {

    @GetExchange("/projects/{project}/repos/{repo}/raw/{path}?at={ref}")
    String raw(@PathVariable String project, @PathVariable String repo, @PathVariable String ref, @PathVariable String path);

}

path parameter can contain slashes (/) - because it is a path inside a repo (e.g. src/main/resources/file.txt) so encoding it breaks the API.

It would be good to have a param in PathVariable that would disable encoding (e.g. @PathVariable(encode = false) String path).

(this was reported earlier at #32041 but it stalled)

krzyk avatar Jun 09 '25 12:06 krzyk

It is not easy to do as proposed. Method parameter annotations are intentionally shared for client and server side (it's an HTTP Service contract neutral to either), but this would make it asymmetric. Also, no way to set per variable encoding options at the level of UriComponentsBuilder.

One way to do it is by passing a UriBuilderFactory that's configured accordingly, e.g. to encode the template only, or not at all (see encodingMode property on DefaultUriBuilderFactory). There is more context (and snippets) in the issue where support for this parameter was added #30935 (the docs don't cover this, something to correct).

rstoyanchev avatar Jun 11 '25 09:06 rstoyanchev

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Jun 20 '25 14:06 spring-projects-issues

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

spring-projects-issues avatar Jun 27 '25 14:06 spring-projects-issues