DEV Community

Ola Johansson
Ola Johansson

Posted on

Trying to parse "accept-language" header, beware of extra spaces

For some reason i've decided to parse this header myself the other day, shouldn't be that hard i supposed. And it wasn't that hard and everything was working perfectly locally.

Then i deployed this to my prod and things started to act weird. Only one language was detected and so forth. Finally i noticed that in prod my header string looked like this.

"sv, fr; q=0.9, en; q=0.8, no; q=0.7"

and locally it looked like this

"sv,fr;q=0.9,en;q=0.8,no;q=0.7"

I'm not sure why and I'm not sure what is more correct. But i just needed to add some trim to my parsing method and now things works.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay