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

Charset omitted from UrlEncodedFormEntity Content-Type header

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 4.0 Final
    • 4.0.1, 4.1 Alpha1
    • HttpClient (classic)
    • None
    • all

    Description

      UrlEncodedFormEntity sets the Content-Type header to:
      "application/x-www-form-urlencoded"

      It should set the header to:
      "application/x-www-form-urlencoded; charset=" + charset

      As a result, content can be misinterpreted by the recipient (e.g. if the entity content includes multibyte Unicode characters encoded with the "UTF-8" charset).

      For a correct example of specifying the charset in the Content-Type header, see StringEntity.java.

      Here's the fix:

      public UrlEncodedFormEntity (
      final List <? extends NameValuePair> parameters,
      final String encoding) throws UnsupportedEncodingException

      { super(URLEncodedUtils.format(parameters, encoding), encoding); - setContentType(URLEncodedUtils.CONTENT_TYPE); + setContentType(URLEncodedUtils.CONTENT_TYPE + HTTP.CHARSET_PARAM + + (encoding != null ? encoding : HTTP.DEFAULT_CONTENT_CHARSET)); }

      public UrlEncodedFormEntity (
      final List <? extends NameValuePair> parameters) throws UnsupportedEncodingException

      { - super(URLEncodedUtils.format(parameters, HTTP.DEFAULT_CONTENT_CHARSET), - HTTP.DEFAULT_CONTENT_CHARSET); - setContentType(URLEncodedUtils.CONTENT_TYPE); + this(parameters, HTTP.DEFAULT_CONTENT_CHARSET); }

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            jaredjacobs Jared Jacobs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified

                Slack

                  Issue deployment