Custom HTTP header value - trying to pass umlaut characters

天大地大妈咪最大 提交于 2019-11-28 10:47:56

问题


I am using Node.js and Express.js 3.x.

As one of our authorization headers we are passing in the username. Some of our usernames contain umlaut characters: ü ö ä and the likes of. For usernames with just 'normal' characters, all works fine. But when a jörg tries to make a request, the server doesn't recognize the umlaut character in the header.

Trying to simulate the problem I:

  • Created some tests that set the username header with the umlaut character. These tests pass, they are able to pass in the umlaut correctly.
  • Used 'postman' and 'advanced rest client' Chrome extensions and made the request manually against the server - in this case it failed. I saw the server is unable to recognize the umlaut character, it juts interpreted it as some sort of ?.

Is there any limitation on custom HTTP header values characters that forbids using these kind of characters? Any idea why it would work in tests but not from my browser extension? Am I forgetting to set some character set somewhere?


回答1:


Summary of what was written in the other related question and in comments:

  • You may put any 'printable' ASCII char in your custom header value field.
  • If you want to use special characters, encode these characters following whatever rules/charset/encoding you choose. As long as this encoding it uses simple ASCII chars, it's OK. An example is using UTF-8 and encoding string chars to \u%%.
  • On the server side - you must manually make sense out of the encoded string, probably by decoding it using the rules of the character set/encoding paradigm you chose before.


来源:https://stackoverflow.com/questions/23489832/custom-http-header-value-trying-to-pass-umlaut-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!