You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Brad Medinger <BM...@linoma.com> on 2013/06/05 21:54:33 UTC

Charset for header values when using HttpMultipartMode.STRICT

I am using HttpClient 4.2.2 to upload a file with non ascii characters in the name using a multipart request.  The issue I'm running into is the character encoding used for the filename in the header is always US-ASCII instead of using the charset on the HttpMultipart MIME entity.  When constructing a new MultipartEntity I pass in a mode of STRICT which, after looking at the source, I found will always use MIME.DEFAULT_CHARSET (US-ASCII).  If I use the BROWSER_COMPATIBLE mode then the specified charset is used, but this mode will only write Content-Disposition and Content-Type headers.  Is there a reason that a multipart request with a mode of STRICT will always use US-ASCII for header values?

Thanks,
Brad


Re: Charset for header values when using HttpMultipartMode.STRICT

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2013-06-05 at 19:54 +0000, Brad Medinger wrote:
> I am using HttpClient 4.2.2 to upload a file with non ascii characters in the name using a multipart request.  The issue I'm running into is the character encoding used for the filename in the header is always US-ASCII instead of using the charset on the HttpMultipart MIME entity.  When constructing a new MultipartEntity I pass in a mode of STRICT which, after looking at the source, I found will always use MIME.DEFAULT_CHARSET (US-ASCII).  If I use the BROWSER_COMPATIBLE mode then the specified charset is used, but this mode will only write Content-Disposition and Content-Type headers.  Is there a reason that a multipart request with a mode of STRICT will always use US-ASCII for header values?
> 
> Thanks,
> Brad
> 

This is due to the requirement of the MIME specification. Non-ASCII
characters are not allowed in MIME headers and must be escaped using
Base64 or Quote-Printable encoding as described in RFC 2047 [1]. For
more complex manipulations with MIME formatted content you might want to
use mime4j [2] instead of HttpMime 

Oleg

[1] http://tools.ietf.org/html/rfc2047  
[2] http://james.apache.org/mime4j/index.html


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