]> git.kaiwu.me - nginx.git/commitdiff
underscores_in_headers
authorIgor Sysoev <igor@sysoev.ru>
Wed, 24 Sep 2008 14:02:50 +0000 (14:02 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Wed, 24 Sep 2008 14:02:50 +0000 (14:02 +0000)
src/http/modules/ngx_http_fastcgi_module.c
src/http/modules/ngx_http_proxy_module.c
src/http/ngx_http.h
src/http/ngx_http_core_module.c
src/http/ngx_http_core_module.h
src/http/ngx_http_parse.c
src/http/ngx_http_request.c

index 049c1130be9bee9f548c4bcd627509e03867aae4..b4a07d011ef5aac8fdd4abd90d2a9618c9982944 100644 (file)
@@ -1031,7 +1031,7 @@ ngx_http_fastcgi_process_header(ngx_http_request_t *r)
 
             part_start = u->buffer.pos;
 
-            rc = ngx_http_parse_header_line(r, &u->buffer);
+            rc = ngx_http_parse_header_line(r, &u->buffer, 1);
 
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                            "http fastcgi parser: %d", rc);
@@ -1076,7 +1076,7 @@ ngx_http_fastcgi_process_header(ngx_http_request_t *r)
 
                     f->split_parts->nelts = 0;
 
-                    rc = ngx_http_parse_header_line(r, &buf);
+                    rc = ngx_http_parse_header_line(r, &buf, 1);
 
                     h->key.len = r->header_name_end - r->header_name_start;
                     h->key.data = r->header_name_start;
index 6c0e28a346520aa3bcd5db929c2e1835b5cdce8d..d8392ee8d57ca6df5853b0383cfd8305cdd56565 100644 (file)
@@ -1214,7 +1214,7 @@ ngx_http_proxy_process_header(ngx_http_request_t *r)
 
     for ( ;; ) {
 
-        rc = ngx_http_parse_header_line(r, &r->upstream->buffer);
+        rc = ngx_http_parse_header_line(r, &r->upstream->buffer, 1);
 
         if (rc == NGX_OK) {
 
index 762d85c74590cac4924681988b0d37e5408aa20e..79b21871637508df0a40196b4a1202f71582fe5a 100644 (file)
@@ -72,7 +72,8 @@ ngx_int_t ngx_http_parse_complex_uri(ngx_http_request_t *r,
     ngx_uint_t merge_slashes);
 ngx_int_t ngx_http_parse_unsafe_uri(ngx_http_request_t *r, ngx_str_t *uri,
     ngx_str_t *args, ngx_uint_t *flags);
-ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b);
+ngx_int_t ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b,
+    ngx_uint_t allow_underscores);
 ngx_int_t ngx_http_parse_multi_header_lines(ngx_array_t *headers,
     ngx_str_t *name, ngx_str_t *value);
 
index e1d5a8f55fae42544b83d08b8d13d3655ecdf3c9..050f81e7ffd232c9556a25d23d2ebab1bebdb163 100644 (file)
@@ -231,6 +231,13 @@ static ngx_command_t  ngx_http_core_commands[] = {
       offsetof(ngx_http_core_srv_conf_t, merge_slashes),
       NULL },
 
+    { ngx_string("underscores_in_headers"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
+      ngx_conf_set_flag_slot,
+      NGX_HTTP_SRV_CONF_OFFSET,
+      offsetof(ngx_http_core_srv_conf_t, underscores_in_headers),
+      NULL },
+
     { ngx_string("location"),
       NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE12,
       ngx_http_core_location,
@@ -2527,6 +2534,7 @@ ngx_http_core_create_srv_conf(ngx_conf_t *cf)
     cscf->client_header_buffer_size = NGX_CONF_UNSET_SIZE;
     cscf->ignore_invalid_headers = NGX_CONF_UNSET;
     cscf->merge_slashes = NGX_CONF_UNSET;
+    cscf->underscores_in_headers = NGX_CONF_UNSET;
 
     return cscf;
 }
@@ -2605,6 +2613,9 @@ ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
 
     ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
 
+    ngx_conf_merge_value(conf->underscores_in_headers,
+                              prev->underscores_in_headers, 0);
+
     return NGX_CONF_OK;
 }
 
index a3d8940a988af55930069af6d690f230f8f053c4..e28aad56137673d51f4b73f8ca890c5d50a37342 100644 (file)
@@ -155,6 +155,7 @@ typedef struct {
 
     ngx_flag_t                  ignore_invalid_headers;
     ngx_flag_t                  merge_slashes;
+    ngx_flag_t                  underscores_in_headers;
 
     ngx_http_core_loc_conf_t  **named_locations;
 } ngx_http_core_srv_conf_t;
index 2fce7acac87c6c27743ee69163254a1065cc2209..b08d5eaa7fdb22c950f7548a1a092573c889a3e7 100644 (file)
@@ -700,7 +700,8 @@ done:
 
 
 ngx_int_t
-ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
+ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b,
+    ngx_uint_t allow_underscores)
 {
     u_char      c, ch, *p;
     ngx_uint_t  hash, i;
@@ -720,7 +721,7 @@ ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
     static u_char  lowcase[] =
         "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
         "\0\0\0\0\0\0\0\0\0\0\0\0\0-\0\0" "0123456789\0\0\0\0\0\0"
-        "\0abcdefghijklmnopqrstuvwxyz\0\0\0\0_"
+        "\0abcdefghijklmnopqrstuvwxyz\0\0\0\0\0"
         "\0abcdefghijklmnopqrstuvwxyz\0\0\0\0\0"
         "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
         "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
@@ -779,6 +780,19 @@ ngx_http_parse_header_line(ngx_http_request_t *r, ngx_buf_t *b)
                 break;
             }
 
+            if (ch == '_') {
+                if (allow_underscores) {
+                    hash = ngx_hash(hash, ch);
+                    r->lowcase_header[i++] = ch;
+                    i &= (NGX_HTTP_LC_HEADER_LEN - 1);
+
+                } else {
+                    r->invalid_header = 1;
+                }
+
+                break;
+            }
+
             if (ch == ':') {
                 r->header_name_end = p;
                 state = sw_space_before_value;
index ae3bb03d5a6ca9242eeb810d3c442564f6a36f49..3970852ea3c01bcfa3ddb273dcd759eb950e2cd3 100644 (file)
@@ -902,7 +902,8 @@ ngx_http_process_request_headers(ngx_event_t *rev)
             }
         }
 
-        rc = ngx_http_parse_header_line(r, r->header_in);
+        rc = ngx_http_parse_header_line(r, r->header_in,
+                                        cscf->underscores_in_headers);
 
         if (rc == NGX_OK) {