ApacheHttpClient does not respect already encoded QueryMap(encoded = true) · Issue #637 · OpenFeign/feign · GitHub
Skip to content

ApacheHttpClient does not respect already encoded QueryMap(encoded = true) #637

Closed

Description

@antechrestos

Hi,

Using default client I am able to do something like this

interface MyService {
     @RequestLine("GET /something")
     fun getConnection(
            @QueryMap(encoded = true) filter: Map<String, String?>) : MyObject
}

Instantiating client like this

val objectMapper = ObjectMapper()
val builder = Feign.builder()
                .encoder(JacksonEncoder(objectMapper))
                .decoder(JacksonDecoder(objectMapper))
val client = builder.target(MyService::class.java, "http://somewhere.org")

Calling service like this

val result = client.getConnection(mapOf("foo" to "/some/value"))

Call the service with the following url: http://somewhere.org/something?foo=/some/value which is what I wanted.

I tried to use ApacheHttpClient

val objectMapper = ObjectMapper()
val builder = Feign.builder()
                .client(ApacheHttpClient())
                ....

With this client, the url got is http://somewhere.org/something?foo=%2Fsome%2Fvalue

How can I maintain the @QueryMap(encoded = true) ?

Thank you 😄

Activity

  1. kdavisk6 commented on Mar 8, 2018

    @kdavisk6
    Member

    @antechrestos This appears to be a bug. Let's classify it as such. The documentation of @QueryMap does appear to indicate that when encoded = false the map values should not be encoded.

  2. kdavisk6 commented on Mar 9, 2018

    @kdavisk6
    Member

    I think I found the issue

    In the ApacheHttpClient it appears it is encoding all parameters all the time. I'll do some more research.

  3. antechrestos commented on Mar 9, 2018

    @antechrestos
    Author

    Thank you very much @kdavisk6

  4. fdirlikli commented on Mar 10, 2018

    @fdirlikli

    It looks like Apache Http Client is encoding the query parameters. Feign is using the RequestBuilder (Apache) to build the HttpUriRequest before making a request. build method within the RequestBuilder has the below code block handling the request parameters:

    
            if (this.parameters != null && !this.parameters.isEmpty()) {
                if (entityCopy != null || !"POST".equalsIgnoreCase(this.method) && !"PUT".equalsIgnoreCase(this.method)) {
                    try {
                        uriNotNull = (new URIBuilder(uriNotNull)).setCharset(this.charset).addParameters(this.parameters).build();
                    } catch (URISyntaxException var5) {
                        ;
                    }
                } else {
                    entityCopy = new UrlEncodedFormEntity(this.parameters, this.charset != null ? this.charset : HTTP.DEF_CONTENT_CHARSET);
                }
            }
    
            
    

    If you check the
    new URIBuilder(uriNotNull)).setCharset(this.charset).addParameters(this.parameters).build()
    addParameters mehod is handling the url encoding and there doesn't seem to be a way of changing this behaviour on the URIBuilder or RequestBuilder classes.
    A stackoverflow answer mentions using BasicHttpRequest instead of HttpUriRequest but I need to dig deeper to see if this is a viable solution.

  5. added
    bugUnexpected or incorrect behavior
    help wantedIssues we need help with tackling
    on Jul 26, 2018
  6. kdavisk6 commented on Dec 5, 2018

    @kdavisk6
    Member

    This should be fixed via #778, but if this comes again, please feel free to re-open.

  7. hendryluk commented on Jul 31, 2019

    @hendryluk

    This is still happening, v10.2.3

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

    bugUnexpected or incorrect behaviorhelp wantedIssues we need help with tackling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions