Skip to content

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

Open
@krzyk

Description

@krzyk
Contributor

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)

Activity

rstoyanchev

rstoyanchev commented on Jun 11, 2025

@rstoyanchev
Contributor

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).

added
in: webIssues in web modules (web, webmvc, webflux, websocket)
on Jun 11, 2025
spring-projects-issues

spring-projects-issues commented on Jun 20, 2025

@spring-projects-issues
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: feedback-reminderWe've sent a reminder that we need additional information before we can continuestatus: waiting-for-feedbackWe need additional information before we can continuestatus: waiting-for-triageAn issue we've not yet triaged or decided on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @krzyk@rstoyanchev@spring-projects-issues

        Issue actions

          Provide a way to disable URL Encoding for PathVariables in HttpExchange clients · Issue #35016 · spring-projects/spring-framework