[PATCH] Parse: underscores_in_headers should apply to the first character as well

Piotr Sikora piotr at cloudflare.com
Mon Mar 24 23:48:29 UTC 2014


Hey Maxim,

> - the "Parse:" prefix isn't something we use, it may be good idea
>   to avoid id;

Done.

> - please keep summary line short to avoid "hg log" wrapping, see
>   http://nginx.org/en/docs/contributing_changes.html;

Done.

> - is it something really needed in practice?

Well, I'm not a fan of allowing underscores in the headers in the
first place, but since this is already in nginx, I don't see a reason
why this directive should allow underscores anywhere in the header
name, but not in the first character...

And yes, we have customers proxying headers starting with an underscore.

> Should be
>
>                            hash = ngx_hash(0, ch);
>
> instead.

Good catch, thanks!

Best regards,
Piotr Sikora


# HG changeset patch
# User Piotr Sikora <piotr at cloudflare.com>
# Date 1395704144 25200
#      Mon Mar 24 16:35:44 2014 -0700
# Node ID 9b71aa40b65135ed65c5f39c54a743a417ac77e8
# Parent  a23c35496c2fc0ba9a34d968c2ca6d1f9374f8a8
Apply underscores_in_headers also to the first character.

Signed-off-by: Piotr Sikora <piotr at cloudflare.com>

diff -r a23c35496c2f -r 9b71aa40b651 src/http/ngx_http_parse.c
--- a/src/http/ngx_http_parse.c Mon Mar 24 17:55:10 2014 +0400
+++ b/src/http/ngx_http_parse.c Mon Mar 24 16:35:44 2014 -0700
@@ -886,6 +886,19 @@ ngx_http_parse_header_line(ngx_http_requ
                     break;
                 }

+                if (ch == '_') {
+                    if (allow_underscores) {
+                        hash = ngx_hash(0, ch);
+                        r->lowcase_header[0] = ch;
+                        i = 1;
+
+                    } else {
+                        r->invalid_header = 1;
+                    }
+
+                    break;
+                }
+
                 if (ch == '\0') {
                     return NGX_HTTP_PARSE_INVALID_HEADER;
                 }



More information about the nginx-devel mailing list