[PATCH 11 of 20] Upstream: simplified Content-Encoding handling

Maxim Dounin mdounin at mdounin.ru
Fri May 13 00:18:13 UTC 2022


Hello!

On Thu, May 12, 2022 at 12:00:32AM +0400, Sergey Kandaurov wrote:

> On Thu, Apr 21, 2022 at 01:18:51AM +0300, Maxim Dounin wrote:
> > # HG changeset patch
> > # User Maxim Dounin <mdounin at mdounin.ru>
> > # Date 1650492330 -10800
> > #      Thu Apr 21 01:05:30 2022 +0300
> > # Node ID 6441069e16a0c4755c662bc07bdcb0960c9ac04a
> > # Parent  ee1a8a4aa2c262d25a4aa871cda4f6c4515fc85c
> > Upstream: simplified Content-Encoding handling.
> > 
> > Since introduction of offset handling in ngx_http_upstream_copy_header_line()
> > in revision 573:58475592100c, the ngx_http_upstream_copy_content_encoding()
> > function is no longer needed, as its behaviour is exactly equivalent to
> > ngx_http_upstream_copy_header_line() with appropriate offset.  As such,
> > the ngx_http_upstream_copy_content_encoding() function was removed.
> > 
> > Further, the u->headers_in.content_encoding field is not used anywhere,
> > so it was removed as well.
> 
> jftr, it's used (seemingly incorrect) in ngx_http_redis for gzip decompression
> https://github.com/onnimonni/redis-nginx-module/commit/cbe2630fd070

This commit emulates previously existing processing of the 
"Content-Encoding: gzip" header.  Just removing the 
"u->headers_in.content_encoding = h;" line will suffice.

(Ideally, it should call hh->handler() instead, but this will 
require a lot more changes, notably compiling headers hash.  Just 
in case, in the memcached module similar code simply add r->headers_out 
header - which is also wrong, but won't somewhat simpler.)

> It might be better to improve gunzip filter itself as marked in TODO.

No changes in gunzip filter are needed for this.  Further, it 
doesn't need gunzip at all (assuming it is ok to ignore clients 
without gzip support): the code simply provides the 
"Content-Encoding: gzip" header in responses.

If you mean the "always gunzip" TODO, it is irrelevant here: in 
this case not all responses needs to be gunzipped (even assuming 
all responses are gzipped, which is not true, for example, in 
memcached, where gzipping is signalled by a flag stored in 
memcached).

> > 
> > Further, Content-Encoding handling no longer depends on NGX_HTTP_GZIP,
> > as it can be used even without any gzip handling compiled in (for example,
> > in the charset filter).
> > 
> > diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
> > --- a/src/http/ngx_http_upstream.c
> > +++ b/src/http/ngx_http_upstream.c
> > @@ -147,11 +147,6 @@ static ngx_int_t ngx_http_upstream_rewri
> >  static ngx_int_t ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r,
> >      ngx_table_elt_t *h, ngx_uint_t offset);
> >  
> > -#if (NGX_HTTP_GZIP)
> > -static ngx_int_t ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r,
> > -    ngx_table_elt_t *h, ngx_uint_t offset);
> > -#endif
> > -
> >  static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf);
> >  static ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r,
> >      ngx_http_variable_value_t *v, uintptr_t data);
> > @@ -316,12 +311,10 @@ static ngx_http_upstream_header_t  ngx_h
> >                   ngx_http_upstream_process_transfer_encoding, 0,
> >                   ngx_http_upstream_ignore_header_line, 0, 0 },
> >  
> > -#if (NGX_HTTP_GZIP)
> >      { ngx_string("Content-Encoding"),
> > -                 ngx_http_upstream_process_header_line,
> > -                 offsetof(ngx_http_upstream_headers_in_t, content_encoding),
> > -                 ngx_http_upstream_copy_content_encoding, 0, 0 },
> > -#endif
> > +                 ngx_http_upstream_ignore_header_line, 0,
> > +                 ngx_http_upstream_copy_header_line,
> > +                 offsetof(ngx_http_headers_out_t, content_encoding), 0 },
> >  
> >      { ngx_null_string, NULL, 0, NULL, 0, 0 }
> >  };
> > @@ -5349,29 +5342,6 @@ ngx_http_upstream_copy_allow_ranges(ngx_
> >  }
> >  
> >  
> > -#if (NGX_HTTP_GZIP)
> > -
> > -static ngx_int_t
> > -ngx_http_upstream_copy_content_encoding(ngx_http_request_t *r,
> > -    ngx_table_elt_t *h, ngx_uint_t offset)
> > -{
> > -    ngx_table_elt_t  *ho;
> > -
> > -    ho = ngx_list_push(&r->headers_out.headers);
> > -    if (ho == NULL) {
> > -        return NGX_ERROR;
> > -    }
> > -
> > -    *ho = *h;
> > -
> > -    r->headers_out.content_encoding = ho;
> > -
> > -    return NGX_OK;
> > -}
> > -
> > -#endif
> > -
> > -
> >  static ngx_int_t
> >  ngx_http_upstream_add_variables(ngx_conf_t *cf)
> >  {
> > diff --git a/src/http/ngx_http_upstream.h b/src/http/ngx_http_upstream.h
> > --- a/src/http/ngx_http_upstream.h
> > +++ b/src/http/ngx_http_upstream.h
> > @@ -285,10 +285,6 @@ typedef struct {
> >      ngx_table_elt_t                 *transfer_encoding;
> >      ngx_table_elt_t                 *vary;
> >  
> > -#if (NGX_HTTP_GZIP)
> > -    ngx_table_elt_t                 *content_encoding;
> > -#endif
> > -
> >      ngx_table_elt_t                 *cache_control;
> >      ngx_table_elt_t                 *set_cookie;
> >  
> > 
> 
> _______________________________________________
> nginx-devel mailing list -- nginx-devel at nginx.org
> To unsubscribe send an email to nginx-devel-leave at nginx.org

-- 
Maxim Dounin
http://mdounin.ru/



More information about the nginx-devel mailing list