[PATCH] HTTP/2: add debug logging of pseudo-headers and cookies

Valentin V. Bartenev vbart at nginx.com
Wed May 24 16:49:17 UTC 2017


On Monday 24 April 2017 15:58:46 Piotr Sikora via nginx-devel wrote:
> # HG changeset patch
> # User Piotr Sikora <piotrsikora at google.com>
> # Date 1490516711 25200
> #      Sun Mar 26 01:25:11 2017 -0700
> # Node ID 164b95f24f414359c5b8045415da3de82653c4db
> # Parent  2c4dbcd6f2e4c9c2a1eb8dc1f0d39c99975ae208
> HTTP/2: add debug logging of pseudo-headers and cookies.
> 
> Signed-off-by: Piotr Sikora <piotrsikora at google.com>
> 
> diff -r 2c4dbcd6f2e4 -r 164b95f24f41 src/http/v2/ngx_http_v2.c
> --- a/src/http/v2/ngx_http_v2.c
> +++ b/src/http/v2/ngx_http_v2.c
> @@ -1589,6 +1589,10 @@ ngx_http_v2_state_process_header(ngx_htt
>          rc = ngx_http_v2_pseudo_header(r, header);
>  
>          if (rc == NGX_OK) {
> +            ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
> +                           "http2 pseudo-header: \":%V: %V\"",
> +                           &header->name, &header->value);
> +
>              return ngx_http_v2_state_header_complete(h2c, pos, end);
>          }
>  
> @@ -1630,6 +1634,10 @@ ngx_http_v2_state_process_header(ngx_htt
>                                                  NGX_HTTP_V2_INTERNAL_ERROR);
>          }
>  
> +        ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
> +                       "http2 http header: \"%V: %V\"",
> +                       &header->name, &header->value);
> +
>          return ngx_http_v2_state_header_complete(h2c, pos, end);
>      }
>  
> 

IMHO, it's better to not duplicate message for Cookie:

# HG changeset patch
# User Piotr Sikora <piotrsikora at google.com>
# Date 1490516711 25200
#      Sun Mar 26 01:25:11 2017 -0700
# Node ID 9e5113f051206b2c09a377ac524c33f33ba0602a
# Parent  b624fbf7bee296b8f95f4a90228a1920127f12a0
HTTP/2: add debug logging of pseudo-headers and cookies.

Signed-off-by: Piotr Sikora <piotrsikora at google.com>

diff -r b624fbf7bee2 -r 9e5113f05120 src/http/v2/ngx_http_v2.c
--- a/src/http/v2/ngx_http_v2.c Tue May 23 20:19:39 2017 +0300
+++ b/src/http/v2/ngx_http_v2.c Sun Mar 26 01:25:11 2017 -0700
@@ -1589,6 +1589,10 @@ ngx_http_v2_state_process_header(ngx_htt
         rc = ngx_http_v2_pseudo_header(r, header);
 
         if (rc == NGX_OK) {
+            ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                           "http2 pseudo-header: \":%V: %V\"",
+                           &header->name, &header->value);
+
             return ngx_http_v2_state_header_complete(h2c, pos, end);
         }
 
@@ -1630,36 +1634,39 @@ ngx_http_v2_state_process_header(ngx_htt
                                                 NGX_HTTP_V2_INTERNAL_ERROR);
         }
 
-        return ngx_http_v2_state_header_complete(h2c, pos, end);
-    }
-
-    h = ngx_list_push(&r->headers_in.headers);
-    if (h == NULL) {
-        return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
-    }
-
-    h->key.len = header->name.len;
-    h->key.data = header->name.data;
-
-    /* TODO Optimization: precalculate hash and handler for indexed headers. */
-    h->hash = ngx_hash_key(h->key.data, h->key.len);
-
-    h->value.len = header->value.len;
-    h->value.data = header->value.data;
-
-    h->lowcase_key = h->key.data;
-
-    cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
-    hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,
-                       h->lowcase_key, h->key.len);
-
-    if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
-        goto error;
+    } else {
+        h = ngx_list_push(&r->headers_in.headers);
+        if (h == NULL) {
+            return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
+        }
+
+        h->key.len = header->name.len;
+        h->key.data = header->name.data;
+
+        /*
+         * TODO Optimization: precalculate hash
+         * and handler for indexed headers.
+         */
+        h->hash = ngx_hash_key(h->key.data, h->key.len);
+
+        h->value.len = header->value.len;
+        h->value.data = header->value.data;
+
+        h->lowcase_key = h->key.data;
+
+        cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
+
+        hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,
+                           h->lowcase_key, h->key.len);
+
+        if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
+            goto error;
+        }
     }
 
     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
-                   "http2 http header: \"%V: %V\"", &h->key, &h->value);
+                   "http2 http header: \"%V: %V\"",
+                   &header->name, &header->value);
 
     return ngx_http_v2_state_header_complete(h2c, pos, end);
 



More information about the nginx-devel mailing list