Mercurial > hg > nginx-quic
annotate src/http/v3/ngx_http_v3_request.c @ 7946:908cae4f3078 quic
HTTP/3: do not emit a DATA frame header for header_only responses.
This resulted in the frame error due to the invalid DATA frame length.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 25 Jun 2020 20:31:13 +0300 |
parents | 5b367070cc9c |
children | a6675a976560 |
rev | line source |
---|---|
7681 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 static ngx_int_t ngx_http_v3_process_pseudo_header(ngx_http_request_t *r, | |
14 ngx_str_t *name, ngx_str_t *value); | |
15 | |
16 | |
17 struct { | |
18 ngx_str_t name; | |
19 ngx_uint_t method; | |
20 } ngx_http_v3_methods[] = { | |
21 | |
22 { ngx_string("GET"), NGX_HTTP_GET }, | |
23 { ngx_string("POST"), NGX_HTTP_POST }, | |
24 { ngx_string("HEAD"), NGX_HTTP_HEAD }, | |
25 { ngx_string("OPTIONS"), NGX_HTTP_OPTIONS }, | |
26 { ngx_string("PROPFIND"), NGX_HTTP_PROPFIND }, | |
27 { ngx_string("PUT"), NGX_HTTP_PUT }, | |
28 { ngx_string("MKCOL"), NGX_HTTP_MKCOL }, | |
29 { ngx_string("DELETE"), NGX_HTTP_DELETE }, | |
30 { ngx_string("COPY"), NGX_HTTP_COPY }, | |
31 { ngx_string("MOVE"), NGX_HTTP_MOVE }, | |
32 { ngx_string("PROPPATCH"), NGX_HTTP_PROPPATCH }, | |
33 { ngx_string("LOCK"), NGX_HTTP_LOCK }, | |
34 { ngx_string("UNLOCK"), NGX_HTTP_UNLOCK }, | |
35 { ngx_string("PATCH"), NGX_HTTP_PATCH }, | |
36 { ngx_string("TRACE"), NGX_HTTP_TRACE } | |
37 }; | |
38 | |
39 | |
40 ngx_int_t | |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
41 ngx_http_v3_parse_request(ngx_http_request_t *r, ngx_buf_t *b) |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
42 { |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
43 size_t len; |
7699
1e45c02f6376
HTTP/3 $request_line variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7696
diff
changeset
|
44 u_char *p; |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
45 ngx_int_t rc, n; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
46 ngx_str_t *name, *value; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
47 ngx_connection_t *c; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
48 ngx_http_v3_parse_headers_t *st; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
49 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
50 c = r->connection; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
51 st = r->h3_parse; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
52 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
53 if (st == NULL) { |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
54 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header"); |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
55 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
56 st = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_parse_headers_t)); |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
57 if (st == NULL) { |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
58 goto failed; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
59 } |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
60 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
61 r->h3_parse = st; |
7884
d6feece1288a
Fixed $request_length for HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7883
diff
changeset
|
62 r->parse_start = b->pos; |
7885
5b367070cc9c
Fixed client buffer reallocation for HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7884
diff
changeset
|
63 r->state = 1; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
64 } |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
65 |
7696
31f7c697b6d9
Fixed pointer increment while parsing HTTP/3 header.
Roman Arutyunyan <arut@nginx.com>
parents:
7692
diff
changeset
|
66 while (b->pos < b->last) { |
31f7c697b6d9
Fixed pointer increment while parsing HTTP/3 header.
Roman Arutyunyan <arut@nginx.com>
parents:
7692
diff
changeset
|
67 rc = ngx_http_v3_parse_headers(c, st, *b->pos++); |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
68 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
69 if (rc == NGX_ERROR) { |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
70 goto failed; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
71 } |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
72 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
73 if (rc == NGX_AGAIN) { |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
74 continue; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
75 } |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
76 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
77 name = &st->header_rep.header.name; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
78 value = &st->header_rep.header.value; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
79 |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
80 n = ngx_http_v3_process_pseudo_header(r, name, value); |
7699
1e45c02f6376
HTTP/3 $request_line variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7696
diff
changeset
|
81 |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
82 if (n == NGX_ERROR) { |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
83 goto failed; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
84 } |
7699
1e45c02f6376
HTTP/3 $request_line variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7696
diff
changeset
|
85 |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
86 if (n == NGX_OK && rc == NGX_OK) { |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
87 continue; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
88 } |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
89 |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
90 len = (r->method_end - r->method_start) + 1 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
91 + (r->uri_end - r->uri_start) + 1 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
92 + sizeof("HTTP/3") - 1; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
93 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
94 p = ngx_pnalloc(c->pool, len); |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
95 if (p == NULL) { |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
96 goto failed; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
97 } |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
98 |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
99 r->request_start = p; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
100 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
101 p = ngx_cpymem(p, r->method_start, r->method_end - r->method_start); |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
102 *p++ = ' '; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
103 p = ngx_cpymem(p, r->uri_start, r->uri_end - r->uri_start); |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
104 *p++ = ' '; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
105 p = ngx_cpymem(p, "HTTP/3", sizeof("HTTP/3") - 1); |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
106 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
107 r->request_end = p; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
108 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
109 return NGX_OK; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
110 } |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
111 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
112 return NGX_AGAIN; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
113 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
114 failed: |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
115 |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
116 return NGX_HTTP_PARSE_INVALID_REQUEST; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
117 } |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
118 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
119 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
120 ngx_int_t |
7883
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
121 ngx_http_v3_parse_header(ngx_http_request_t *r, ngx_buf_t *b, |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
122 ngx_uint_t allow_underscores) |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
123 { |
7883
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
124 u_char ch; |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
125 ngx_int_t rc; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
126 ngx_str_t *name, *value; |
7883
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
127 ngx_uint_t hash, i, n; |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
128 ngx_connection_t *c; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
129 ngx_http_v3_parse_headers_t *st; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
130 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
131 c = r->connection; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
132 st = r->h3_parse; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
133 |
7883
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
134 if (st->header_rep.state == 0) { |
7884
d6feece1288a
Fixed $request_length for HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7883
diff
changeset
|
135 r->parse_start = b->pos; |
7883
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
136 r->invalid_header = 0; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
137 } |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
138 |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
139 if (st->state == 0) { |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
140 if (r->header_name_start == NULL) { |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
141 name = &st->header_rep.header.name; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
142 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
143 if (name->len && name->data[0] != ':') { |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
144 goto done; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
145 } |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
146 } |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
147 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
148 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
149 "http3 parse header done"); |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
150 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
151 return NGX_HTTP_PARSE_HEADER_DONE; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
152 } |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
153 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
154 while (b->pos < b->last) { |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
155 rc = ngx_http_v3_parse_headers(c, st, *b->pos++); |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
156 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
157 if (rc == NGX_ERROR) { |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
158 return NGX_HTTP_PARSE_INVALID_HEADER; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
159 } |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
160 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
161 if (rc != NGX_AGAIN) { |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
162 goto done; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
163 } |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
164 } |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
165 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
166 return NGX_AGAIN; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
167 |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
168 done: |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
169 |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
170 name = &st->header_rep.header.name; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
171 value = &st->header_rep.header.value; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
172 |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
173 r->header_name_start = name->data; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
174 r->header_name_end = name->data + name->len; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
175 r->header_start = value->data; |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
176 r->header_end = value->data + value->len; |
7883
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
177 |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
178 hash = 0; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
179 i = 0; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
180 |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
181 for (n = 0; n < name->len; n++) { |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
182 ch = name->data[n]; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
183 |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
184 if (ch >= 'A' && ch <= 'Z') { |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
185 /* |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
186 * A request or response containing uppercase |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
187 * header field names MUST be treated as malformed |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
188 */ |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
189 return NGX_HTTP_PARSE_INVALID_HEADER; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
190 } |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
191 |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
192 if (ch == '\0') { |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
193 return NGX_HTTP_PARSE_INVALID_HEADER; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
194 } |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
195 |
7883
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
196 if (ch == '_' && !allow_underscores) { |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
197 r->invalid_header = 1; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
198 continue; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
199 } |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
200 |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
201 if ((ch < 'a' || ch > 'z') |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
202 && (ch < '0' || ch > '9') |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
203 && ch != '-' && ch != '_') |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
204 { |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
205 r->invalid_header = 1; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
206 continue; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
207 } |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
208 |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
209 hash = ngx_hash(hash, ch); |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
210 r->lowcase_header[i++] = ch; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
211 i &= (NGX_HTTP_LC_HEADER_LEN - 1); |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
212 } |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
213 |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
214 r->header_hash = hash; |
66feab03d9b7
HTTP/3: restricted symbols in header names.
Roman Arutyunyan <arut@nginx.com>
parents:
7882
diff
changeset
|
215 r->lowcase_index = i; |
7882
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
216 |
d2759e4cc437
HTTP/3: split header parser in two functions.
Roman Arutyunyan <arut@nginx.com>
parents:
7871
diff
changeset
|
217 return NGX_OK; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
218 } |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
219 |
7681 | 220 |
221 static ngx_int_t | |
222 ngx_http_v3_process_pseudo_header(ngx_http_request_t *r, ngx_str_t *name, | |
223 ngx_str_t *value) | |
224 { | |
225 ngx_uint_t i; | |
226 ngx_connection_t *c; | |
227 | |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
228 if (name->len == 0 || name->data[0] != ':') { |
7699
1e45c02f6376
HTTP/3 $request_line variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7696
diff
changeset
|
229 return NGX_DONE; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
230 } |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
231 |
7681 | 232 c = r->connection; |
233 | |
234 if (name->len == 7 && ngx_strncmp(name->data, ":method", 7) == 0) { | |
235 r->method_start = value->data; | |
236 r->method_end = value->data + value->len; | |
237 | |
238 for (i = 0; i < sizeof(ngx_http_v3_methods) | |
239 / sizeof(ngx_http_v3_methods[0]); i++) | |
240 { | |
241 if (value->len == ngx_http_v3_methods[i].name.len | |
242 && ngx_strncmp(value->data, ngx_http_v3_methods[i].name.data, | |
243 value->len) == 0) | |
244 { | |
245 r->method = ngx_http_v3_methods[i].method; | |
246 break; | |
247 } | |
248 } | |
249 | |
250 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
251 "http3 method \"%V\" %ui", value, r->method); | |
252 return NGX_OK; | |
253 } | |
254 | |
255 if (name->len == 5 && ngx_strncmp(name->data, ":path", 5) == 0) { | |
256 r->uri_start = value->data; | |
257 r->uri_end = value->data + value->len; | |
258 | |
259 if (ngx_http_parse_uri(r) != NGX_OK) { | |
260 ngx_log_error(NGX_LOG_INFO, c->log, 0, | |
261 "client sent invalid :path header: \"%V\"", value); | |
262 return NGX_ERROR; | |
263 } | |
264 | |
265 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
266 "http3 path \"%V\"", value); | |
267 | |
268 return NGX_OK; | |
269 } | |
270 | |
271 if (name->len == 7 && ngx_strncmp(name->data, ":scheme", 7) == 0) { | |
272 r->schema_start = value->data; | |
273 r->schema_end = value->data + value->len; | |
274 | |
275 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
276 "http3 schema \"%V\"", value); | |
277 | |
278 return NGX_OK; | |
279 } | |
280 | |
281 if (name->len == 10 && ngx_strncmp(name->data, ":authority", 10) == 0) { | |
282 r->host_start = value->data; | |
283 r->host_end = value->data + value->len; | |
284 | |
285 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
286 "http3 authority \"%V\"", value); | |
287 | |
288 return NGX_OK; | |
289 } | |
290 | |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
291 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
292 "http3 unknown pseudo header \"%V\" \"%V\"", name, value); |
7681 | 293 |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
294 return NGX_OK; |
7681 | 295 } |
296 | |
297 | |
7761
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
298 ngx_int_t |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
299 ngx_http_v3_parse_request_body(ngx_http_request_t *r, ngx_buf_t *b, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
300 ngx_http_chunked_t *ctx) |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
301 { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
302 ngx_int_t rc; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
303 ngx_connection_t *c; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
304 ngx_http_v3_parse_data_t *st; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
305 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
306 c = r->connection; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
307 st = ctx->h3_parse; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
308 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
309 if (st == NULL) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
310 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
311 "http3 parse request body"); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
312 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
313 st = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_parse_data_t)); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
314 if (st == NULL) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
315 goto failed; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
316 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
317 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
318 r->h3_parse = st; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
319 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
320 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
321 if (ctx->size) { |
7795
7bd334b8d91a
HTTP/3: fixed reading request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
322 ctx->length = ctx->size + 1; |
7bd334b8d91a
HTTP/3: fixed reading request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7761
diff
changeset
|
323 return (b->pos == b->last) ? NGX_AGAIN : NGX_OK; |
7761
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
324 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
325 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
326 while (b->pos < b->last) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
327 rc = ngx_http_v3_parse_data(c, st, *b->pos++); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
328 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
329 if (rc == NGX_ERROR) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
330 goto failed; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
331 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
332 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
333 if (rc == NGX_AGAIN) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
334 continue; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
335 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
336 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
337 /* rc == NGX_DONE */ |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
338 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
339 ctx->size = st->length; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
340 return NGX_OK; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
341 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
342 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
343 if (!b->last_buf) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
344 ctx->length = 1; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
345 return NGX_AGAIN; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
346 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
347 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
348 if (st->state) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
349 goto failed; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
350 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
351 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
352 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header done"); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
353 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
354 return NGX_DONE; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
355 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
356 failed: |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
357 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
358 return NGX_ERROR; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
359 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
360 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
7758
diff
changeset
|
361 |
7681 | 362 ngx_chain_t * |
363 ngx_http_v3_create_header(ngx_http_request_t *r) | |
364 { | |
365 u_char *p; | |
7719
69365c7bb07f
Removed unused variable.
Roman Arutyunyan <arut@nginx.com>
parents:
7704
diff
changeset
|
366 size_t len, n; |
7681 | 367 ngx_buf_t *b; |
368 ngx_uint_t i, j; | |
369 ngx_chain_t *hl, *cl, *bl; | |
370 ngx_list_part_t *part; | |
371 ngx_table_elt_t *header; | |
372 ngx_connection_t *c; | |
373 ngx_http_core_loc_conf_t *clcf; | |
374 | |
375 c = r->connection; | |
376 | |
377 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 create header"); | |
378 | |
7757 | 379 len = 2; |
7681 | 380 |
381 if (r->headers_out.status == NGX_HTTP_OK) { | |
382 len += ngx_http_v3_encode_prefix_int(NULL, 25, 6); | |
383 | |
384 } else { | |
385 len += 3 + ngx_http_v3_encode_prefix_int(NULL, 25, 4) | |
386 + ngx_http_v3_encode_prefix_int(NULL, 3, 7); | |
387 } | |
388 | |
389 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
390 | |
391 if (r->headers_out.server == NULL) { | |
392 if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) { | |
393 n = sizeof(NGINX_VER) - 1; | |
394 | |
395 } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) { | |
396 n = sizeof(NGINX_VER_BUILD) - 1; | |
397 | |
398 } else { | |
399 n = sizeof("nginx") - 1; | |
400 } | |
401 | |
402 len += ngx_http_v3_encode_prefix_int(NULL, 92, 4) | |
403 + ngx_http_v3_encode_prefix_int(NULL, n, 7) + n; | |
404 } | |
405 | |
406 if (r->headers_out.date == NULL) { | |
407 len += ngx_http_v3_encode_prefix_int(NULL, 6, 4) | |
408 + ngx_http_v3_encode_prefix_int(NULL, ngx_cached_http_time.len, | |
409 7) | |
410 + ngx_cached_http_time.len; | |
411 } | |
412 | |
413 if (r->headers_out.content_type.len) { | |
414 n = r->headers_out.content_type.len; | |
415 | |
416 if (r->headers_out.content_type_len == r->headers_out.content_type.len | |
417 && r->headers_out.charset.len) | |
418 { | |
419 n += sizeof("; charset=") - 1 + r->headers_out.charset.len; | |
420 } | |
421 | |
422 len += ngx_http_v3_encode_prefix_int(NULL, 53, 4) | |
423 + ngx_http_v3_encode_prefix_int(NULL, n, 7) + n; | |
424 } | |
425 | |
7704
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
426 if (r->headers_out.content_length_n > 0) { |
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
427 len += ngx_http_v3_encode_prefix_int(NULL, 4, 4) + 1 + NGX_OFF_T_LEN; |
7681 | 428 |
7704
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
429 } else if (r->headers_out.content_length_n == 0) { |
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
430 len += ngx_http_v3_encode_prefix_int(NULL, 4, 6); |
7681 | 431 } |
432 | |
433 if (r->headers_out.last_modified == NULL | |
434 && r->headers_out.last_modified_time != -1) | |
435 { | |
436 len += ngx_http_v3_encode_prefix_int(NULL, 10, 4) + 1 | |
437 + sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT"); | |
438 } | |
439 | |
440 /* XXX location */ | |
441 | |
442 #if (NGX_HTTP_GZIP) | |
443 if (r->gzip_vary) { | |
444 if (clcf->gzip_vary) { | |
445 /* Vary: Accept-Encoding */ | |
446 len += ngx_http_v3_encode_prefix_int(NULL, 59, 6); | |
447 | |
448 } else { | |
449 r->gzip_vary = 0; | |
450 } | |
451 } | |
452 #endif | |
453 | |
454 part = &r->headers_out.headers.part; | |
455 header = part->elts; | |
456 | |
457 for (i = 0; /* void */; i++) { | |
458 | |
459 if (i >= part->nelts) { | |
460 if (part->next == NULL) { | |
461 break; | |
462 } | |
463 | |
464 part = part->next; | |
465 header = part->elts; | |
466 i = 0; | |
467 } | |
468 | |
469 if (header[i].hash == 0) { | |
470 continue; | |
471 } | |
472 | |
473 len += ngx_http_v3_encode_prefix_int(NULL, header[i].key.len, 3) | |
474 + header[i].key.len | |
475 + ngx_http_v3_encode_prefix_int(NULL, header[i].value.len, 7 ) | |
476 + header[i].value.len; | |
477 } | |
478 | |
479 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 header len:%uz", len); | |
480 | |
481 b = ngx_create_temp_buf(r->pool, len); | |
482 if (b == NULL) { | |
483 return NULL; | |
484 } | |
485 | |
486 *b->last++ = 0; | |
487 *b->last++ = 0; | |
488 | |
489 if (r->headers_out.status == NGX_HTTP_OK) { | |
490 /* :status: 200 */ | |
491 *b->last = 0xc0; | |
492 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 25, 6); | |
493 | |
494 } else { | |
495 /* :status: 200 */ | |
496 *b->last = 0x70; | |
497 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 25, 4); | |
498 *b->last = 0; | |
499 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 3, 7); | |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7685
diff
changeset
|
500 b->last = ngx_sprintf(b->last, "%03ui", r->headers_out.status); |
7681 | 501 } |
502 | |
503 if (r->headers_out.server == NULL) { | |
504 if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) { | |
505 p = (u_char *) NGINX_VER; | |
506 n = sizeof(NGINX_VER) - 1; | |
507 | |
508 } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) { | |
509 p = (u_char *) NGINX_VER_BUILD; | |
510 n = sizeof(NGINX_VER_BUILD) - 1; | |
511 | |
512 } else { | |
513 p = (u_char *) "nginx"; | |
514 n = sizeof("nginx") - 1; | |
515 } | |
516 | |
517 /* server */ | |
518 *b->last = 0x70; | |
519 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 92, 4); | |
520 *b->last = 0; | |
521 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, n, 7); | |
522 b->last = ngx_cpymem(b->last, p, n); | |
523 } | |
524 | |
525 if (r->headers_out.date == NULL) { | |
526 /* date */ | |
527 *b->last = 0x70; | |
528 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 6, 4); | |
529 *b->last = 0; | |
530 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, | |
531 ngx_cached_http_time.len, 7); | |
532 b->last = ngx_cpymem(b->last, ngx_cached_http_time.data, | |
533 ngx_cached_http_time.len); | |
534 } | |
535 | |
536 if (r->headers_out.content_type.len) { | |
537 n = r->headers_out.content_type.len; | |
538 | |
539 if (r->headers_out.content_type_len == r->headers_out.content_type.len | |
540 && r->headers_out.charset.len) | |
541 { | |
542 n += sizeof("; charset=") - 1 + r->headers_out.charset.len; | |
543 } | |
544 | |
545 /* content-type: text/plain */ | |
546 *b->last = 0x70; | |
547 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 53, 4); | |
548 *b->last = 0; | |
549 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, n, 7); | |
550 | |
551 p = b->last; | |
552 b->last = ngx_copy(b->last, r->headers_out.content_type.data, | |
553 r->headers_out.content_type.len); | |
554 | |
555 if (r->headers_out.content_type_len == r->headers_out.content_type.len | |
556 && r->headers_out.charset.len) | |
557 { | |
558 b->last = ngx_cpymem(b->last, "; charset=", | |
559 sizeof("; charset=") - 1); | |
560 b->last = ngx_copy(b->last, r->headers_out.charset.data, | |
561 r->headers_out.charset.len); | |
562 | |
563 /* update r->headers_out.content_type for possible logging */ | |
564 | |
565 r->headers_out.content_type.len = b->last - p; | |
566 r->headers_out.content_type.data = p; | |
567 } | |
568 } | |
569 | |
7704
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
570 if (r->headers_out.content_length_n > 0) { |
7681 | 571 /* content-length: 0 */ |
572 *b->last = 0x70; | |
573 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 4, 4); | |
574 p = b->last++; | |
575 b->last = ngx_sprintf(b->last, "%O", r->headers_out.content_length_n); | |
576 *p = b->last - p - 1; | |
7704
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
577 |
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
578 } else if (r->headers_out.content_length_n == 0) { |
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
579 /* content-length: 0 */ |
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
580 *b->last = 0xc0; |
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
581 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 4, 6); |
7681 | 582 } |
583 | |
584 if (r->headers_out.last_modified == NULL | |
585 && r->headers_out.last_modified_time != -1) | |
586 { | |
587 /* last-modified */ | |
588 *b->last = 0x70; | |
589 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 10, 4); | |
590 p = b->last++; | |
591 b->last = ngx_http_time(b->last, r->headers_out.last_modified_time); | |
592 *p = b->last - p - 1; | |
593 } | |
594 | |
595 #if (NGX_HTTP_GZIP) | |
596 if (r->gzip_vary) { | |
597 /* vary: accept-encoding */ | |
598 *b->last = 0xc0; | |
599 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, 59, 6); | |
600 } | |
601 #endif | |
602 | |
603 part = &r->headers_out.headers.part; | |
604 header = part->elts; | |
605 | |
606 for (i = 0; /* void */; i++) { | |
607 | |
608 if (i >= part->nelts) { | |
609 if (part->next == NULL) { | |
610 break; | |
611 } | |
612 | |
613 part = part->next; | |
614 header = part->elts; | |
615 i = 0; | |
616 } | |
617 | |
618 if (header[i].hash == 0) { | |
619 continue; | |
620 } | |
621 | |
622 *b->last = 0x30; | |
623 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, | |
624 header[i].key.len, | |
625 3); | |
626 for (j = 0; j < header[i].key.len; j++) { | |
627 *b->last++ = ngx_tolower(header[i].key.data[j]); | |
628 } | |
629 | |
630 *b->last = 0; | |
631 b->last = (u_char *) ngx_http_v3_encode_prefix_int(b->last, | |
632 header[i].value.len, | |
633 7); | |
634 b->last = ngx_copy(b->last, header[i].value.data, header[i].value.len); | |
635 } | |
636 | |
7704
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
637 if (r->header_only) { |
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
638 b->last_buf = 1; |
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
639 } |
a3257a725b3d
Fixed header creation for header_only responses in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7699
diff
changeset
|
640 |
7681 | 641 cl = ngx_alloc_chain_link(c->pool); |
642 if (cl == NULL) { | |
643 return NULL; | |
644 } | |
645 | |
646 cl->buf = b; | |
647 cl->next = NULL; | |
648 | |
649 n = b->last - b->pos; | |
650 | |
651 len = 1 + ngx_http_v3_encode_varlen_int(NULL, n); | |
652 | |
653 b = ngx_create_temp_buf(c->pool, len); | |
654 if (b == NULL) { | |
655 return NULL; | |
656 } | |
657 | |
658 *b->last++ = NGX_HTTP_V3_FRAME_HEADERS; | |
659 b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last, n); | |
660 | |
661 hl = ngx_alloc_chain_link(c->pool); | |
662 if (hl == NULL) { | |
663 return NULL; | |
664 } | |
665 | |
666 hl->buf = b; | |
667 hl->next = cl; | |
668 | |
7946
908cae4f3078
HTTP/3: do not emit a DATA frame header for header_only responses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7885
diff
changeset
|
669 if (r->headers_out.content_length_n >= 0 && !r->header_only) { |
7681 | 670 len = 1 + ngx_http_v3_encode_varlen_int(NULL, |
671 r->headers_out.content_length_n); | |
672 | |
673 b = ngx_create_temp_buf(c->pool, len); | |
674 if (b == NULL) { | |
7871 | 675 return NULL; |
7681 | 676 } |
677 | |
678 *b->last++ = NGX_HTTP_V3_FRAME_DATA; | |
679 b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last, | |
680 r->headers_out.content_length_n); | |
681 | |
682 bl = ngx_alloc_chain_link(c->pool); | |
683 if (bl == NULL) { | |
684 return NULL; | |
685 } | |
686 | |
687 bl->buf = b; | |
688 bl->next = NULL; | |
689 cl->next = bl; | |
690 } | |
691 | |
692 return hl; | |
693 } | |
7758
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
694 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
695 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
696 ngx_chain_t * |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
697 ngx_http_v3_create_trailers(ngx_http_request_t *r) |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
698 { |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
699 ngx_buf_t *b; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
700 ngx_chain_t *cl; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
701 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
702 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
703 "http3 create trailers"); |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
704 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
705 /* XXX */ |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
706 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
707 b = ngx_calloc_buf(r->pool); |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
708 if (b == NULL) { |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
709 return NULL; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
710 } |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
711 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
712 b->last_buf = 1; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
713 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
714 cl = ngx_alloc_chain_link(r->pool); |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
715 if (cl == NULL) { |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
716 return NULL; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
717 } |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
718 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
719 cl->buf = b; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
720 cl->next = NULL; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
721 |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
722 return cl; |
46e3542d51b3
Chunked response body in HTTP/3.
Roman Arutyunyan <arut@nginx.com>
parents:
7757
diff
changeset
|
723 } |