2

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
samz
  • 1,592
  • 3
  • 21
  • 37
  • 2
    possible duplicate of [HTTP header should use what character encoding?](http://stackoverflow.com/questions/4400678/http-header-should-use-what-character-encoding) – Alexey Ten May 06 '14 at 08:51
  • already seen that Q, its a little of a mixed bag. one answer says that only ascii is allowed while the accepted answer said anything can be in the header if its encoded per RFC 2047. I tried sending this star symbol and had no success. it juts sent =?UTF-8?Q?=E2=9C=B0?= as a string :( – samz May 06 '14 at 18:35
  • Encoding per RFC2047 is not in contradiction with “only ascii is allowed”. It's up to you how you encode string to fit into ascii, RFC2047 is only one of them. Personally I prefer encodeURIComponent. And in any case it's your job to decode them on receiving. – Alexey Ten May 07 '14 at 06:43
  • aha I thought the header or the format is a hint to the server on how to automatically decode them. but actually i just put whatever ascii string I want in the header and then its my responsibility to decode this. did i get it right? – samz May 07 '14 at 12:09
  • Yes. Especially if it's custom header. – Alexey Ten May 07 '14 at 12:17

1 Answers1

5

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.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
samz
  • 1,592
  • 3
  • 21
  • 37