-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Headers API #161
Comments
Hello! On Fri, Sep 28, 2012 at 2:06 AM, James Hurst [email protected] wrote:
Yes.
Yes.
Yes, I changed my mind after introducing the former and right before The ngx.header.HEADER uses (in my opinon) too much magic for the sake
I don't like the idea of adding ngx.req.header.HEADER which mostly How about adding new options to ngx.req.get_headers() so that it
such that ngx.req.get_headers(true, true)["content-type"] will work in
We can make it iterate-able because LuaJIT 2.0 and Lua 5.2
Yes, adding the __index metamethod for lookup misses sounds like a good idea :)
I agree :) Best regards, |
I've updated the ngx.req.get_headers() per your request in the git "devel" branch of ngx_lua. Here's the updated documentation for this method: http://wiki.nginx.org/HttpLuaModule#ngx.req.get_headers Could you take a look at it? If it's OK, I'll merge it back to "master". This change will be included in the 0.6.9 release of ngx_lua and the 1.2.3.7 devel release of ngx_openresty. Thanks! |
That looks great, thanks for turning it around so quickly! I'm glad that the normalised version is the default, I think that does make the most sense. So generally speaking people will only use the "raw" option when iterating over the headers, perhaps to serialise them in their original form. For lookups, the default behaviour is to ignore case. Can you elaborate on the doc note about Perhaps something like:
Presuming I'm right about the performance reasons? |
Hello! On Wed, Oct 3, 2012 at 3:32 AM, James Hurst [email protected] wrote:
Yes, exactly. Glad you like it :)
Actually I won't ngx.var.http_HEADER is preferable, because of the
I think we can mention ngx.var.http_HEADER there, but not the Best regards, |
So actually it's now no longer preferable at all? I see what you mean - it's hard to generalise the performance comparison. I just think that new users will appreciate having clear confidence in which method to choose, and clear guidance will lead to more consistent user-land code. I almost feel like (based on what you're saying), the I don't have a strong opinion, it just struck me as ambiguous. |
Hello! On Thu, Oct 4, 2012 at 1:42 AM, James Hurst [email protected] wrote:
Exactly. I hope ngx.req.get_headers() become the One True Way of doing
The culture of Nginx is kinda like Perl, I must say, that is, "There's Best regards, |
Anyway, I'm closing this :) |
I find myself grappling with issues of case sensitivity around request headers. I've implemented some work arounds in Lua land, but it's not pretty, and I noticed we have this task on the ngx_lua short term todo:
I realise the above is probably just a performance task, to make lookups for the known
headers_in
faster, before scanning the whole list on a miss? But perhaps it's an opportunity to revisit the API here.The issue is that
ngx.var.http_HEADER
gives you case insensitive lookup of header fields (which is correct), so long as they are single values (so you can't get a table back for multiple values of the same header key, at least as far as I can tell?), whilstngx.req.get_headers()[HEADER]
gives you case sensitive lookup, but with the added benefit of returning a table of header values where appropriate.Moreover, the
ngx.header.HEADER
API looks different to thengx.req.get_headers()
API, which is a shame.I'd like to see
ngx.req.header.HEADER
implemented much like the response headers API, where you access header fields case __in__sensitively, and can get / set tables for multiple values where appropriate.ngx.req.get_headers()
still has its use - to iterate over the request headers. And I note thatngx.header
is not a normal Lua table, so you can't iterate over response headers at all?I guess it feels like there are too many internal limitations passed onto Lua-land here. From what I can tell,
ngx.header["Content-Type"]
matchesngx.header.content_type
internally, because it's a more direct mapping to theheaders_out
structure, whereasngx.req.get_headers()
returns a true Lua table as a copy of the headers, leaving us to deal with case ourselves.Perhaps if the Lua table from
ngx.req.get_headers()
actually gave keys lowercased / underscored, and we set a metatable to normalise the lookup, that would help?Personally I'd like to see a nice consistent request / response header API, but if that's not possible / desirable, I'd settle for any solution that doesn't pass on case sensitivity in field names to the Lua programmer.
Thoughts?
The text was updated successfully, but these errors were encountered: