1384Szelenkov@nginx.com 
2384Szelenkov@nginx.com /*
3384Szelenkov@nginx.com  * Copyright (C) NGINX, Inc.
4384Szelenkov@nginx.com  * Copyright (C) Valentin V. Bartenev
5384Szelenkov@nginx.com  */
6384Szelenkov@nginx.com 
7384Szelenkov@nginx.com #include <nxt_main.h>
8384Szelenkov@nginx.com #include "nxt_tests.h"
9384Szelenkov@nginx.com 
10384Szelenkov@nginx.com 
11384Szelenkov@nginx.com typedef struct {
12384Szelenkov@nginx.com     nxt_str_t  method;
13384Szelenkov@nginx.com     nxt_str_t  target;
14384Szelenkov@nginx.com     nxt_str_t  exten;
15384Szelenkov@nginx.com     nxt_str_t  args;
16384Szelenkov@nginx.com     u_char     version[8];
17384Szelenkov@nginx.com 
18384Szelenkov@nginx.com     /* target with "/." */
19384Szelenkov@nginx.com     unsigned   complex_target:1;
20384Szelenkov@nginx.com     /* target with "%" */
21384Szelenkov@nginx.com     unsigned   quoted_target:1;
22384Szelenkov@nginx.com     /* target with " " */
23384Szelenkov@nginx.com     unsigned   space_in_target:1;
24384Szelenkov@nginx.com     /* target with "+" */
25384Szelenkov@nginx.com     unsigned   plus_in_target:1;
26384Szelenkov@nginx.com } nxt_http_parse_test_request_line_t;
27384Szelenkov@nginx.com 
28384Szelenkov@nginx.com 
29384Szelenkov@nginx.com typedef union {
30384Szelenkov@nginx.com     void                                *pointer;
31384Szelenkov@nginx.com     nxt_int_t                           result;
32384Szelenkov@nginx.com     nxt_http_parse_test_request_line_t  request_line;
33384Szelenkov@nginx.com } nxt_http_parse_test_data_t;
34384Szelenkov@nginx.com 
35384Szelenkov@nginx.com 
36384Szelenkov@nginx.com typedef struct {
37384Szelenkov@nginx.com     nxt_str_t  request;
38384Szelenkov@nginx.com     nxt_int_t  result;
39384Szelenkov@nginx.com     nxt_int_t  (*handler)(nxt_http_request_parse_t *rp,
40384Szelenkov@nginx.com                           nxt_http_parse_test_data_t *data,
41384Szelenkov@nginx.com                           nxt_str_t *request, nxt_log_t *log);
42384Szelenkov@nginx.com 
43384Szelenkov@nginx.com     nxt_http_parse_test_data_t  data;
44384Szelenkov@nginx.com } nxt_http_parse_test_case_t;
45384Szelenkov@nginx.com 
46384Szelenkov@nginx.com 
47384Szelenkov@nginx.com static nxt_int_t nxt_http_parse_test_run(nxt_http_request_parse_t *rp,
48384Szelenkov@nginx.com     nxt_str_t *request);
49384Szelenkov@nginx.com static nxt_int_t nxt_http_parse_test_bench(nxt_thread_t *thr,
50417Svbart@nginx.com     nxt_str_t *request, nxt_lvlhsh_t *hash, const char *name, nxt_uint_t n);
51384Szelenkov@nginx.com static nxt_int_t nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp,
52384Szelenkov@nginx.com     nxt_http_parse_test_data_t *data,
53384Szelenkov@nginx.com     nxt_str_t *request, nxt_log_t *log);
54384Szelenkov@nginx.com static nxt_int_t nxt_http_parse_test_fields(nxt_http_request_parse_t *rp,
55384Szelenkov@nginx.com     nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log);
56384Szelenkov@nginx.com 
57384Szelenkov@nginx.com 
58384Szelenkov@nginx.com static nxt_int_t nxt_http_test_header_return(void *ctx, nxt_http_field_t *field,
59417Svbart@nginx.com     uintptr_t data);
60384Szelenkov@nginx.com 
61384Szelenkov@nginx.com 
62384Szelenkov@nginx.com static nxt_http_parse_test_case_t  nxt_http_test_cases[] = {
63384Szelenkov@nginx.com     {
64384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.0\r\n\r\n"),
65384Szelenkov@nginx.com         NXT_DONE,
66384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
67384Szelenkov@nginx.com         { .request_line = {
68384Szelenkov@nginx.com             nxt_string("GET"),
69384Szelenkov@nginx.com             nxt_string("/"),
70384Szelenkov@nginx.com             nxt_null_string,
71384Szelenkov@nginx.com             nxt_null_string,
72384Szelenkov@nginx.com             "HTTP/1.0",
73384Szelenkov@nginx.com             0, 0, 0, 0
74384Szelenkov@nginx.com         }}
75384Szelenkov@nginx.com     },
76384Szelenkov@nginx.com     {
77384Szelenkov@nginx.com         nxt_string("XXX-METHOD    /d.ir/fi+le.ext?key=val    HTTP/1.2\n\n"),
78384Szelenkov@nginx.com         NXT_DONE,
79384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
80384Szelenkov@nginx.com         { .request_line = {
81384Szelenkov@nginx.com             nxt_string("XXX-METHOD"),
82384Szelenkov@nginx.com             nxt_string("/d.ir/fi+le.ext?key=val"),
83384Szelenkov@nginx.com             nxt_string("ext?key=val"),
84384Szelenkov@nginx.com             nxt_string("key=val"),
85384Szelenkov@nginx.com             "HTTP/1.2",
86384Szelenkov@nginx.com             0, 0, 0, 1
87384Szelenkov@nginx.com         }}
88384Szelenkov@nginx.com     },
89384Szelenkov@nginx.com     {
90384Szelenkov@nginx.com         nxt_string("GET /di.r/? HTTP/1.0\r\n\r\n"),
91384Szelenkov@nginx.com         NXT_DONE,
92384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
93384Szelenkov@nginx.com         { .request_line = {
94384Szelenkov@nginx.com             nxt_string("GET"),
95384Szelenkov@nginx.com             nxt_string("/di.r/?"),
96384Szelenkov@nginx.com             nxt_null_string,
97384Szelenkov@nginx.com             nxt_string(""),
98384Szelenkov@nginx.com             "HTTP/1.0",
99384Szelenkov@nginx.com             0, 0, 0, 0
100384Szelenkov@nginx.com         }}
101384Szelenkov@nginx.com     },
102384Szelenkov@nginx.com     {
103384Szelenkov@nginx.com         nxt_string("GEt / HTTP/1.0\r\n\r\n"),
104480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
105384Szelenkov@nginx.com         NULL, { NULL }
106384Szelenkov@nginx.com     },
107384Szelenkov@nginx.com     {
108384Szelenkov@nginx.com         nxt_string("GET /\0 HTTP/1.0\r\n\r\n"),
109480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
110384Szelenkov@nginx.com         NULL, { NULL }
111384Szelenkov@nginx.com     },
112384Szelenkov@nginx.com     {
113384Szelenkov@nginx.com         nxt_string("GET /\r HTTP/1.0\r\n\r\n"),
114480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
115384Szelenkov@nginx.com         NULL, { NULL }
116384Szelenkov@nginx.com     },
117384Szelenkov@nginx.com     {
118384Szelenkov@nginx.com         nxt_string("GET /\n HTTP/1.0\r\n\r\n"),
119480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
120384Szelenkov@nginx.com         NULL, { NULL }
121384Szelenkov@nginx.com     },
122384Szelenkov@nginx.com     {
123384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.0\r\r\n"),
124480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
125384Szelenkov@nginx.com         NULL, { NULL }
126384Szelenkov@nginx.com     },
127384Szelenkov@nginx.com     {
128482Svbart@nginx.com         nxt_string("GET / HTTP/2.0\r\n"),
129482Svbart@nginx.com         NXT_HTTP_PARSE_UNSUPPORTED_VERSION,
130482Svbart@nginx.com         NULL, { NULL }
131482Svbart@nginx.com     },
132482Svbart@nginx.com     {
133384Szelenkov@nginx.com         nxt_string("GET /. HTTP/1.0\r\n\r\n"),
134384Szelenkov@nginx.com         NXT_DONE,
135384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
136384Szelenkov@nginx.com         { .request_line = {
137384Szelenkov@nginx.com             nxt_string("GET"),
138384Szelenkov@nginx.com             nxt_string("/."),
139384Szelenkov@nginx.com             nxt_null_string,
140384Szelenkov@nginx.com             nxt_null_string,
141384Szelenkov@nginx.com             "HTTP/1.0",
142384Szelenkov@nginx.com             1, 0, 0, 0
143384Szelenkov@nginx.com         }}
144384Szelenkov@nginx.com     },
145384Szelenkov@nginx.com     {
146384Szelenkov@nginx.com         nxt_string("GET /# HTTP/1.0\r\n\r\n"),
147384Szelenkov@nginx.com         NXT_DONE,
148384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
149384Szelenkov@nginx.com         { .request_line = {
150384Szelenkov@nginx.com             nxt_string("GET"),
151384Szelenkov@nginx.com             nxt_string("/#"),
152384Szelenkov@nginx.com             nxt_null_string,
153384Szelenkov@nginx.com             nxt_null_string,
154384Szelenkov@nginx.com             "HTTP/1.0",
155384Szelenkov@nginx.com             1, 0, 0, 0
156384Szelenkov@nginx.com         }}
157384Szelenkov@nginx.com     },
158384Szelenkov@nginx.com     {
159384Szelenkov@nginx.com         nxt_string("GET /?# HTTP/1.0\r\n\r\n"),
160384Szelenkov@nginx.com         NXT_DONE,
161384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
162384Szelenkov@nginx.com         { .request_line = {
163384Szelenkov@nginx.com             nxt_string("GET"),
164384Szelenkov@nginx.com             nxt_string("/?#"),
165384Szelenkov@nginx.com             nxt_null_string,
166384Szelenkov@nginx.com             nxt_string("#"),
167384Szelenkov@nginx.com             "HTTP/1.0",
168384Szelenkov@nginx.com             1, 0, 0, 0
169384Szelenkov@nginx.com         }}
170384Szelenkov@nginx.com     },
171384Szelenkov@nginx.com     {
172384Szelenkov@nginx.com         nxt_string("GET // HTTP/1.0\r\n\r\n"),
173384Szelenkov@nginx.com         NXT_DONE,
174384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
175384Szelenkov@nginx.com         { .request_line = {
176384Szelenkov@nginx.com             nxt_string("GET"),
177384Szelenkov@nginx.com             nxt_string("//"),
178384Szelenkov@nginx.com             nxt_null_string,
179384Szelenkov@nginx.com             nxt_null_string,
180384Szelenkov@nginx.com             "HTTP/1.0",
181384Szelenkov@nginx.com             1, 0, 0, 0
182384Szelenkov@nginx.com         }}
183384Szelenkov@nginx.com     },
184384Szelenkov@nginx.com     {
185384Szelenkov@nginx.com         nxt_string("GET /%20 HTTP/1.0\r\n\r\n"),
186384Szelenkov@nginx.com         NXT_DONE,
187384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
188384Szelenkov@nginx.com         { .request_line = {
189384Szelenkov@nginx.com             nxt_string("GET"),
190384Szelenkov@nginx.com             nxt_string("/%20"),
191384Szelenkov@nginx.com             nxt_null_string,
192384Szelenkov@nginx.com             nxt_null_string,
193384Szelenkov@nginx.com             "HTTP/1.0",
194384Szelenkov@nginx.com             0, 1, 0, 0
195384Szelenkov@nginx.com         }}
196384Szelenkov@nginx.com     },
197384Szelenkov@nginx.com     {
198384Szelenkov@nginx.com         nxt_string("GET / a HTTP/1.0\r\n\r\n"),
199384Szelenkov@nginx.com         NXT_DONE,
200384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
201384Szelenkov@nginx.com         { .request_line = {
202384Szelenkov@nginx.com             nxt_string("GET"),
203384Szelenkov@nginx.com             nxt_string("/ a"),
204384Szelenkov@nginx.com             nxt_null_string,
205384Szelenkov@nginx.com             nxt_null_string,
206384Szelenkov@nginx.com             "HTTP/1.0",
207384Szelenkov@nginx.com             0, 0, 1, 0
208384Szelenkov@nginx.com         }}
209384Szelenkov@nginx.com     },
210384Szelenkov@nginx.com     {
211384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.0 HTTP/1.1\r\n\r\n"),
212384Szelenkov@nginx.com         NXT_DONE,
213384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
214384Szelenkov@nginx.com         { .request_line = {
215384Szelenkov@nginx.com             nxt_string("GET"),
216384Szelenkov@nginx.com             nxt_string("/ HTTP/1.0"),
217384Szelenkov@nginx.com             nxt_null_string,
218384Szelenkov@nginx.com             nxt_null_string,
219384Szelenkov@nginx.com             "HTTP/1.1",
220384Szelenkov@nginx.com             0, 0, 1, 0
221384Szelenkov@nginx.com         }}
222384Szelenkov@nginx.com     },
223384Szelenkov@nginx.com     {
224384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
225384Szelenkov@nginx.com                    "Host: example.com\r\n\r\n"),
226384Szelenkov@nginx.com         NXT_DONE,
227384Szelenkov@nginx.com         NULL, { NULL }
228384Szelenkov@nginx.com     },
229384Szelenkov@nginx.com     {
230384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
231574Svbart@nginx.com                    "Host:example.com \r\n\r\n"),
232574Svbart@nginx.com         NXT_DONE,
233574Svbart@nginx.com         NULL, { NULL }
234574Svbart@nginx.com     },
235574Svbart@nginx.com     {
236574Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
237384Szelenkov@nginx.com                    "Host:\r\n\r\n"),
238384Szelenkov@nginx.com         NXT_DONE,
239384Szelenkov@nginx.com         NULL, { NULL }
240384Szelenkov@nginx.com     },
241384Szelenkov@nginx.com     {
242384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
243384Szelenkov@nginx.com                    "Host example.com\r\n\r\n"),
244480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
245384Szelenkov@nginx.com         NULL, { NULL }
246384Szelenkov@nginx.com     },
247384Szelenkov@nginx.com     {
248384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
249384Szelenkov@nginx.com                    ":Host: example.com\r\n\r\n"),
250480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
251384Szelenkov@nginx.com         NULL, { NULL }
252384Szelenkov@nginx.com     },
253384Szelenkov@nginx.com     {
254384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
255384Szelenkov@nginx.com                    "Ho_st: example.com\r\n\r\n"),
256454Svbart@nginx.com         NXT_DONE,
257384Szelenkov@nginx.com         NULL, { NULL }
258384Szelenkov@nginx.com     },
259384Szelenkov@nginx.com     {
260384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
261384Szelenkov@nginx.com                    "Ho\0st: example.com\r\n\r\n"),
262480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
263384Szelenkov@nginx.com         NULL, { NULL }
264384Szelenkov@nginx.com     },
265384Szelenkov@nginx.com     {
266384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
267384Szelenkov@nginx.com                    "Ho\rst: example.com\r\n\r\n"),
268480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
269384Szelenkov@nginx.com         NULL, { NULL }
270384Szelenkov@nginx.com     },
271384Szelenkov@nginx.com     {
272384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
273384Szelenkov@nginx.com                    "Host: exa\0mple.com\r\n\r\n"),
274480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
275384Szelenkov@nginx.com         NULL, { NULL }
276384Szelenkov@nginx.com     },
277384Szelenkov@nginx.com     {
278384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
279384Szelenkov@nginx.com                    "Host: exa\rmple.com\r\n\r\n"),
280480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
281384Szelenkov@nginx.com         NULL, { NULL }
282384Szelenkov@nginx.com     },
283384Szelenkov@nginx.com     {
284384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
285*575Svbart@nginx.com                    "Host: exa\bmple.com\r\n\r\n"),
286*575Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
287*575Svbart@nginx.com         NULL, { NULL }
288*575Svbart@nginx.com     },
289*575Svbart@nginx.com     {
290*575Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
291*575Svbart@nginx.com                    "Host: пример.испытание\r\n\r\n"),
292*575Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
293*575Svbart@nginx.com         NULL, { NULL }
294*575Svbart@nginx.com     },
295*575Svbart@nginx.com     {
296*575Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
297*575Svbart@nginx.com                    "Host: xn--e1afmkfd.xn--80akhbyknj4f\r\n\r\n"),
298*575Svbart@nginx.com         NXT_DONE,
299*575Svbart@nginx.com         NULL, { NULL }
300*575Svbart@nginx.com     },
301*575Svbart@nginx.com     {
302*575Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
303384Szelenkov@nginx.com                    "X-Unknown-Header: value\r\n"
304384Szelenkov@nginx.com                    "X-Good-Header: value\r\n\r\n"),
305384Szelenkov@nginx.com         NXT_DONE,
306384Szelenkov@nginx.com         &nxt_http_parse_test_fields,
307384Szelenkov@nginx.com         { .result = NXT_OK }
308384Szelenkov@nginx.com     },
309384Szelenkov@nginx.com     {
310384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
311384Szelenkov@nginx.com                    "X-Good-Header: value\r\n"
312384Szelenkov@nginx.com                    "X-Unknown-Header: value\r\n"
313384Szelenkov@nginx.com                    "X-Bad-Header: value\r\n\r\n"),
314384Szelenkov@nginx.com         NXT_DONE,
315384Szelenkov@nginx.com         &nxt_http_parse_test_fields,
316384Szelenkov@nginx.com         { .result = NXT_ERROR }
317384Szelenkov@nginx.com     },
318384Szelenkov@nginx.com };
319384Szelenkov@nginx.com 
320384Szelenkov@nginx.com 
321417Svbart@nginx.com static nxt_http_field_proc_t  nxt_http_test_fields[] = {
322384Szelenkov@nginx.com     { nxt_string("X-Bad-Header"),
323384Szelenkov@nginx.com       &nxt_http_test_header_return,
324417Svbart@nginx.com       NXT_ERROR },
325384Szelenkov@nginx.com 
326384Szelenkov@nginx.com     { nxt_string("X-Good-Header"),
327384Szelenkov@nginx.com       &nxt_http_test_header_return,
328417Svbart@nginx.com       NXT_OK },
329384Szelenkov@nginx.com };
330384Szelenkov@nginx.com 
331384Szelenkov@nginx.com 
332417Svbart@nginx.com static nxt_lvlhsh_t  nxt_http_test_fields_hash;
333417Svbart@nginx.com 
334417Svbart@nginx.com 
335417Svbart@nginx.com static nxt_http_field_proc_t  nxt_http_test_bench_fields[] = {
336384Szelenkov@nginx.com     { nxt_string("Host"),
337384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
338384Szelenkov@nginx.com     { nxt_string("User-Agent"),
339384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
340417Svbart@nginx.com     { nxt_string("Accept"),
341417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
342384Szelenkov@nginx.com     { nxt_string("Accept-Encoding"),
343384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
344384Szelenkov@nginx.com     { nxt_string("Accept-Language"),
345384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
346384Szelenkov@nginx.com     { nxt_string("Connection"),
347384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
348384Szelenkov@nginx.com     { nxt_string("Content-Length"),
349384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
350417Svbart@nginx.com     { nxt_string("Content-Range"),
351417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
352384Szelenkov@nginx.com     { nxt_string("Content-Type"),
353384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
354417Svbart@nginx.com     { nxt_string("Cookie"),
355417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
356417Svbart@nginx.com     { nxt_string("Range"),
357417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
358417Svbart@nginx.com     { nxt_string("If-Range"),
359417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
360417Svbart@nginx.com     { nxt_string("Transfer-Encoding"),
361417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
362417Svbart@nginx.com     { nxt_string("Expect"),
363417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
364417Svbart@nginx.com     { nxt_string("Via"),
365417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
366384Szelenkov@nginx.com     { nxt_string("If-Modified-Since"),
367384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
368417Svbart@nginx.com     { nxt_string("If-Unmodified-Since"),
369417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
370384Szelenkov@nginx.com     { nxt_string("If-Match"),
371384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
372417Svbart@nginx.com     { nxt_string("If-None-Match"),
373417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
374417Svbart@nginx.com     { nxt_string("Referer"),
375417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
376384Szelenkov@nginx.com     { nxt_string("Date"),
377384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
378384Szelenkov@nginx.com     { nxt_string("Upgrade"),
379384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
380417Svbart@nginx.com     { nxt_string("Authorization"),
381417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
382417Svbart@nginx.com     { nxt_string("Keep-Alive"),
383417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
384384Szelenkov@nginx.com     { nxt_string("X-Forwarded-For"),
385384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
386417Svbart@nginx.com     { nxt_string("X-Forwarded-Host"),
387417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
388417Svbart@nginx.com     { nxt_string("X-Forwarded-Proto"),
389417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
390417Svbart@nginx.com     { nxt_string("X-Http-Method-Override"),
391417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
392417Svbart@nginx.com     { nxt_string("X-Real-IP"),
393417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
394384Szelenkov@nginx.com     { nxt_string("X-Request-ID"),
395384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
396417Svbart@nginx.com     { nxt_string("TE"),
397417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
398417Svbart@nginx.com     { nxt_string("Pragma"),
399417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
400417Svbart@nginx.com     { nxt_string("Cache-Control"),
401417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
402417Svbart@nginx.com     { nxt_string("Origin"),
403417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
404417Svbart@nginx.com     { nxt_string("Upgrade-Insecure-Requests"),
405417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
406384Szelenkov@nginx.com };
407384Szelenkov@nginx.com 
408384Szelenkov@nginx.com 
409384Szelenkov@nginx.com static nxt_str_t nxt_http_test_simple_request = nxt_string(
410384Szelenkov@nginx.com     "GET /page HTTP/1.1\r\n"
411384Szelenkov@nginx.com     "Host: example.com\r\n\r\n"
412384Szelenkov@nginx.com );
413384Szelenkov@nginx.com 
414384Szelenkov@nginx.com 
415384Szelenkov@nginx.com static nxt_str_t nxt_http_test_big_request = nxt_string(
416384Szelenkov@nginx.com     "POST /path/to/very/interesting/article/on.this.site?arg1=value&arg2=value"
417384Szelenkov@nginx.com         "2&very_big_arg=even_bigger_value HTTP/1.1\r\n"
418384Szelenkov@nginx.com     "Host: www.example.com\r\n"
419384Szelenkov@nginx.com     "User-Agent: Mozilla/5.0 (X11; Gentoo Linux x86_64; rv:42.0) Firefox/42.0"
420384Szelenkov@nginx.com         "\r\n"
421384Szelenkov@nginx.com     "Accept: text/html,application/json,application/xml;q=0.9,*/*;q=0.8\r\n"
422384Szelenkov@nginx.com     "Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4\r\n"
423384Szelenkov@nginx.com     "Accept-Encoding: gzip, deflate, br\r\n"
424384Szelenkov@nginx.com     "If-Modified-Since: Wed, 31 Dec 1986 16:00:00 GMT\r\n"
425384Szelenkov@nginx.com     "Referer: https://example.org/path/to/not-interesting/article.html\r\n"
426384Szelenkov@nginx.com     "Cookie: name=value; name2=value2; some_big_cookie=iVBORw0KGgoAAAANSUhEUgA"
427384Szelenkov@nginx.com         "AAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABmelRY"
428384Szelenkov@nginx.com         "dFJhdyBwcm9maWxlIHR5cGUgZXhpZgAAeNptitsJgEAMBP9ThSWsZy6PcvKhcB1YvjEni"
429384Szelenkov@nginx.com         "ODAwjAs7ec4aCmkEXc1cREk7OwtUgyTFRA3BU+vFPjS7gUI/p46Q0u2fP/1B7oA1Scbwk"
430384Szelenkov@nginx.com         "nkf9gAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACfUExURQwMDDw8PFBQUAICAhQUFAcHBxs"
431384Szelenkov@nginx.com         "bGxEREQkJCTk5OTU1NSAgIFRUVB8fH0xMTCUlJVtbW0pKSikpKS8vL0BAQEZGRjMzM2Bg"
432384Szelenkov@nginx.com         "YL6+vsDAwLS0tF1dXXJycrGxsWVlZWhoaKenp29vb6urq8TExHp6epSUlLu7u66urqOjo"
433384Szelenkov@nginx.com         "5ycnH9/f4CAgJOTk5qamo6OjoWFhYiIiHd3d8nJyc/Pz9LS0ojXP1QAAAihSURBVFjDZV"
434384Szelenkov@nginx.com         "eHdqM6EBUYEEh0EM3gCu41+/7/294dCSfZsxOHeM8yV3f6iGVGYohNEtJPGEjPiSLpMTz"
435384Szelenkov@nginx.com         "zokg8DmGOCOm/P0I6MTPaBGDPCGEYV3kEzchjzPOSPIkk8BzuM8fSCOFfALER+6MdpnaV"
436384Szelenkov@nginx.com         "55FMoOP7UliioK8QzpiT0Qv0Fl4lDJvFPwChETuHFjhw7vhRVcGAXDqcfhhnRaZUWeJTW"
437384Szelenkov@nginx.com         "pYVCBEYAJihtCsUpIhyq6win3ueDCoRBIknJRwACtz3AJhDYBhESsmyEjhaKv0MRJIIFR"
438384Szelenkov@nginx.com         "d4XyYqC1RWwQFeBF2CcApCmEFI2KwHTRIrsMq8UnYcRUkehKtlaGeq8BjowKHEQf7oEgH"
439384Szelenkov@nginx.com         "JcKRWpSeZpTIrs5dKlGX9fF7GfrtdWqDAuce1IyOtLbWyRKRYIIIPBo63gswO07q20/p6"
440384Szelenkov@nginx.com         "2txvj+flvUZUZeQ4IODBGDoYivoReREzugaAJKuX637dP0/DbnMGwuWyTTNlBYX0ItL3E"
441384Szelenkov@nginx.com         "q2ptUmYZi9+ANLt9r2+nrqmORKD1/W9Xi3hirisEumQOz+qRv5hUL/H1bg7tG0znKbHCy"
442384Szelenkov@nginx.com         "Zs16u6TgmiQH5rLW2Ltslhf6kjO1bjOJ4PTfu1PwDgeR0BsF6BBCBQIThee+P78QvAQNS"
443384Szelenkov@nginx.com         "X17mD/tfXYaMBejAAhWWahqoiB5q8dmYQ9rc+AF7Trmn2BLC7vy4XQ0ADpHZmJRQPznVO"
444384Szelenkov@nginx.com         "0YcABJRnBwBg+Tofm3a//2q7zYREIAAyAQRQQKqAJ/ksH4CPC4wJy9uma2eA2+syjtsVn"
445384Szelenkov@nginx.com         "LicKzDTRYaqMgi/AQyHQNSPY0uyb7vdHVEcezDQBhAHJXLPqLOZxN8+CLJVehmapoUX2u"
446384Szelenkov@nginx.com         "54okzsIXACucAOYyunov62AUDiN0IQd69+dyAf7PfdsLlRGAGwXekowIgySRzoMzZzcAj"
447384Szelenkov@nginx.com         "gpxIs9Ti+TsTghLMvV1Lfbvt+vbTR9ZAJtlWoXxSIwaxuohCUt8Pp3LTd+XHt01KF9XZL"
448384Szelenkov@nginx.com         "iRhXkSwKCzYg7X2NwGYYJsRvCHU6nndNO3SH4TauV9v3OK7rUKHnUJaiTxRl4XODwD8mC"
449384Szelenkov@nginx.com         "Gptn0Q8j1e4oOmmfi0iZY/naRuWaIyiNI1bxDljs/7M4Hcxlta9fzTd/qubrrdYpNZ2GL"
450384Szelenkov@nginx.com         "ZxgJboFkmFVhGLLPE/6ubPp5nNTphOAGj/QHavtZ292t3KLouiQocqbXhRKOlr+/9hoA0"
451384Szelenkov@nginx.com         "og/d+dzi0/+2b7nTr60vXbtZhJkQZx2GaLsNMxZ8ozk5gphN/M4i79nBo/uwHdJPn1Db7"
452384Szelenkov@nginx.com         "c40aUgoDRVdTmhn3awbsXxOs4PZfc2i+vrrTNCEe+/0JnTmkoZOiJcT2co4i5z9hnHu6Z"
453384Szelenkov@nginx.com         "bxoT7sWAM3mfp9O7Vd7rnUV6E8ap2lk/MdmJzD2eyRohKrf4+DmON2ej6HZ31epnnqpLg"
454384Szelenkov@nginx.com         "ZV8dmFMw6fB0vww0Gs903ToJaviOifdnrXS6SxhgjjxNEF9BH6VlUVMKqf+STqPTLpeHr"
455384Szelenkov@nginx.com         "0l2HYHaYeHohVZiOIYUYjhjHfx0cLAHI96Qrzi4BXeYxiRi94PjeH4/k8xshgO8u0HYoI"
456384Szelenkov@nginx.com         "EIDvQgzEPOJIaGAlSSQQye54nzbH3Wb3wFSJ9SJAi0XAZ33NwXUXC5dJFIRHvZo7n0Z3J"
457384Szelenkov@nginx.com         "oDNaYef0zVd2bFZJjDzEmhByWfQ8bi/gDDpuz7NCa4RidhivT90w7B51tfXpV+F2CVEqd"
458384Szelenkov@nginx.com         "eamC+gj5cYznSYawCYwSPvEIbP3ArqXXdeXze3MUUNBJbSAGHgGuOZ7maazAfAoXnnaP8"
459384Szelenkov@nginx.com         "yN9kdj8fhjPY8TNt6FWchDTbsVB4s196jANI3XwNQPPXM9LSLmZ/Ae0f8nuGC2lhPK5md"
460384Szelenkov@nginx.com         "++zbh76B8V0Wmaz0aOB7epHy5XA4b3ZIgt1puvYYrCkaQZyhCrjZ1ehw+B//An2skMYLh"
461384Szelenkov@nginx.com         "GDCXB3b43Q6dhSL+7NHQ0YZYW3yyVfgyUwoOI1WABje3IkkBRMHRPmmPWxupyM4nF/jek"
462384Szelenkov@nginx.com         "mrp8pSSSqap++aSADA1ZuTtsLTewPgKmfadx2q8YwNZVwhDzJVZnbGfEcDOB8A/Y1wDAV"
463384Szelenkov@nginx.com         "iRxtHVLF321EiTJf3u0b+osLgglyTximcUQr6NJ2ZvwDAxwa9ejg8l7wcDsOAZLptwzgr"
464384Szelenkov@nginx.com         "LUXLdOC5nF5yPi6giFAYsbTwbwQHcRCejFCHA/lwwoZFZRBjvZlbGJ4mGylj8E27giJDo"
465384Szelenkov@nginx.com         "SQCsvJyR702xwGz8X5dp7qSMuy7lGcmhBrB13XxC8Asw7zIueBJ/brvEINHvzRLeSmS3C"
466384Szelenkov@nginx.com         "SfTgHDwaXKIOd5c4/RoYzrRHiOtbpOm8391dNuhXW3rECBzwC+qWQS+IAZABSBE+VoJzV"
467384Szelenkov@nginx.com         "6P+e5Wl9u9wlZRJtNjEXTLq1INwHdhvxZH9GkcFI8HFqAsWDLhYw5k0W8Hl8Y0fUSFxBs"
468384Szelenkov@nginx.com         "9CquLGFKQBfcDODPrQGPnPpRlADAiZEMCVb1/r0lAkjD0kq9xSJnmj/7NoEiYUxAElOOA"
469384Szelenkov@nginx.com         "SMoFgwAUhbKpnmANhTTFSXD+x6jEjJm+CaUXIdfJhFuN3RLy3GbcBcqYjJPKH8QwGWdod"
470384Szelenkov@nginx.com         "nbEgqOMQD6xpXQJ/fjelXlgKU9vghk4S0KwZIC15YSvXjZ15awslAHzP00008iUEE7oC4"
471384Szelenkov@nginx.com         "r7nKHerJAl18gGRGPAMwzez2GVpmFFhEAAKOe5CN6ZL6v0znPpVcluBMyj2ZDHhWLhciT"
472384Szelenkov@nginx.com         "Ctq4UKb9uIIfV3ChqzvJpxvpWBIeAOheSXQ8ZEEig2DhyjyqSqVoJ9j2W0y2knLW16dCd"
473384Szelenkov@nginx.com         "6EjyQ0a/E23IDDwowJ5IFJsMzJaRAEoxOFy1S+tXDAAcMdlxoP4w7UtnABQe0nhUa1HES"
474384Szelenkov@nginx.com         "5kVennooC/WWEpANRLK4mYjplkcy/ViU+n627I8gjXIJ9L5APiCDYiqFD7IIYLWKoKySj"
475384Szelenkov@nginx.com         "lUXleNM9TzcSfdxRGqlKijGALtTVJA7bgi0RVRaByyhjqP1S73BxPyjoeM47LPRqvVInU"
476384Szelenkov@nginx.com         "cvGoCit3GRpZ5VC0XZ1zpg6pb1AqLAhDD8L/AcHH1p8sEFAHAAAAAElFTkSuQmCC\r\n"
477384Szelenkov@nginx.com     "Connection: keep-alive\r\n"
478384Szelenkov@nginx.com     "Content-Length: 0\r\n"
479384Szelenkov@nginx.com     "Upgrade-Insecure-Requests: 1\r\n"
480384Szelenkov@nginx.com     "Pragma: no-cache\r\n"
481384Szelenkov@nginx.com     "Cache-Control: no-cache\r\n"
482384Szelenkov@nginx.com     "X-Forwarded-For: 192.0.2.0, 198.51.100.0, 203.0.113.0\r\n"
483384Szelenkov@nginx.com     "\r\n"
484384Szelenkov@nginx.com );
485384Szelenkov@nginx.com 
486384Szelenkov@nginx.com 
487384Szelenkov@nginx.com nxt_int_t
488384Szelenkov@nginx.com nxt_http_parse_test(nxt_thread_t *thr)
489384Szelenkov@nginx.com {
490384Szelenkov@nginx.com     nxt_mp_t                    *mp, *mp_temp;
491384Szelenkov@nginx.com     nxt_int_t                   rc;
492417Svbart@nginx.com     nxt_uint_t                  i, colls, lvl_colls;
493417Svbart@nginx.com     nxt_lvlhsh_t                hash;
494384Szelenkov@nginx.com     nxt_http_request_parse_t    rp;
495384Szelenkov@nginx.com     nxt_http_parse_test_case_t  *test;
496384Szelenkov@nginx.com 
497384Szelenkov@nginx.com     nxt_thread_time_update(thr);
498384Szelenkov@nginx.com 
499384Szelenkov@nginx.com     mp = nxt_mp_create(1024, 128, 256, 32);
500384Szelenkov@nginx.com     if (mp == NULL) {
501384Szelenkov@nginx.com         return NXT_ERROR;
502384Szelenkov@nginx.com     }
503384Szelenkov@nginx.com 
504417Svbart@nginx.com     rc = nxt_http_fields_hash(&nxt_http_test_fields_hash, mp,
505417Svbart@nginx.com                               nxt_http_test_fields,
506417Svbart@nginx.com                               nxt_nitems(nxt_http_test_fields));
507417Svbart@nginx.com     if (rc != NXT_OK) {
508384Szelenkov@nginx.com         return NXT_ERROR;
509384Szelenkov@nginx.com     }
510384Szelenkov@nginx.com 
511384Szelenkov@nginx.com     for (i = 0; i < nxt_nitems(nxt_http_test_cases); i++) {
512384Szelenkov@nginx.com         test = &nxt_http_test_cases[i];
513384Szelenkov@nginx.com 
514384Szelenkov@nginx.com         nxt_memzero(&rp, sizeof(nxt_http_request_parse_t));
515384Szelenkov@nginx.com 
516384Szelenkov@nginx.com         mp_temp = nxt_mp_create(1024, 128, 256, 32);
517384Szelenkov@nginx.com         if (mp_temp == NULL) {
518384Szelenkov@nginx.com             return NXT_ERROR;
519384Szelenkov@nginx.com         }
520384Szelenkov@nginx.com 
521384Szelenkov@nginx.com         if (nxt_http_parse_request_init(&rp, mp_temp) != NXT_OK) {
522384Szelenkov@nginx.com             return NXT_ERROR;
523384Szelenkov@nginx.com         }
524384Szelenkov@nginx.com 
525384Szelenkov@nginx.com         rc = nxt_http_parse_test_run(&rp, &test->request);
526384Szelenkov@nginx.com 
527384Szelenkov@nginx.com         if (rc != test->result) {
528384Szelenkov@nginx.com             nxt_log_alert(thr->log, "http parse test case failed:\n"
529384Szelenkov@nginx.com                                     " - request:\n\"%V\"\n"
530384Szelenkov@nginx.com                                     " - result: %i (expected: %i)",
531384Szelenkov@nginx.com                                     &test->request, rc, test->result);
532384Szelenkov@nginx.com             return NXT_ERROR;
533384Szelenkov@nginx.com         }
534384Szelenkov@nginx.com 
535384Szelenkov@nginx.com         if (test->handler != NULL
536384Szelenkov@nginx.com             && test->handler(&rp, &test->data, &test->request, thr->log)
537384Szelenkov@nginx.com                != NXT_OK)
538384Szelenkov@nginx.com         {
539384Szelenkov@nginx.com             return NXT_ERROR;
540384Szelenkov@nginx.com         }
541384Szelenkov@nginx.com 
542384Szelenkov@nginx.com         nxt_mp_destroy(mp_temp);
543384Szelenkov@nginx.com     }
544384Szelenkov@nginx.com 
545384Szelenkov@nginx.com     nxt_log_error(NXT_LOG_NOTICE, thr->log, "http parse test passed");
546384Szelenkov@nginx.com 
547417Svbart@nginx.com     nxt_memzero(&hash, sizeof(nxt_lvlhsh_t));
548417Svbart@nginx.com 
549417Svbart@nginx.com     colls = nxt_http_fields_hash_collisions(&hash, mp,
550417Svbart@nginx.com                                         nxt_http_test_bench_fields,
551417Svbart@nginx.com                                         nxt_nitems(nxt_http_test_bench_fields),
552417Svbart@nginx.com                                         0);
553417Svbart@nginx.com 
554417Svbart@nginx.com     nxt_memzero(&hash, sizeof(nxt_lvlhsh_t));
555417Svbart@nginx.com 
556417Svbart@nginx.com     lvl_colls = nxt_http_fields_hash_collisions(&hash, mp,
557417Svbart@nginx.com                                         nxt_http_test_bench_fields,
558417Svbart@nginx.com                                         nxt_nitems(nxt_http_test_bench_fields),
559417Svbart@nginx.com                                         1);
560417Svbart@nginx.com 
561417Svbart@nginx.com     nxt_log_error(NXT_LOG_NOTICE, thr->log,
562494Spluknet@nginx.com                   "http parse test hash collisions %ui out of %uz, level: %ui",
563417Svbart@nginx.com                   colls, nxt_nitems(nxt_http_test_bench_fields), lvl_colls);
564417Svbart@nginx.com 
565417Svbart@nginx.com     nxt_memzero(&hash, sizeof(nxt_lvlhsh_t));
566417Svbart@nginx.com 
567417Svbart@nginx.com     rc = nxt_http_fields_hash(&hash, mp, nxt_http_test_bench_fields,
568417Svbart@nginx.com                               nxt_nitems(nxt_http_test_bench_fields));
569417Svbart@nginx.com     if (rc != NXT_OK) {
570384Szelenkov@nginx.com         return NXT_ERROR;
571384Szelenkov@nginx.com     }
572384Szelenkov@nginx.com 
573384Szelenkov@nginx.com     if (nxt_http_parse_test_bench(thr, &nxt_http_test_simple_request,
574417Svbart@nginx.com                                   &hash, "simple", 1000000)
575384Szelenkov@nginx.com         != NXT_OK)
576384Szelenkov@nginx.com     {
577384Szelenkov@nginx.com         return NXT_ERROR;
578384Szelenkov@nginx.com     }
579384Szelenkov@nginx.com 
580384Szelenkov@nginx.com     if (nxt_http_parse_test_bench(thr, &nxt_http_test_big_request,
581417Svbart@nginx.com                                   &hash, "big", 100000)
582384Szelenkov@nginx.com         != NXT_OK)
583384Szelenkov@nginx.com     {
584384Szelenkov@nginx.com         return NXT_ERROR;
585384Szelenkov@nginx.com     }
586384Szelenkov@nginx.com 
587384Szelenkov@nginx.com     nxt_mp_destroy(mp);
588384Szelenkov@nginx.com 
589384Szelenkov@nginx.com     return NXT_OK;
590384Szelenkov@nginx.com }
591384Szelenkov@nginx.com 
592384Szelenkov@nginx.com 
593384Szelenkov@nginx.com static nxt_int_t
594384Szelenkov@nginx.com nxt_http_parse_test_run(nxt_http_request_parse_t *rp, nxt_str_t *request)
595384Szelenkov@nginx.com {
596384Szelenkov@nginx.com     nxt_int_t      rc;
597384Szelenkov@nginx.com     nxt_buf_mem_t  buf;
598384Szelenkov@nginx.com 
599384Szelenkov@nginx.com     buf.start = request->start;
600384Szelenkov@nginx.com     buf.end = request->start + request->length;
601384Szelenkov@nginx.com 
602384Szelenkov@nginx.com     buf.pos = buf.start;
603384Szelenkov@nginx.com     buf.free = buf.pos + 1;
604384Szelenkov@nginx.com 
605384Szelenkov@nginx.com     do {
606384Szelenkov@nginx.com         buf.free++;
607384Szelenkov@nginx.com         rc = nxt_http_parse_request(rp, &buf);
608384Szelenkov@nginx.com     } while (buf.free < buf.end && rc == NXT_AGAIN);
609384Szelenkov@nginx.com 
610384Szelenkov@nginx.com     return rc;
611384Szelenkov@nginx.com }
612384Szelenkov@nginx.com 
613384Szelenkov@nginx.com 
614384Szelenkov@nginx.com static nxt_int_t
615384Szelenkov@nginx.com nxt_http_parse_test_bench(nxt_thread_t *thr, nxt_str_t *request,
616417Svbart@nginx.com     nxt_lvlhsh_t *hash, const char *name, nxt_uint_t n)
617384Szelenkov@nginx.com {
618384Szelenkov@nginx.com     nxt_mp_t                  *mp;
619384Szelenkov@nginx.com     nxt_nsec_t                start, end;
620384Szelenkov@nginx.com     nxt_uint_t                i;
621384Szelenkov@nginx.com     nxt_buf_mem_t             buf;
622384Szelenkov@nginx.com     nxt_http_request_parse_t  rp;
623384Szelenkov@nginx.com 
624384Szelenkov@nginx.com     nxt_log_error(NXT_LOG_NOTICE, thr->log,
625384Szelenkov@nginx.com                   "http parse %s request bench started: %uz bytes, %ui runs",
626384Szelenkov@nginx.com                   name, request->length, n);
627384Szelenkov@nginx.com 
628384Szelenkov@nginx.com     buf.start = request->start;
629384Szelenkov@nginx.com     buf.end = request->start + request->length;
630384Szelenkov@nginx.com 
631384Szelenkov@nginx.com     nxt_thread_time_update(thr);
632384Szelenkov@nginx.com     start = nxt_thread_monotonic_time(thr);
633384Szelenkov@nginx.com 
634384Szelenkov@nginx.com     for (i = 0; nxt_fast_path(i < n); i++) {
635384Szelenkov@nginx.com         nxt_memzero(&rp, sizeof(nxt_http_request_parse_t));
636384Szelenkov@nginx.com 
637384Szelenkov@nginx.com         mp = nxt_mp_create(1024, 128, 256, 32);
638384Szelenkov@nginx.com         if (nxt_slow_path(mp == NULL)) {
639384Szelenkov@nginx.com             return NXT_ERROR;
640384Szelenkov@nginx.com         }
641384Szelenkov@nginx.com 
642384Szelenkov@nginx.com         if (nxt_slow_path(nxt_http_parse_request_init(&rp, mp) != NXT_OK)) {
643384Szelenkov@nginx.com             return NXT_ERROR;
644384Szelenkov@nginx.com         }
645384Szelenkov@nginx.com 
646384Szelenkov@nginx.com         buf.pos = buf.start;
647384Szelenkov@nginx.com         buf.free = buf.end;
648384Szelenkov@nginx.com 
649384Szelenkov@nginx.com         if (nxt_slow_path(nxt_http_parse_request(&rp, &buf) != NXT_DONE)) {
650384Szelenkov@nginx.com             nxt_log_alert(thr->log, "http parse %s request bench failed "
651384Szelenkov@nginx.com                                     "while parsing", name);
652384Szelenkov@nginx.com             return NXT_ERROR;
653384Szelenkov@nginx.com         }
654384Szelenkov@nginx.com 
655417Svbart@nginx.com         if (nxt_slow_path(nxt_http_fields_process(rp.fields, hash, NULL)
656384Szelenkov@nginx.com                           != NXT_OK))
657384Szelenkov@nginx.com         {
658384Szelenkov@nginx.com             nxt_log_alert(thr->log, "http parse %s request bench failed "
659384Szelenkov@nginx.com                                     "while fields processing", name);
660384Szelenkov@nginx.com             return NXT_ERROR;
661384Szelenkov@nginx.com         }
662384Szelenkov@nginx.com 
663384Szelenkov@nginx.com         nxt_mp_destroy(mp);
664384Szelenkov@nginx.com     }
665384Szelenkov@nginx.com 
666384Szelenkov@nginx.com     nxt_thread_time_update(thr);
667384Szelenkov@nginx.com     end = nxt_thread_monotonic_time(thr);
668384Szelenkov@nginx.com 
669384Szelenkov@nginx.com     nxt_log_error(NXT_LOG_NOTICE, thr->log,
670384Szelenkov@nginx.com                   "http parse %s request bench: %0.3fs",
671384Szelenkov@nginx.com                   name, (end - start) / 1000000000.0);
672384Szelenkov@nginx.com 
673384Szelenkov@nginx.com     return NXT_OK;
674384Szelenkov@nginx.com }
675384Szelenkov@nginx.com 
676384Szelenkov@nginx.com 
677384Szelenkov@nginx.com static nxt_int_t
678384Szelenkov@nginx.com nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp,
679384Szelenkov@nginx.com     nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log)
680384Szelenkov@nginx.com {
681384Szelenkov@nginx.com     nxt_str_t  str;
682384Szelenkov@nginx.com 
683384Szelenkov@nginx.com     nxt_http_parse_test_request_line_t  *test = &data->request_line;
684384Szelenkov@nginx.com 
685384Szelenkov@nginx.com     if (rp->method.start != test->method.start
686384Szelenkov@nginx.com         && !nxt_strstr_eq(&rp->method, &test->method))
687384Szelenkov@nginx.com     {
688384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
689384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
690384Szelenkov@nginx.com                            " - method: \"%V\" (expected: \"%V\")",
691384Szelenkov@nginx.com                            request, &rp->method, &test->method);
692384Szelenkov@nginx.com         return NXT_ERROR;
693384Szelenkov@nginx.com     }
694384Szelenkov@nginx.com 
695384Szelenkov@nginx.com     str.length = rp->target_end - rp->target_start;
696384Szelenkov@nginx.com     str.start = rp->target_start;
697384Szelenkov@nginx.com 
698384Szelenkov@nginx.com     if (str.start != test->target.start
699384Szelenkov@nginx.com         && !nxt_strstr_eq(&str, &test->target))
700384Szelenkov@nginx.com     {
701384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
702384Szelenkov@nginx.com                             " - request:\n\"%V\"\n"
703384Szelenkov@nginx.com                             " - target: \"%V\" (expected: \"%V\")",
704384Szelenkov@nginx.com                             request, &str, &test->target);
705384Szelenkov@nginx.com         return NXT_ERROR;
706384Szelenkov@nginx.com     }
707384Szelenkov@nginx.com 
708384Szelenkov@nginx.com     str.length = (rp->exten_start != NULL) ? rp->target_end - rp->exten_start
709384Szelenkov@nginx.com                                            : 0;
710384Szelenkov@nginx.com     str.start = rp->exten_start;
711384Szelenkov@nginx.com 
712384Szelenkov@nginx.com     if (str.start != test->exten.start
713384Szelenkov@nginx.com         && !nxt_strstr_eq(&str, &test->exten))
714384Szelenkov@nginx.com     {
715384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
716384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
717384Szelenkov@nginx.com                            " - exten: \"%V\" (expected: \"%V\")",
718384Szelenkov@nginx.com                            request, &str, &test->exten);
719384Szelenkov@nginx.com         return NXT_ERROR;
720384Szelenkov@nginx.com     }
721384Szelenkov@nginx.com 
722384Szelenkov@nginx.com     str.length = (rp->args_start != NULL) ? rp->target_end - rp->args_start
723384Szelenkov@nginx.com                                           : 0;
724384Szelenkov@nginx.com     str.start = rp->args_start;
725384Szelenkov@nginx.com 
726384Szelenkov@nginx.com     if (str.start != test->args.start
727384Szelenkov@nginx.com         && !nxt_strstr_eq(&str, &test->args))
728384Szelenkov@nginx.com     {
729384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
730384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
731384Szelenkov@nginx.com                            " - args: \"%V\" (expected: \"%V\")",
732384Szelenkov@nginx.com                            request, &str, &test->args);
733384Szelenkov@nginx.com         return NXT_ERROR;
734384Szelenkov@nginx.com     }
735384Szelenkov@nginx.com 
736384Szelenkov@nginx.com     if (nxt_memcmp(rp->version.str, test->version, 8) != 0) {
737384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
738384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
739493Spluknet@nginx.com                            " - version: \"%*s\" (expected: \"%*s\")", request,
740493Spluknet@nginx.com                            (size_t) 8, rp->version.str,
741493Spluknet@nginx.com                            (size_t) 8, test->version);
742384Szelenkov@nginx.com         return NXT_ERROR;
743384Szelenkov@nginx.com     }
744384Szelenkov@nginx.com 
745384Szelenkov@nginx.com     if (rp->complex_target != test->complex_target) {
746384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
747384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
748384Szelenkov@nginx.com                            " - complex_target: %d (expected: %d)",
749384Szelenkov@nginx.com                            request, rp->complex_target, test->complex_target);
750384Szelenkov@nginx.com         return NXT_ERROR;
751384Szelenkov@nginx.com     }
752384Szelenkov@nginx.com 
753384Szelenkov@nginx.com     if (rp->quoted_target != test->quoted_target) {
754384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
755384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
756384Szelenkov@nginx.com                            " - quoted_target: %d (expected: %d)",
757384Szelenkov@nginx.com                            request, rp->quoted_target, test->quoted_target);
758384Szelenkov@nginx.com         return NXT_ERROR;
759384Szelenkov@nginx.com     }
760384Szelenkov@nginx.com 
761384Szelenkov@nginx.com     if (rp->space_in_target != test->space_in_target) {
762384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
763384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
764384Szelenkov@nginx.com                            " - space_in_target: %d (expected: %d)",
765384Szelenkov@nginx.com                            request, rp->space_in_target, test->space_in_target);
766384Szelenkov@nginx.com         return NXT_ERROR;
767384Szelenkov@nginx.com     }
768384Szelenkov@nginx.com 
769384Szelenkov@nginx.com     if (rp->plus_in_target != test->plus_in_target) {
770384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
771384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
772384Szelenkov@nginx.com                            " - plus_in_target: %d (expected: %d)",
773384Szelenkov@nginx.com                            request, rp->plus_in_target, test->plus_in_target);
774384Szelenkov@nginx.com         return NXT_ERROR;
775384Szelenkov@nginx.com     }
776384Szelenkov@nginx.com 
777384Szelenkov@nginx.com     return NXT_OK;
778384Szelenkov@nginx.com }
779384Szelenkov@nginx.com 
780384Szelenkov@nginx.com 
781384Szelenkov@nginx.com static nxt_int_t
782384Szelenkov@nginx.com nxt_http_parse_test_fields(nxt_http_request_parse_t *rp,
783384Szelenkov@nginx.com     nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log)
784384Szelenkov@nginx.com {
785384Szelenkov@nginx.com     nxt_int_t  rc;
786384Szelenkov@nginx.com 
787417Svbart@nginx.com     rc = nxt_http_fields_process(rp->fields, &nxt_http_test_fields_hash, NULL);
788384Szelenkov@nginx.com 
789384Szelenkov@nginx.com     if (rc != data->result) {
790384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test hash failed:\n"
791384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
792384Szelenkov@nginx.com                            " - result: %i (expected: %i)",
793384Szelenkov@nginx.com                            request, rc, data->result);
794384Szelenkov@nginx.com         return NXT_ERROR;
795384Szelenkov@nginx.com     }
796384Szelenkov@nginx.com 
797384Szelenkov@nginx.com     return NXT_OK;
798384Szelenkov@nginx.com }
799384Szelenkov@nginx.com 
800384Szelenkov@nginx.com 
801384Szelenkov@nginx.com static nxt_int_t
802417Svbart@nginx.com nxt_http_test_header_return(void *ctx, nxt_http_field_t *field, uintptr_t data)
803384Szelenkov@nginx.com {
804417Svbart@nginx.com     return data;
805384Szelenkov@nginx.com }
806