From 668faeb7b0b77d08a65b38a87cbd16ae275998ac Mon Sep 17 00:00:00 2001 From: Hakase Date: Tue, 5 Jun 2018 21:38:04 +0900 Subject: [PATCH] Fix hpack push error. --- src/http/v2/ngx_http_v2_filter_module.c | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/http/v2/ngx_http_v2_filter_module.c b/src/http/v2/ngx_http_v2_filter_module.c index bd9a02f..9d6cfdd 100644 --- a/src/http/v2/ngx_http_v2_filter_module.c +++ b/src/http/v2/ngx_http_v2_filter_module.c @@ -59,6 +59,17 @@ #define NGX_HTTP_V2_NO_TRAILERS (ngx_http_v2_out_frame_t *) -1 +static const struct { + u_char *name; + u_char const len; +} push_header[] = { + { (u_char*)":authority" , 10 }, + { (u_char*)"accept-encoding" , 15 }, + { (u_char*)"accept-language" , 15 }, + { (u_char*)"user-agent" , 10 } +}; + + typedef struct { ngx_str_t name; u_char index; @@ -955,7 +966,7 @@ ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path, for (i = 0; i < NGX_HTTP_V2_PUSH_HEADERS; i++) { len += binary[i].len; - len += sizeof(ph[i].name); + len += push_header[i].len + 1; } pos = ngx_pnalloc(r->pool, len); @@ -1014,20 +1025,9 @@ ngx_http_v2_push_resource(ngx_http_request_t *r, ngx_str_t *path, "http2 push header: \"%V: %V\"", &ph[i].name, &(*h)->value); - switch(i) { - case 0: - pos = ngx_http_v2_write_header_pot(":authority", value); - break; - case 1: - pos = ngx_http_v2_write_header_pot("accept-encoding", value); - break; - case 2: - pos = ngx_http_v2_write_header_pot("accept-language", value); - break; - case 3: - pos = ngx_http_v2_write_header_pot("user-agent", value); - break; - } + pos = ngx_http_v2_write_header(h2c, pos, + push_header[i].name, push_header[i].len, value->data, value->len, + tmp); } frame = ngx_http_v2_create_push_frame(r, start, pos);