당신의 HTTP Headers에 underscores를 쓰지 마세요!!
당신이 Headers에 underscores를 사용하면 안되는 이유
  • Backend

HTTP Headers에 underscores를 사용하지 마세요! 특히 nginx를 사용한다면

일반적으로 클라이언으로부터 헤더에 필요한 어떤 값을 headers에 담아 서버로 전송하고,
서버에서 해당 headers값 중 필요한 값을 파싱해서 사용하곤 합니다.

그런데 headers의 key값에 underscores가 포함되어있다면 nginx는 이를 무시합니다. 예를들어 key값을 foo_bar와 같이 사용했다면 말이죠.

underscores가 왜 ?

nginx의 문서에 따르면 underscores_in_headers 설정을 on 해주지 않으면 기본적으로는 헤더의 underscores를 drop하고 있습니다.

If you do not explicitly set underscores_in_headers on;, NGINX will silently drop HTTP headers with underscores

필요에 따라 nginx의 underscores 설정을 수정하면 되겠지만, 그것보다는 underscores를 사용하지 않는것이 더 좋을 것입니다.

foo_bar (X) Bad
foo-bar (O) Good