[PATCH] SPDY: stop emitting empty header values
Valentin V. Bartenev
vbart at nginx.com
Mon Oct 27 14:01:58 UTC 2014
On Tuesday 21 October 2014 04:16:01 Piotr Sikora wrote:
> # HG changeset patch
> # User Piotr Sikora <piotr at cloudflare.com>
> # Date 1413890111 25200
> # Tue Oct 21 04:15:11 2014 -0700
> # Node ID fbc2eb84bd266b64644b00a6454c4f79f241af5a
> # Parent 973fded4f461f3a397779b3a1dc80881b1b34974
> SPDY: stop emitting empty header values.
>
> Previously, nginx would emit empty values in a header with multiple,
> NULL-separated values.
>
> This is forbidden by the SPDY specification, which requires headers to
> have either a single (possibly empty) value or multiple, NULL-separated
> non-empty values.
>
> Signed-off-by: Piotr Sikora <piotr at cloudflare.com>
>
> diff -r 973fded4f461 -r fbc2eb84bd26 src/http/ngx_http_spdy_filter_module.c
> --- a/src/http/ngx_http_spdy_filter_module.c Wed Oct 15 22:57:23 2014 +0400
> +++ b/src/http/ngx_http_spdy_filter_module.c Tue Oct 21 04:15:11 2014 -0700
> @@ -100,7 +100,7 @@ ngx_http_spdy_header_filter(ngx_http_req
> u_char *p, *buf, *last;
> ngx_buf_t *b;
> ngx_str_t host;
> - ngx_uint_t i, j, count, port;
> + ngx_uint_t i, j, count, port, sep;
> ngx_chain_t *cl;
> ngx_list_part_t *part, *pt;
> ngx_table_elt_t *header, *h;
> @@ -472,6 +472,7 @@ ngx_http_spdy_header_filter(ngx_http_req
>
> pt = part;
> h = header;
> + sep = header[i].value.len ? 1 : 0;
>
> for (j = i + 1; /* void */; j++) {
>
> @@ -493,9 +494,14 @@ ngx_http_spdy_header_filter(ngx_http_req
> continue;
> }
>
> - *last++ = '\0';
> + if (h[j].value.len) {
> + if (sep) {
> + *last++ = '\0';
> + }
>
> - last = ngx_cpymem(last, h[j].value.data, h[j].value.len);
> + last = ngx_cpymem(last, h[j].value.data, h[j].value.len);
> + sep = 1;
> + }
>
> h[j].hash = 2;
> }
>
IMHO, there is no need to introduce "sep" variable:
diff -r a8d111bb6884 src/http/ngx_http_spdy_filter_module.c
--- a/src/http/ngx_http_spdy_filter_module.c Tue Sep 30 17:20:32 2014 +0400
+++ b/src/http/ngx_http_spdy_filter_module.c Mon Oct 27 16:58:02 2014 +0300
@@ -493,9 +493,13 @@ ngx_http_spdy_header_filter(ngx_http_req
continue;
}
- *last++ = '\0';
+ if (h[j].value.len) {
+ if (last != p) {
+ *last++ = '\0';
+ }
- last = ngx_cpymem(last, h[j].value.data, h[j].value.len);
+ last = ngx_cpymem(last, h[j].value.data, h[j].value.len);
+ }
h[j].hash = 2;
}
More information about the nginx-devel
mailing list