Mercurial > hg > nginx
annotate src/http/v2/ngx_http_v2_encode.c @ 9295:c5623963c29e
Upstream: fixed proxy_no_cache when caching errors.
Caching errors, notably intercepted errors and internally generated
502/504 errors, as well as handling of cache revalidation with 304,
did not take into account u->conf->no_cache predicates configured.
As a result, an error might be cached even if configuration explicitly
says not to. Fix is to check u->conf->no_cache in these cases.
To simplify usage in multiple places, checking u->conf->no_cache is now
done in a separate function. As a minor optimization, u->conf->no_cache
is only checked if u->cacheable is set.
As a side effect, this change also fixes caching errors after
proxy_cache_bypass. Also, during cache revalidation u->cacheable is
now tested, so 304 responses which disable caching won't extend
cacheability of stored responses.
Additionally, when caching internally generated 502/504 errors
u->cacheable is now explicitly updated from u->headers_in.no_cache and
u->headers_in.expired, restoring the behaviour before 8041:0784ab86ad08
(1.23.0) when an error happens while reading the response headers.
Reported by Kirill A. Korinsky,
https://freenginx.org/pipermail/nginx/2024-April/000082.html
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 25 Jun 2024 21:44:50 +0300 |
parents | 336084ff943b |
children |
rev | line source |
---|---|
7229
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
1 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
2 /* |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
3 * Copyright (C) Nginx, Inc. |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
4 * Copyright (C) Valentin V. Bartenev |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
5 */ |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
6 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
7 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
11 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
12 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
13 static u_char *ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix, |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
14 ngx_uint_t value); |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
15 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
16 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
17 u_char * |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
18 ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len, u_char *tmp, |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
19 ngx_uint_t lower) |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
20 { |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
21 size_t hlen; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
22 |
7977
336084ff943b
Moved Huffman coding out of HTTP/2.
Ruslan Ermilov <ru@nginx.com>
parents:
7229
diff
changeset
|
23 hlen = ngx_http_huff_encode(src, len, tmp, lower); |
7229
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
24 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
25 if (hlen > 0) { |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
26 *dst = NGX_HTTP_V2_ENCODE_HUFF; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
27 dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), hlen); |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
28 return ngx_cpymem(dst, tmp, hlen); |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
29 } |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
30 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
31 *dst = NGX_HTTP_V2_ENCODE_RAW; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
32 dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), len); |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
33 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
34 if (lower) { |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
35 ngx_strlow(dst, src, len); |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
36 return dst + len; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
37 } |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
38 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
39 return ngx_cpymem(dst, src, len); |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
40 } |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
41 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
42 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
43 static u_char * |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
44 ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix, ngx_uint_t value) |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
45 { |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
46 if (value < prefix) { |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
47 *pos++ |= value; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
48 return pos; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
49 } |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
50 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
51 *pos++ |= prefix; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
52 value -= prefix; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
53 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
54 while (value >= 128) { |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
55 *pos++ = value % 128 + 128; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
56 value /= 128; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
57 } |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
58 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
59 *pos++ = (u_char) value; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
60 |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
61 return pos; |
87e9e4aabf1b
HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff
changeset
|
62 } |