annotate src/http/v2/ngx_http_v2_encode.c @ 7355:b64adc956643

Rewrite: removed r->err_status special handling (ticket #1634). Trying to look into r->err_status in the "return" directive makes it behave differently than real errors generated in other parts of the code, and is an endless source of various problems. This behaviour was introduced in 726:7b71936d5299 (0.4.4) with the comment "fix: "return" always overrode "error_page" response code". It is not clear if there were any real cases this was expected to fix, but there are several cases which are broken due to this change, some previously fixed (4147:7f64de1cc2c0). In ticket #1634, the problem is that when r->err_status is set to a non-special status code, it is not possible to return a response by simply returning r->err_status. If this is the case, the only option is to return script's e->status instead. An example configuration: location / { error_page 404 =200 /err502; return 404; } location = /err502 { return 502; } After the change, such a configuration will properly return standard 502 error, much like it happens when a 502 error is generated by proxy_pass. This also fixes the following configuration to properly close connection as clearly requested by "return 444": location / { error_page 404 /close; return 404; } location = /close { return 444; } Previously, this required "error_page 404 = /close;" to work as intended.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 21 Sep 2018 15:59:33 +0300
parents 87e9e4aabf1b
children 336084ff943b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
87e9e4aabf1b HTTP/2: externalized various constants and interfaces.
Maxim Dounin <mdounin@mdounin.ru>
parents:
diff changeset
23 hlen = ngx_http_v2_huff_encode(src, len, tmp, lower);
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 }