[PATCH 1 of 2] HTTP: add support for trailers in HTTP responses
Maxim Dounin
mdounin at mdounin.ru
Mon Jun 27 13:45:01 UTC 2016
Hello!
On Sun, Jun 26, 2016 at 04:13:15PM -0700, Piotr Sikora wrote:
> # HG changeset patch
> # User Piotr Sikora <piotrsikora at google.com>
> # Date 1466735480 25200
> # Thu Jun 23 19:31:20 2016 -0700
> # Node ID a96187a9806536ab2a8bf3fa7f7b659cf5d3ff13
> # Parent 6f69e3c0f780e29bca752fc1f938f4a459a1ec59
> HTTP: add support for trailers in HTTP responses.
>
> Example:
>
> ngx_table_elt_t *h;
>
> h = ngx_list_push(&r->headers_out.trailers);
> if (h == NULL) {
> return NGX_ERROR;
> }
>
> ngx_str_set(&h->key, "Fun");
> ngx_str_set(&h->value, "with trailers");
> h->hash = ngx_hash_key_lc(h->key.data, h->key.len);
>
> The code above adds "Fun: with trailers" trailer to the response to
> the request with "TE: trailers" header (which indicates support for
> trailers).
>
> Note that trailers MUST be added before last buffer of the response
> (last_buf = 1) reaches chunked or v2 output filters, otherwise they
> are going to be ignored.
>
> Signed-off-by: Piotr Sikora <piotrsikora at google.com>
What's the goal? Any real-world use for this?
>
> diff -r 6f69e3c0f780 -r a96187a98065 src/http/modules/ngx_http_chunked_filter_module.c
> --- a/src/http/modules/ngx_http_chunked_filter_module.c
> +++ b/src/http/modules/ngx_http_chunked_filter_module.c
> @@ -17,6 +17,7 @@ typedef struct {
>
>
> static ngx_int_t ngx_http_chunked_filter_init(ngx_conf_t *cf);
> +static ngx_chain_t *ngx_http_chunked_get_trailers(ngx_http_request_t *r);
>
>
> static ngx_http_module_t ngx_http_chunked_filter_module_ctx = {
> @@ -69,28 +70,31 @@ ngx_http_chunked_header_filter(ngx_http_
> return ngx_http_next_header_filter(r);
> }
>
> - if (r->headers_out.content_length_n == -1) {
> + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
> +
> + if (clcf->chunked_transfer_encoding && r->trailers_ok) {
> + ngx_http_clear_content_length(r);
> + r->chunked = 1;
As far as I understand the patch, this will cause chunked encoding
to be used for all responses to a client which supports trailers.
This certainly looks like a bad idea.
[...]
--
Maxim Dounin
http://nginx.org/
More information about the nginx-devel
mailing list