Welcome! Log In Create A New Profile

Advanced

Re: [PATCH] Gzip static: ranges support (ticket #2349)

Sergey Kandaurov
January 23, 2023 12:30PM
> On 3 Jan 2023, at 06:48, Maxim Dounin <mdounin@mdounin.ru> wrote:
>
> # HG changeset patch
> # User Maxim Dounin <mdounin@mdounin.ru>
> # Date 1672713976 -10800
> # Tue Jan 03 05:46:16 2023 +0300
> # Node ID e0688b4494f02dcf6feebf0c73e02749bd7de381
> # Parent 07b0bee87f32be91a33210bc06973e07c4c1dac9
> Gzip static: ranges support (ticket #2349).
>
> In contrast to on-the-fly gzipping with gzip filter, static gzipped
> representation as returned by gzip_static is persistent, and therefore
> the same binary representation is available for future requests, making
> it possible to use range requests.
>
> Further, if a gzipped representation is re-generated with different
> compression settings, it is expected to result in different ETag and
> different size reported in the Content-Range header, making it possible
> to safely use range requests anyway.
>
> As such, ranges are now allowed for files returned by gzip_static.
>
> diff --git a/src/http/modules/ngx_http_gzip_static_module.c b/src/http/modules/ngx_http_gzip_static_module.c
> --- a/src/http/modules/ngx_http_gzip_static_module.c
> +++ b/src/http/modules/ngx_http_gzip_static_module.c
> @@ -247,6 +247,8 @@ ngx_http_gzip_static_handler(ngx_http_re
> ngx_str_set(&h->value, "gzip");
> r->headers_out.content_encoding = h;
>
> + r->allow_ranges = 1;
> +
> /* we need to allocate all before the header would be sent */
>
> b = ngx_calloc_buf(r->pool);

Looks good.

On a related note, while comparing with static module, which gzip_static
is based on, I further noticed that gzip_static doesn't check for 0-size
response in subrequests. Existing handling of r->main suggests that
such configuration might be used in practice, e.g. together with gunzip
filter, as documented in the gzip_static module documentation.
So, it makes sense to add such check for zero size buffers as well.

# HG changeset patch
# User Sergey Kandaurov <pluknet@nginx.com>
# Date 1674493925 -14400
# Mon Jan 23 21:12:05 2023 +0400
# Node ID 27217fca1966ddb20c843384d438df2af062fdfc
# Parent dd458c69858b88231f542be4573a3f81141d1359
Gzip static: avoid "zero size buf" alerts in subrequests.

Similar to the static module, gzip_static enabled in subrequests might
result in zero size buffers with responses from empty precompressed files.

diff --git a/src/http/modules/ngx_http_gzip_static_module.c b/src/http/modules/ngx_http_gzip_static_module.c
--- a/src/http/modules/ngx_http_gzip_static_module.c
+++ b/src/http/modules/ngx_http_gzip_static_module.c
@@ -236,6 +236,10 @@ ngx_http_gzip_static_handler(ngx_http_re
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

+ if (r != r->main && of.size == 0) {
+ return ngx_http_send_header(r);
+ }
+
h = ngx_list_push(&r->headers_out.headers);
if (h == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;


--
Sergey Kandaurov
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Gzip static: ranges support (ticket #2349)

Maxim Dounin 777 January 02, 2023 09:50PM

Re: [PATCH] Gzip static: ranges support (ticket #2349)

Maxim Dounin 139 January 13, 2023 07:02PM

Re: [PATCH] Gzip static: ranges support (ticket #2349)

Sergey Kandaurov 102 January 23, 2023 12:30PM

Re: [PATCH] Gzip static: ranges support (ticket #2349)

Maxim Dounin 103 January 23, 2023 09:20PM

Re: [PATCH] Gzip static: ranges support (ticket #2349)

Sergey Kandaurov 108 January 25, 2023 04:52AM

Re: [PATCH] Gzip static: ranges support (ticket #2349)

Maxim Dounin 118 January 28, 2023 03:04PM

Re: [PATCH] Gzip static: ranges support (ticket #2349)

Sergey Kandaurov 116 February 02, 2023 04:06AM

Re: [PATCH] Gzip static: ranges support (ticket #2349)

Maxim Dounin 152 February 02, 2023 03:32PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 280
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready