Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-2266

UTF-8 chars unsupported in query params

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 5.2.1
    • None
    • HttpClient (classic)
    • None

    Description

      Trying to upgrade from HttpClient 4.5.13 to HttpClient 5.2.1 we have ONE test failing in a scary way.

      The test spins up a httpserver and we use httpclient to do a simple query with "scary Swedish chars in the query".

      Here is the call that works with httpclient 4.5.x and fails with httpclient 5.2.1

      try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
          URI uri = new URI("http://localhost:4711/v1/discovery/services?serviceName=Fräs");
          String s = client.execute(new HttpGet(uri), new HttpClientResponseHandler<String>() {
              @Override
              public String handleResponse(ClassicHttpResponse response) throws HttpException, IOException {
                  return EntityUtils.toString(response.getEntity(), "UTF-8");
              }
          });
          System.out.println(s);
      } catch (IOException e) {
          throw new RuntimeException(e);
      } 

       

      This code results in printout of (and of cause http status 400):

      <h1>Bad Message 400</h1><pre>reason: Bad Request</pre> 

      HttpClient 4.5 prints "whatever the server responded and whatever statuscode". If you give a dummy non existent path a 404 is retuned. But as soon as we switch back to 5.2.1 it responds 400 (without exception and the evil text "reason: Bad Request")

      Debugging though the inner workings of httpclient renders nothing out of the ordinary and if we URLEncode the "nasty" chars it works. 

       

      I.e. it works when request uri is done like:

      URI uri = new URI("http://localhost:9112/v1/discovery/services?"+ URLEncoder.encode("Fräs", "UTF-8"));

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            kkarlberg Karl-Johan Karlberg
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: