Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonic header field capitalization does not work with all existing headers titles out of the box #440

Open
johnd0e opened this issue Oct 17, 2024 · 3 comments · May be fixed by #442
Open

Comments

@johnd0e
Copy link

johnd0e commented Oct 17, 2024

The issue is that the list in headers.lua is finite and cannot accommodate all possible header values. For instance, it does not include the commonly used header "Origin." I understand that keeping this list updated is challenging, especially given the existence of headers like "X-*-*."

Currently, the options are either to ignore this limitation (as most services handle lower-cased headers well) or to manage the headers manually.

My suggestion is to avoid storing headers altogether and instead normalize them on-the-fly. The existing socket.headers table could remain in place and serve as a cache.

@Tieske
Copy link
Member

Tieske commented Oct 18, 2024

You can add a metatable with an __index method, it would get called if a header doesn't exist in the table. In that case, normalize it once, and update the table.

@johnd0e
Copy link
Author

johnd0e commented Oct 19, 2024

That is exactly what I mean.
Sholdn't that be implemented in socket.headers.canonic instead of static table?

@Tieske
Copy link
Member

Tieske commented Oct 20, 2024

Either way, using this table would be like a "warmed-up cache".

A PR to add it is most appreciated. Prior art: https://github.com/ledgetech/lua-resty-http/blob/master/lib/resty/http_headers.lua

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants