Codebase for my homepage.
git clone git://vcs.sapka.me/michal-sapka-me
Log | Files | Refs

commit fc7c2cfbbc897c3ad93d8c9a64919d2234e5534f
parent 38465d4f8dcf74a5071559d24048c5e63d47a9bb
Author: MichaƂ M. Sapka <michal@sapka.me>
Date:   Wed,  1 Feb 2023 18:15:59 +0100

article for 2023-02-01

Acontent/2023/http-headers-in-rails-hyphens-and-underscores.md | 18++++++++++++++++++
Acontent/2023/http-headers-in-rails-hyphens-and-underscores.md~ | 10++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/content/2023/http-headers-in-rails-hyphens-and-underscores.md b/content/2023/http-headers-in-rails-hyphens-and-underscores.md @@ -0,0 +1,18 @@ +--- +title: "HTTP Headers in Rails: Hyphens, Underscores, and a terrible day" +category: "engineering" +abstract: Rack modyfies incomming requests's headers! +date: 2023-02-01T18:00:51+01:00 +year: 2023 +draft: false +tags: ['rack', 'ruby-on-rails', 'headers', 'magic'] +--- +Everyone's favorite magician, Ruby on Rails, does it again. + +As it [Rack modifies incoming requests' headers](https://github.com/rails/rails/blob/aaf7bed00338c3a97dbb12b3c82a30ae34e67876/actionpack/lib/action_dispatch/http/headers.rb#L12) and normalizes they keys. So, every time the client/proxy sends something cool like `A-HEADER`, the key is modified, so some characters become underscore. Therefore in Rails code need to access `A_HEADER`, and if I had known that yesterday, my day would be much more pleasant. + +> Also note that when headers are mapped to CGI-like variables by the Rack +> +> server, both dashes and underscores are converted to underscores. +> +> (as [per documentation](https://github.com/rails/rails/blob/aaf7bed00338c3a97dbb12b3c82a30ae34e67876/actionpack/lib/action_dispatch/http/headers.rb#L12) diff --git a/content/2023/http-headers-in-rails-hyphens-and-underscores.md~ b/content/2023/http-headers-in-rails-hyphens-and-underscores.md~ @@ -0,0 +1,10 @@ +--- +title: "Http Headers in Rails Hyphens and Underscores" +category: "blog" +abstract: +date: 2023-02-01T18:00:51+01:00 +year: +draft: false +tags: [] +--- +