HTTP headers encoding/decoding in Java

后端 未结 5 1333
我寻月下人不归
我寻月下人不归 2020-11-30 06:14

A custom HTTP header is being passed to a Servlet application for authentication purposes. The header value must be able to contain accents and other non-ASCII characters, s

5条回答
  •  Happy的楠姐
    2020-11-30 06:40

    Thanks for the answers. It seems that the ideal would be to follow the proper HTTP header encoding as per RFC 2047. Header values in UTF-8 on the wire would look something like this:

    =?UTF-8?Q?...?=
    

    Now here is the funny thing: it seems that neither Tomcat 5.5 or 6 properly decodes HTTP headers as per RFC 2047! The Tomcat code assumes everywhere that header values use ISO-8859-1.

    So for Tomcat, specifically, I will work around this by writing a filter which handles the proper decoding of the header values.

提交回复
热议问题