You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Thomas Kruse (JIRA)" <ji...@apache.org> on 2013/01/16 15:32:13 UTC

[jira] [Created] (HTTPCORE-329) EntityUtils.toString uses wrong charset if no content-type is provided by server

Thomas Kruse created HTTPCORE-329:
-------------------------------------

             Summary: EntityUtils.toString uses wrong charset if no content-type is provided by server
                 Key: HTTPCORE-329
                 URL: https://issues.apache.org/jira/browse/HTTPCORE-329
             Project: HttpComponents HttpCore
          Issue Type: Bug
          Components: HttpCore
    Affects Versions: 4.2.1
            Reporter: Thomas Kruse


The method
{code}
public static String toString( final HttpEntity entity, final String defaultCharset)
{code}
delegates to
{code}
public static String toString( final HttpEntity entity, final Charset defaultCharset) {
...
   ContentType contentType = ContentType.getOrDefault(entity);
   Charset charset = contentType.getCharset();
   if (charset == null) {
        charset = defaultCharset;
   }
...
}
{code}

This method uses a default content type which has a charset set(!)
{code}
public static ContentType getOrDefault(final HttpEntity entity) throws ParseException {
        ContentType contentType = get(entity);
        return contentType != null ? contentType : DEFAULT_TEXT;
    }
{code}

{code}
public static final ContentType DEFAULT_TEXT = TEXT_PLAIN;

public static final ContentType TEXT_PLAIN = create( "text/plain", Consts.ISO_8859_1);
{code}

This leads to the situation that the defaultCharset is not used but latin1 encoding from the default content type.

The default content type should not have an encoding set to prevent this.


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org