xref: /unit/src/test/nxt_http_parse_test.c (revision 1170)
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 } nxt_http_parse_test_request_line_t;
25384Szelenkov@nginx.com 
26384Szelenkov@nginx.com 
27384Szelenkov@nginx.com typedef union {
28384Szelenkov@nginx.com     void                                *pointer;
29384Szelenkov@nginx.com     nxt_int_t                           result;
30384Szelenkov@nginx.com     nxt_http_parse_test_request_line_t  request_line;
31384Szelenkov@nginx.com } nxt_http_parse_test_data_t;
32384Szelenkov@nginx.com 
33384Szelenkov@nginx.com 
34384Szelenkov@nginx.com typedef struct {
35384Szelenkov@nginx.com     nxt_str_t  request;
36384Szelenkov@nginx.com     nxt_int_t  result;
37384Szelenkov@nginx.com     nxt_int_t  (*handler)(nxt_http_request_parse_t *rp,
38384Szelenkov@nginx.com                           nxt_http_parse_test_data_t *data,
39384Szelenkov@nginx.com                           nxt_str_t *request, nxt_log_t *log);
40384Szelenkov@nginx.com 
41384Szelenkov@nginx.com     nxt_http_parse_test_data_t  data;
42384Szelenkov@nginx.com } nxt_http_parse_test_case_t;
43384Szelenkov@nginx.com 
44384Szelenkov@nginx.com 
45384Szelenkov@nginx.com static nxt_int_t nxt_http_parse_test_run(nxt_http_request_parse_t *rp,
46384Szelenkov@nginx.com     nxt_str_t *request);
47384Szelenkov@nginx.com static nxt_int_t nxt_http_parse_test_bench(nxt_thread_t *thr,
48417Svbart@nginx.com     nxt_str_t *request, nxt_lvlhsh_t *hash, const char *name, nxt_uint_t n);
49384Szelenkov@nginx.com static nxt_int_t nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp,
50384Szelenkov@nginx.com     nxt_http_parse_test_data_t *data,
51384Szelenkov@nginx.com     nxt_str_t *request, nxt_log_t *log);
52384Szelenkov@nginx.com static nxt_int_t nxt_http_parse_test_fields(nxt_http_request_parse_t *rp,
53384Szelenkov@nginx.com     nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log);
54384Szelenkov@nginx.com 
55384Szelenkov@nginx.com 
56384Szelenkov@nginx.com static nxt_int_t nxt_http_test_header_return(void *ctx, nxt_http_field_t *field,
57417Svbart@nginx.com     uintptr_t data);
58384Szelenkov@nginx.com 
59384Szelenkov@nginx.com 
60384Szelenkov@nginx.com static nxt_http_parse_test_case_t  nxt_http_test_cases[] = {
61384Szelenkov@nginx.com     {
62384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.0\r\n\r\n"),
63384Szelenkov@nginx.com         NXT_DONE,
64384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
65384Szelenkov@nginx.com         { .request_line = {
66384Szelenkov@nginx.com             nxt_string("GET"),
67384Szelenkov@nginx.com             nxt_string("/"),
68384Szelenkov@nginx.com             nxt_null_string,
69384Szelenkov@nginx.com             nxt_null_string,
70384Szelenkov@nginx.com             "HTTP/1.0",
71*1170Svbart@nginx.com             0, 0, 0
72384Szelenkov@nginx.com         }}
73384Szelenkov@nginx.com     },
74384Szelenkov@nginx.com     {
75384Szelenkov@nginx.com         nxt_string("XXX-METHOD    /d.ir/fi+le.ext?key=val    HTTP/1.2\n\n"),
76384Szelenkov@nginx.com         NXT_DONE,
77384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
78384Szelenkov@nginx.com         { .request_line = {
79384Szelenkov@nginx.com             nxt_string("XXX-METHOD"),
80384Szelenkov@nginx.com             nxt_string("/d.ir/fi+le.ext?key=val"),
811168Svbart@nginx.com             nxt_string("ext"),
82384Szelenkov@nginx.com             nxt_string("key=val"),
83384Szelenkov@nginx.com             "HTTP/1.2",
84*1170Svbart@nginx.com             0, 0, 0
85384Szelenkov@nginx.com         }}
86384Szelenkov@nginx.com     },
87384Szelenkov@nginx.com     {
88384Szelenkov@nginx.com         nxt_string("GET /di.r/? HTTP/1.0\r\n\r\n"),
89384Szelenkov@nginx.com         NXT_DONE,
90384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
91384Szelenkov@nginx.com         { .request_line = {
92384Szelenkov@nginx.com             nxt_string("GET"),
93384Szelenkov@nginx.com             nxt_string("/di.r/?"),
94384Szelenkov@nginx.com             nxt_null_string,
95384Szelenkov@nginx.com             nxt_string(""),
96384Szelenkov@nginx.com             "HTTP/1.0",
97*1170Svbart@nginx.com             0, 0, 0
98384Szelenkov@nginx.com         }}
99384Szelenkov@nginx.com     },
100384Szelenkov@nginx.com     {
101384Szelenkov@nginx.com         nxt_string("GEt / HTTP/1.0\r\n\r\n"),
102480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
103384Szelenkov@nginx.com         NULL, { NULL }
104384Szelenkov@nginx.com     },
105384Szelenkov@nginx.com     {
106384Szelenkov@nginx.com         nxt_string("GET /\0 HTTP/1.0\r\n\r\n"),
107480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
108384Szelenkov@nginx.com         NULL, { NULL }
109384Szelenkov@nginx.com     },
110384Szelenkov@nginx.com     {
111384Szelenkov@nginx.com         nxt_string("GET /\r HTTP/1.0\r\n\r\n"),
112480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
113384Szelenkov@nginx.com         NULL, { NULL }
114384Szelenkov@nginx.com     },
115384Szelenkov@nginx.com     {
116384Szelenkov@nginx.com         nxt_string("GET /\n HTTP/1.0\r\n\r\n"),
117480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
118384Szelenkov@nginx.com         NULL, { NULL }
119384Szelenkov@nginx.com     },
120384Szelenkov@nginx.com     {
121384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.0\r\r\n"),
122480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
123384Szelenkov@nginx.com         NULL, { NULL }
124384Szelenkov@nginx.com     },
125384Szelenkov@nginx.com     {
126482Svbart@nginx.com         nxt_string("GET / HTTP/2.0\r\n"),
127482Svbart@nginx.com         NXT_HTTP_PARSE_UNSUPPORTED_VERSION,
128482Svbart@nginx.com         NULL, { NULL }
129482Svbart@nginx.com     },
130482Svbart@nginx.com     {
131384Szelenkov@nginx.com         nxt_string("GET /. HTTP/1.0\r\n\r\n"),
132384Szelenkov@nginx.com         NXT_DONE,
133384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
134384Szelenkov@nginx.com         { .request_line = {
135384Szelenkov@nginx.com             nxt_string("GET"),
136384Szelenkov@nginx.com             nxt_string("/."),
137384Szelenkov@nginx.com             nxt_null_string,
138384Szelenkov@nginx.com             nxt_null_string,
139384Szelenkov@nginx.com             "HTTP/1.0",
140*1170Svbart@nginx.com             1, 0, 0
141384Szelenkov@nginx.com         }}
142384Szelenkov@nginx.com     },
143384Szelenkov@nginx.com     {
144384Szelenkov@nginx.com         nxt_string("GET /# HTTP/1.0\r\n\r\n"),
145384Szelenkov@nginx.com         NXT_DONE,
146384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
147384Szelenkov@nginx.com         { .request_line = {
148384Szelenkov@nginx.com             nxt_string("GET"),
149384Szelenkov@nginx.com             nxt_string("/#"),
150384Szelenkov@nginx.com             nxt_null_string,
151384Szelenkov@nginx.com             nxt_null_string,
152384Szelenkov@nginx.com             "HTTP/1.0",
153*1170Svbart@nginx.com             1, 0, 0
154384Szelenkov@nginx.com         }}
155384Szelenkov@nginx.com     },
156384Szelenkov@nginx.com     {
157384Szelenkov@nginx.com         nxt_string("GET /?# HTTP/1.0\r\n\r\n"),
158384Szelenkov@nginx.com         NXT_DONE,
159384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
160384Szelenkov@nginx.com         { .request_line = {
161384Szelenkov@nginx.com             nxt_string("GET"),
162384Szelenkov@nginx.com             nxt_string("/?#"),
163384Szelenkov@nginx.com             nxt_null_string,
1641168Svbart@nginx.com             nxt_string(""),
165384Szelenkov@nginx.com             "HTTP/1.0",
166*1170Svbart@nginx.com             1, 0, 0
167384Szelenkov@nginx.com         }}
168384Szelenkov@nginx.com     },
169384Szelenkov@nginx.com     {
170384Szelenkov@nginx.com         nxt_string("GET // HTTP/1.0\r\n\r\n"),
171384Szelenkov@nginx.com         NXT_DONE,
172384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
173384Szelenkov@nginx.com         { .request_line = {
174384Szelenkov@nginx.com             nxt_string("GET"),
175384Szelenkov@nginx.com             nxt_string("//"),
176384Szelenkov@nginx.com             nxt_null_string,
177384Szelenkov@nginx.com             nxt_null_string,
178384Szelenkov@nginx.com             "HTTP/1.0",
179*1170Svbart@nginx.com             1, 0, 0
180384Szelenkov@nginx.com         }}
181384Szelenkov@nginx.com     },
182384Szelenkov@nginx.com     {
183384Szelenkov@nginx.com         nxt_string("GET /%20 HTTP/1.0\r\n\r\n"),
184384Szelenkov@nginx.com         NXT_DONE,
185384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
186384Szelenkov@nginx.com         { .request_line = {
187384Szelenkov@nginx.com             nxt_string("GET"),
188384Szelenkov@nginx.com             nxt_string("/%20"),
189384Szelenkov@nginx.com             nxt_null_string,
190384Szelenkov@nginx.com             nxt_null_string,
191384Szelenkov@nginx.com             "HTTP/1.0",
192*1170Svbart@nginx.com             0, 1, 0
193384Szelenkov@nginx.com         }}
194384Szelenkov@nginx.com     },
195384Szelenkov@nginx.com     {
196384Szelenkov@nginx.com         nxt_string("GET / a HTTP/1.0\r\n\r\n"),
197384Szelenkov@nginx.com         NXT_DONE,
198384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
199384Szelenkov@nginx.com         { .request_line = {
200384Szelenkov@nginx.com             nxt_string("GET"),
201384Szelenkov@nginx.com             nxt_string("/ a"),
202384Szelenkov@nginx.com             nxt_null_string,
203384Szelenkov@nginx.com             nxt_null_string,
204384Szelenkov@nginx.com             "HTTP/1.0",
205*1170Svbart@nginx.com             0, 0, 1
206384Szelenkov@nginx.com         }}
207384Szelenkov@nginx.com     },
208384Szelenkov@nginx.com     {
209384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.0 HTTP/1.1\r\n\r\n"),
210384Szelenkov@nginx.com         NXT_DONE,
211384Szelenkov@nginx.com         &nxt_http_parse_test_request_line,
212384Szelenkov@nginx.com         { .request_line = {
213384Szelenkov@nginx.com             nxt_string("GET"),
214384Szelenkov@nginx.com             nxt_string("/ HTTP/1.0"),
215384Szelenkov@nginx.com             nxt_null_string,
216384Szelenkov@nginx.com             nxt_null_string,
217384Szelenkov@nginx.com             "HTTP/1.1",
218*1170Svbart@nginx.com             0, 0, 1
219384Szelenkov@nginx.com         }}
220384Szelenkov@nginx.com     },
221384Szelenkov@nginx.com     {
222384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
223384Szelenkov@nginx.com                    "Host: example.com\r\n\r\n"),
224384Szelenkov@nginx.com         NXT_DONE,
225384Szelenkov@nginx.com         NULL, { NULL }
226384Szelenkov@nginx.com     },
227384Szelenkov@nginx.com     {
228384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
229574Svbart@nginx.com                    "Host:example.com \r\n\r\n"),
230574Svbart@nginx.com         NXT_DONE,
231574Svbart@nginx.com         NULL, { NULL }
232574Svbart@nginx.com     },
233574Svbart@nginx.com     {
234574Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
235384Szelenkov@nginx.com                    "Host:\r\n\r\n"),
236384Szelenkov@nginx.com         NXT_DONE,
237384Szelenkov@nginx.com         NULL, { NULL }
238384Szelenkov@nginx.com     },
239384Szelenkov@nginx.com     {
240384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
241384Szelenkov@nginx.com                    "Host example.com\r\n\r\n"),
242480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
243384Szelenkov@nginx.com         NULL, { NULL }
244384Szelenkov@nginx.com     },
245384Szelenkov@nginx.com     {
246384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
247384Szelenkov@nginx.com                    ":Host: example.com\r\n\r\n"),
248480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
249384Szelenkov@nginx.com         NULL, { NULL }
250384Szelenkov@nginx.com     },
251384Szelenkov@nginx.com     {
252384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
253384Szelenkov@nginx.com                    "Ho_st: example.com\r\n\r\n"),
254454Svbart@nginx.com         NXT_DONE,
255384Szelenkov@nginx.com         NULL, { NULL }
256384Szelenkov@nginx.com     },
257384Szelenkov@nginx.com     {
258384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
259384Szelenkov@nginx.com                    "Ho\0st: example.com\r\n\r\n"),
260480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
261384Szelenkov@nginx.com         NULL, { NULL }
262384Szelenkov@nginx.com     },
263384Szelenkov@nginx.com     {
264384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
265384Szelenkov@nginx.com                    "Ho\rst: example.com\r\n\r\n"),
266480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
267384Szelenkov@nginx.com         NULL, { NULL }
268384Szelenkov@nginx.com     },
269384Szelenkov@nginx.com     {
270384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
271576Svbart@nginx.com                    "Ho\nst: example.com\r\n\r\n"),
272576Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
273576Svbart@nginx.com         NULL, { NULL }
274576Svbart@nginx.com     },
275576Svbart@nginx.com     {
276576Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
277576Svbart@nginx.com                    "Host : example.com\r\n\r\n"),
278576Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
279576Svbart@nginx.com         NULL, { NULL }
280576Svbart@nginx.com     },
281576Svbart@nginx.com     {
282576Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
283384Szelenkov@nginx.com                    "Host: exa\0mple.com\r\n\r\n"),
284480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
285384Szelenkov@nginx.com         NULL, { NULL }
286384Szelenkov@nginx.com     },
287384Szelenkov@nginx.com     {
288384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
289384Szelenkov@nginx.com                    "Host: exa\rmple.com\r\n\r\n"),
290480Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
291384Szelenkov@nginx.com         NULL, { NULL }
292384Szelenkov@nginx.com     },
293384Szelenkov@nginx.com     {
294384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
295575Svbart@nginx.com                    "Host: exa\bmple.com\r\n\r\n"),
296575Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
297575Svbart@nginx.com         NULL, { NULL }
298575Svbart@nginx.com     },
299575Svbart@nginx.com     {
300575Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
301575Svbart@nginx.com                    "Host: пример.испытание\r\n\r\n"),
302712Svbart@nginx.com         NXT_DONE,
303575Svbart@nginx.com         NULL, { NULL }
304575Svbart@nginx.com     },
305575Svbart@nginx.com     {
306575Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
307575Svbart@nginx.com                    "Host: xn--e1afmkfd.xn--80akhbyknj4f\r\n\r\n"),
308575Svbart@nginx.com         NXT_DONE,
309575Svbart@nginx.com         NULL, { NULL }
310575Svbart@nginx.com     },
311575Svbart@nginx.com     {
312575Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
313576Svbart@nginx.com                    "Host: exa\nmple.com\r\n\r\n"),
314576Svbart@nginx.com         NXT_HTTP_PARSE_INVALID,
315576Svbart@nginx.com         NULL, { NULL }
316576Svbart@nginx.com     },
317576Svbart@nginx.com     {
318576Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
319576Svbart@nginx.com                    "Host: exa\tmple.com\r\n\r\n"),
320576Svbart@nginx.com         NXT_DONE,
321576Svbart@nginx.com         NULL, { NULL }
322576Svbart@nginx.com     },
323576Svbart@nginx.com     {
324576Svbart@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
325384Szelenkov@nginx.com                    "X-Unknown-Header: value\r\n"
326384Szelenkov@nginx.com                    "X-Good-Header: value\r\n\r\n"),
327384Szelenkov@nginx.com         NXT_DONE,
328384Szelenkov@nginx.com         &nxt_http_parse_test_fields,
329384Szelenkov@nginx.com         { .result = NXT_OK }
330384Szelenkov@nginx.com     },
331384Szelenkov@nginx.com     {
332384Szelenkov@nginx.com         nxt_string("GET / HTTP/1.1\r\n"
333384Szelenkov@nginx.com                    "X-Good-Header: value\r\n"
334384Szelenkov@nginx.com                    "X-Unknown-Header: value\r\n"
335384Szelenkov@nginx.com                    "X-Bad-Header: value\r\n\r\n"),
336384Szelenkov@nginx.com         NXT_DONE,
337384Szelenkov@nginx.com         &nxt_http_parse_test_fields,
338384Szelenkov@nginx.com         { .result = NXT_ERROR }
339384Szelenkov@nginx.com     },
340384Szelenkov@nginx.com };
341384Szelenkov@nginx.com 
342384Szelenkov@nginx.com 
343417Svbart@nginx.com static nxt_http_field_proc_t  nxt_http_test_fields[] = {
344384Szelenkov@nginx.com     { nxt_string("X-Bad-Header"),
345384Szelenkov@nginx.com       &nxt_http_test_header_return,
346417Svbart@nginx.com       NXT_ERROR },
347384Szelenkov@nginx.com 
348384Szelenkov@nginx.com     { nxt_string("X-Good-Header"),
349384Szelenkov@nginx.com       &nxt_http_test_header_return,
350417Svbart@nginx.com       NXT_OK },
351384Szelenkov@nginx.com };
352384Szelenkov@nginx.com 
353384Szelenkov@nginx.com 
354417Svbart@nginx.com static nxt_lvlhsh_t  nxt_http_test_fields_hash;
355417Svbart@nginx.com 
356417Svbart@nginx.com 
357417Svbart@nginx.com static nxt_http_field_proc_t  nxt_http_test_bench_fields[] = {
358384Szelenkov@nginx.com     { nxt_string("Host"),
359384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
360384Szelenkov@nginx.com     { nxt_string("User-Agent"),
361384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
362417Svbart@nginx.com     { nxt_string("Accept"),
363417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
364384Szelenkov@nginx.com     { nxt_string("Accept-Encoding"),
365384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
366384Szelenkov@nginx.com     { nxt_string("Accept-Language"),
367384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
368384Szelenkov@nginx.com     { nxt_string("Connection"),
369384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
370384Szelenkov@nginx.com     { nxt_string("Content-Length"),
371384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
372417Svbart@nginx.com     { nxt_string("Content-Range"),
373417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
374384Szelenkov@nginx.com     { nxt_string("Content-Type"),
375384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
376417Svbart@nginx.com     { nxt_string("Cookie"),
377417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
378417Svbart@nginx.com     { nxt_string("Range"),
379417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
380417Svbart@nginx.com     { nxt_string("If-Range"),
381417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
382417Svbart@nginx.com     { nxt_string("Transfer-Encoding"),
383417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
384417Svbart@nginx.com     { nxt_string("Expect"),
385417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
386417Svbart@nginx.com     { nxt_string("Via"),
387417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
388384Szelenkov@nginx.com     { nxt_string("If-Modified-Since"),
389384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
390417Svbart@nginx.com     { nxt_string("If-Unmodified-Since"),
391417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
392384Szelenkov@nginx.com     { nxt_string("If-Match"),
393384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
394417Svbart@nginx.com     { nxt_string("If-None-Match"),
395417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
396417Svbart@nginx.com     { nxt_string("Referer"),
397417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
398384Szelenkov@nginx.com     { nxt_string("Date"),
399384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
400384Szelenkov@nginx.com     { nxt_string("Upgrade"),
401384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
402417Svbart@nginx.com     { nxt_string("Authorization"),
403417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
404417Svbart@nginx.com     { nxt_string("Keep-Alive"),
405417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
406384Szelenkov@nginx.com     { nxt_string("X-Forwarded-For"),
407384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
408417Svbart@nginx.com     { nxt_string("X-Forwarded-Host"),
409417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
410417Svbart@nginx.com     { nxt_string("X-Forwarded-Proto"),
411417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
412417Svbart@nginx.com     { nxt_string("X-Http-Method-Override"),
413417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
414417Svbart@nginx.com     { nxt_string("X-Real-IP"),
415417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
416384Szelenkov@nginx.com     { nxt_string("X-Request-ID"),
417384Szelenkov@nginx.com       &nxt_http_test_header_return, NXT_OK },
418417Svbart@nginx.com     { nxt_string("TE"),
419417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
420417Svbart@nginx.com     { nxt_string("Pragma"),
421417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
422417Svbart@nginx.com     { nxt_string("Cache-Control"),
423417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
424417Svbart@nginx.com     { nxt_string("Origin"),
425417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
426417Svbart@nginx.com     { nxt_string("Upgrade-Insecure-Requests"),
427417Svbart@nginx.com       &nxt_http_test_header_return, NXT_OK },
428384Szelenkov@nginx.com };
429384Szelenkov@nginx.com 
430384Szelenkov@nginx.com 
431384Szelenkov@nginx.com static nxt_str_t nxt_http_test_simple_request = nxt_string(
432384Szelenkov@nginx.com     "GET /page HTTP/1.1\r\n"
433384Szelenkov@nginx.com     "Host: example.com\r\n\r\n"
434384Szelenkov@nginx.com );
435384Szelenkov@nginx.com 
436384Szelenkov@nginx.com 
437384Szelenkov@nginx.com static nxt_str_t nxt_http_test_big_request = nxt_string(
438384Szelenkov@nginx.com     "POST /path/to/very/interesting/article/on.this.site?arg1=value&arg2=value"
439384Szelenkov@nginx.com         "2&very_big_arg=even_bigger_value HTTP/1.1\r\n"
440384Szelenkov@nginx.com     "Host: www.example.com\r\n"
441384Szelenkov@nginx.com     "User-Agent: Mozilla/5.0 (X11; Gentoo Linux x86_64; rv:42.0) Firefox/42.0"
442384Szelenkov@nginx.com         "\r\n"
443384Szelenkov@nginx.com     "Accept: text/html,application/json,application/xml;q=0.9,*/*;q=0.8\r\n"
444384Szelenkov@nginx.com     "Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4\r\n"
445384Szelenkov@nginx.com     "Accept-Encoding: gzip, deflate, br\r\n"
446384Szelenkov@nginx.com     "If-Modified-Since: Wed, 31 Dec 1986 16:00:00 GMT\r\n"
447384Szelenkov@nginx.com     "Referer: https://example.org/path/to/not-interesting/article.html\r\n"
448384Szelenkov@nginx.com     "Cookie: name=value; name2=value2; some_big_cookie=iVBORw0KGgoAAAANSUhEUgA"
449384Szelenkov@nginx.com         "AAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABmelRY"
450384Szelenkov@nginx.com         "dFJhdyBwcm9maWxlIHR5cGUgZXhpZgAAeNptitsJgEAMBP9ThSWsZy6PcvKhcB1YvjEni"
451384Szelenkov@nginx.com         "ODAwjAs7ec4aCmkEXc1cREk7OwtUgyTFRA3BU+vFPjS7gUI/p46Q0u2fP/1B7oA1Scbwk"
452384Szelenkov@nginx.com         "nkf9gAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACfUExURQwMDDw8PFBQUAICAhQUFAcHBxs"
453384Szelenkov@nginx.com         "bGxEREQkJCTk5OTU1NSAgIFRUVB8fH0xMTCUlJVtbW0pKSikpKS8vL0BAQEZGRjMzM2Bg"
454384Szelenkov@nginx.com         "YL6+vsDAwLS0tF1dXXJycrGxsWVlZWhoaKenp29vb6urq8TExHp6epSUlLu7u66urqOjo"
455384Szelenkov@nginx.com         "5ycnH9/f4CAgJOTk5qamo6OjoWFhYiIiHd3d8nJyc/Pz9LS0ojXP1QAAAihSURBVFjDZV"
456384Szelenkov@nginx.com         "eHdqM6EBUYEEh0EM3gCu41+/7/294dCSfZsxOHeM8yV3f6iGVGYohNEtJPGEjPiSLpMTz"
457384Szelenkov@nginx.com         "zokg8DmGOCOm/P0I6MTPaBGDPCGEYV3kEzchjzPOSPIkk8BzuM8fSCOFfALER+6MdpnaV"
458384Szelenkov@nginx.com         "55FMoOP7UliioK8QzpiT0Qv0Fl4lDJvFPwChETuHFjhw7vhRVcGAXDqcfhhnRaZUWeJTW"
459384Szelenkov@nginx.com         "pYVCBEYAJihtCsUpIhyq6win3ueDCoRBIknJRwACtz3AJhDYBhESsmyEjhaKv0MRJIIFR"
460384Szelenkov@nginx.com         "d4XyYqC1RWwQFeBF2CcApCmEFI2KwHTRIrsMq8UnYcRUkehKtlaGeq8BjowKHEQf7oEgH"
461384Szelenkov@nginx.com         "JcKRWpSeZpTIrs5dKlGX9fF7GfrtdWqDAuce1IyOtLbWyRKRYIIIPBo63gswO07q20/p6"
462384Szelenkov@nginx.com         "2txvj+flvUZUZeQ4IODBGDoYivoReREzugaAJKuX637dP0/DbnMGwuWyTTNlBYX0ItL3E"
463384Szelenkov@nginx.com         "q2ptUmYZi9+ANLt9r2+nrqmORKD1/W9Xi3hirisEumQOz+qRv5hUL/H1bg7tG0znKbHCy"
464384Szelenkov@nginx.com         "Zs16u6TgmiQH5rLW2Ltslhf6kjO1bjOJ4PTfu1PwDgeR0BsF6BBCBQIThee+P78QvAQNS"
465384Szelenkov@nginx.com         "X17mD/tfXYaMBejAAhWWahqoiB5q8dmYQ9rc+AF7Trmn2BLC7vy4XQ0ADpHZmJRQPznVO"
466384Szelenkov@nginx.com         "0YcABJRnBwBg+Tofm3a//2q7zYREIAAyAQRQQKqAJ/ksH4CPC4wJy9uma2eA2+syjtsVn"
467384Szelenkov@nginx.com         "LicKzDTRYaqMgi/AQyHQNSPY0uyb7vdHVEcezDQBhAHJXLPqLOZxN8+CLJVehmapoUX2u"
468384Szelenkov@nginx.com         "54okzsIXACucAOYyunov62AUDiN0IQd69+dyAf7PfdsLlRGAGwXekowIgySRzoMzZzcAj"
469384Szelenkov@nginx.com         "gpxIs9Ti+TsTghLMvV1Lfbvt+vbTR9ZAJtlWoXxSIwaxuohCUt8Pp3LTd+XHt01KF9XZL"
470384Szelenkov@nginx.com         "iRhXkSwKCzYg7X2NwGYYJsRvCHU6nndNO3SH4TauV9v3OK7rUKHnUJaiTxRl4XODwD8mC"
471384Szelenkov@nginx.com         "Gptn0Q8j1e4oOmmfi0iZY/naRuWaIyiNI1bxDljs/7M4Hcxlta9fzTd/qubrrdYpNZ2GL"
472384Szelenkov@nginx.com         "ZxgJboFkmFVhGLLPE/6ubPp5nNTphOAGj/QHavtZ292t3KLouiQocqbXhRKOlr+/9hoA0"
473384Szelenkov@nginx.com         "og/d+dzi0/+2b7nTr60vXbtZhJkQZx2GaLsNMxZ8ozk5gphN/M4i79nBo/uwHdJPn1Db7"
474384Szelenkov@nginx.com         "c40aUgoDRVdTmhn3awbsXxOs4PZfc2i+vrrTNCEe+/0JnTmkoZOiJcT2co4i5z9hnHu6Z"
475384Szelenkov@nginx.com         "bxoT7sWAM3mfp9O7Vd7rnUV6E8ap2lk/MdmJzD2eyRohKrf4+DmON2ej6HZ31epnnqpLg"
476384Szelenkov@nginx.com         "ZV8dmFMw6fB0vww0Gs903ToJaviOifdnrXS6SxhgjjxNEF9BH6VlUVMKqf+STqPTLpeHr"
477384Szelenkov@nginx.com         "0l2HYHaYeHohVZiOIYUYjhjHfx0cLAHI96Qrzi4BXeYxiRi94PjeH4/k8xshgO8u0HYoI"
478384Szelenkov@nginx.com         "EIDvQgzEPOJIaGAlSSQQye54nzbH3Wb3wFSJ9SJAi0XAZ33NwXUXC5dJFIRHvZo7n0Z3J"
479384Szelenkov@nginx.com         "oDNaYef0zVd2bFZJjDzEmhByWfQ8bi/gDDpuz7NCa4RidhivT90w7B51tfXpV+F2CVEqd"
480384Szelenkov@nginx.com         "eamC+gj5cYznSYawCYwSPvEIbP3ArqXXdeXze3MUUNBJbSAGHgGuOZ7maazAfAoXnnaP8"
481384Szelenkov@nginx.com         "yN9kdj8fhjPY8TNt6FWchDTbsVB4s196jANI3XwNQPPXM9LSLmZ/Ae0f8nuGC2lhPK5md"
482384Szelenkov@nginx.com         "++zbh76B8V0Wmaz0aOB7epHy5XA4b3ZIgt1puvYYrCkaQZyhCrjZ1ehw+B//An2skMYLh"
483384Szelenkov@nginx.com         "GDCXB3b43Q6dhSL+7NHQ0YZYW3yyVfgyUwoOI1WABje3IkkBRMHRPmmPWxupyM4nF/jek"
484384Szelenkov@nginx.com         "mrp8pSSSqap++aSADA1ZuTtsLTewPgKmfadx2q8YwNZVwhDzJVZnbGfEcDOB8A/Y1wDAV"
485384Szelenkov@nginx.com         "iRxtHVLF321EiTJf3u0b+osLgglyTximcUQr6NJ2ZvwDAxwa9ejg8l7wcDsOAZLptwzgr"
486384Szelenkov@nginx.com         "LUXLdOC5nF5yPi6giFAYsbTwbwQHcRCejFCHA/lwwoZFZRBjvZlbGJ4mGylj8E27giJDo"
487384Szelenkov@nginx.com         "SQCsvJyR702xwGz8X5dp7qSMuy7lGcmhBrB13XxC8Asw7zIueBJ/brvEINHvzRLeSmS3C"
488384Szelenkov@nginx.com         "SfTgHDwaXKIOd5c4/RoYzrRHiOtbpOm8391dNuhXW3rECBzwC+qWQS+IAZABSBE+VoJzV"
489384Szelenkov@nginx.com         "6P+e5Wl9u9wlZRJtNjEXTLq1INwHdhvxZH9GkcFI8HFqAsWDLhYw5k0W8Hl8Y0fUSFxBs"
490384Szelenkov@nginx.com         "9CquLGFKQBfcDODPrQGPnPpRlADAiZEMCVb1/r0lAkjD0kq9xSJnmj/7NoEiYUxAElOOA"
491384Szelenkov@nginx.com         "SMoFgwAUhbKpnmANhTTFSXD+x6jEjJm+CaUXIdfJhFuN3RLy3GbcBcqYjJPKH8QwGWdod"
492384Szelenkov@nginx.com         "nbEgqOMQD6xpXQJ/fjelXlgKU9vghk4S0KwZIC15YSvXjZ15awslAHzP00008iUEE7oC4"
493384Szelenkov@nginx.com         "r7nKHerJAl18gGRGPAMwzez2GVpmFFhEAAKOe5CN6ZL6v0znPpVcluBMyj2ZDHhWLhciT"
494384Szelenkov@nginx.com         "Ctq4UKb9uIIfV3ChqzvJpxvpWBIeAOheSXQ8ZEEig2DhyjyqSqVoJ9j2W0y2knLW16dCd"
495384Szelenkov@nginx.com         "6EjyQ0a/E23IDDwowJ5IFJsMzJaRAEoxOFy1S+tXDAAcMdlxoP4w7UtnABQe0nhUa1HES"
496384Szelenkov@nginx.com         "5kVennooC/WWEpANRLK4mYjplkcy/ViU+n627I8gjXIJ9L5APiCDYiqFD7IIYLWKoKySj"
497384Szelenkov@nginx.com         "lUXleNM9TzcSfdxRGqlKijGALtTVJA7bgi0RVRaByyhjqP1S73BxPyjoeM47LPRqvVInU"
498384Szelenkov@nginx.com         "cvGoCit3GRpZ5VC0XZ1zpg6pb1AqLAhDD8L/AcHH1p8sEFAHAAAAAElFTkSuQmCC\r\n"
499384Szelenkov@nginx.com     "Connection: keep-alive\r\n"
500384Szelenkov@nginx.com     "Content-Length: 0\r\n"
501384Szelenkov@nginx.com     "Upgrade-Insecure-Requests: 1\r\n"
502384Szelenkov@nginx.com     "Pragma: no-cache\r\n"
503384Szelenkov@nginx.com     "Cache-Control: no-cache\r\n"
504384Szelenkov@nginx.com     "X-Forwarded-For: 192.0.2.0, 198.51.100.0, 203.0.113.0\r\n"
505384Szelenkov@nginx.com     "\r\n"
506384Szelenkov@nginx.com );
507384Szelenkov@nginx.com 
508384Szelenkov@nginx.com 
509384Szelenkov@nginx.com nxt_int_t
510384Szelenkov@nginx.com nxt_http_parse_test(nxt_thread_t *thr)
511384Szelenkov@nginx.com {
512384Szelenkov@nginx.com     nxt_mp_t                    *mp, *mp_temp;
513384Szelenkov@nginx.com     nxt_int_t                   rc;
514417Svbart@nginx.com     nxt_uint_t                  i, colls, lvl_colls;
515417Svbart@nginx.com     nxt_lvlhsh_t                hash;
516384Szelenkov@nginx.com     nxt_http_request_parse_t    rp;
517384Szelenkov@nginx.com     nxt_http_parse_test_case_t  *test;
518384Szelenkov@nginx.com 
519384Szelenkov@nginx.com     nxt_thread_time_update(thr);
520384Szelenkov@nginx.com 
521384Szelenkov@nginx.com     mp = nxt_mp_create(1024, 128, 256, 32);
522384Szelenkov@nginx.com     if (mp == NULL) {
523384Szelenkov@nginx.com         return NXT_ERROR;
524384Szelenkov@nginx.com     }
525384Szelenkov@nginx.com 
526417Svbart@nginx.com     rc = nxt_http_fields_hash(&nxt_http_test_fields_hash, mp,
527417Svbart@nginx.com                               nxt_http_test_fields,
528417Svbart@nginx.com                               nxt_nitems(nxt_http_test_fields));
529417Svbart@nginx.com     if (rc != NXT_OK) {
530384Szelenkov@nginx.com         return NXT_ERROR;
531384Szelenkov@nginx.com     }
532384Szelenkov@nginx.com 
533384Szelenkov@nginx.com     for (i = 0; i < nxt_nitems(nxt_http_test_cases); i++) {
534384Szelenkov@nginx.com         test = &nxt_http_test_cases[i];
535384Szelenkov@nginx.com 
536384Szelenkov@nginx.com         nxt_memzero(&rp, sizeof(nxt_http_request_parse_t));
537384Szelenkov@nginx.com 
538384Szelenkov@nginx.com         mp_temp = nxt_mp_create(1024, 128, 256, 32);
539384Szelenkov@nginx.com         if (mp_temp == NULL) {
540384Szelenkov@nginx.com             return NXT_ERROR;
541384Szelenkov@nginx.com         }
542384Szelenkov@nginx.com 
543384Szelenkov@nginx.com         if (nxt_http_parse_request_init(&rp, mp_temp) != NXT_OK) {
544384Szelenkov@nginx.com             return NXT_ERROR;
545384Szelenkov@nginx.com         }
546384Szelenkov@nginx.com 
547384Szelenkov@nginx.com         rc = nxt_http_parse_test_run(&rp, &test->request);
548384Szelenkov@nginx.com 
549384Szelenkov@nginx.com         if (rc != test->result) {
550384Szelenkov@nginx.com             nxt_log_alert(thr->log, "http parse test case failed:\n"
551384Szelenkov@nginx.com                                     " - request:\n\"%V\"\n"
552384Szelenkov@nginx.com                                     " - result: %i (expected: %i)",
553384Szelenkov@nginx.com                                     &test->request, rc, test->result);
554384Szelenkov@nginx.com             return NXT_ERROR;
555384Szelenkov@nginx.com         }
556384Szelenkov@nginx.com 
557384Szelenkov@nginx.com         if (test->handler != NULL
558384Szelenkov@nginx.com             && test->handler(&rp, &test->data, &test->request, thr->log)
559384Szelenkov@nginx.com                != NXT_OK)
560384Szelenkov@nginx.com         {
561384Szelenkov@nginx.com             return NXT_ERROR;
562384Szelenkov@nginx.com         }
563384Szelenkov@nginx.com 
564384Szelenkov@nginx.com         nxt_mp_destroy(mp_temp);
565384Szelenkov@nginx.com     }
566384Szelenkov@nginx.com 
567384Szelenkov@nginx.com     nxt_log_error(NXT_LOG_NOTICE, thr->log, "http parse test passed");
568384Szelenkov@nginx.com 
569417Svbart@nginx.com     nxt_memzero(&hash, sizeof(nxt_lvlhsh_t));
570417Svbart@nginx.com 
571417Svbart@nginx.com     colls = nxt_http_fields_hash_collisions(&hash, mp,
572417Svbart@nginx.com                                         nxt_http_test_bench_fields,
573417Svbart@nginx.com                                         nxt_nitems(nxt_http_test_bench_fields),
574417Svbart@nginx.com                                         0);
575417Svbart@nginx.com 
576417Svbart@nginx.com     nxt_memzero(&hash, sizeof(nxt_lvlhsh_t));
577417Svbart@nginx.com 
578417Svbart@nginx.com     lvl_colls = nxt_http_fields_hash_collisions(&hash, mp,
579417Svbart@nginx.com                                         nxt_http_test_bench_fields,
580417Svbart@nginx.com                                         nxt_nitems(nxt_http_test_bench_fields),
581417Svbart@nginx.com                                         1);
582417Svbart@nginx.com 
583417Svbart@nginx.com     nxt_log_error(NXT_LOG_NOTICE, thr->log,
584494Spluknet@nginx.com                   "http parse test hash collisions %ui out of %uz, level: %ui",
585417Svbart@nginx.com                   colls, nxt_nitems(nxt_http_test_bench_fields), lvl_colls);
586417Svbart@nginx.com 
587417Svbart@nginx.com     nxt_memzero(&hash, sizeof(nxt_lvlhsh_t));
588417Svbart@nginx.com 
589417Svbart@nginx.com     rc = nxt_http_fields_hash(&hash, mp, nxt_http_test_bench_fields,
590417Svbart@nginx.com                               nxt_nitems(nxt_http_test_bench_fields));
591417Svbart@nginx.com     if (rc != NXT_OK) {
592384Szelenkov@nginx.com         return NXT_ERROR;
593384Szelenkov@nginx.com     }
594384Szelenkov@nginx.com 
595384Szelenkov@nginx.com     if (nxt_http_parse_test_bench(thr, &nxt_http_test_simple_request,
596417Svbart@nginx.com                                   &hash, "simple", 1000000)
597384Szelenkov@nginx.com         != NXT_OK)
598384Szelenkov@nginx.com     {
599384Szelenkov@nginx.com         return NXT_ERROR;
600384Szelenkov@nginx.com     }
601384Szelenkov@nginx.com 
602384Szelenkov@nginx.com     if (nxt_http_parse_test_bench(thr, &nxt_http_test_big_request,
603417Svbart@nginx.com                                   &hash, "big", 100000)
604384Szelenkov@nginx.com         != NXT_OK)
605384Szelenkov@nginx.com     {
606384Szelenkov@nginx.com         return NXT_ERROR;
607384Szelenkov@nginx.com     }
608384Szelenkov@nginx.com 
609384Szelenkov@nginx.com     nxt_mp_destroy(mp);
610384Szelenkov@nginx.com 
611384Szelenkov@nginx.com     return NXT_OK;
612384Szelenkov@nginx.com }
613384Szelenkov@nginx.com 
614384Szelenkov@nginx.com 
615384Szelenkov@nginx.com static nxt_int_t
616384Szelenkov@nginx.com nxt_http_parse_test_run(nxt_http_request_parse_t *rp, nxt_str_t *request)
617384Szelenkov@nginx.com {
618384Szelenkov@nginx.com     nxt_int_t      rc;
619384Szelenkov@nginx.com     nxt_buf_mem_t  buf;
620384Szelenkov@nginx.com 
621384Szelenkov@nginx.com     buf.start = request->start;
622384Szelenkov@nginx.com     buf.end = request->start + request->length;
623384Szelenkov@nginx.com 
624384Szelenkov@nginx.com     buf.pos = buf.start;
625384Szelenkov@nginx.com     buf.free = buf.pos + 1;
626384Szelenkov@nginx.com 
627384Szelenkov@nginx.com     do {
628384Szelenkov@nginx.com         buf.free++;
629384Szelenkov@nginx.com         rc = nxt_http_parse_request(rp, &buf);
630384Szelenkov@nginx.com     } while (buf.free < buf.end && rc == NXT_AGAIN);
631384Szelenkov@nginx.com 
632384Szelenkov@nginx.com     return rc;
633384Szelenkov@nginx.com }
634384Szelenkov@nginx.com 
635384Szelenkov@nginx.com 
636384Szelenkov@nginx.com static nxt_int_t
637384Szelenkov@nginx.com nxt_http_parse_test_bench(nxt_thread_t *thr, nxt_str_t *request,
638417Svbart@nginx.com     nxt_lvlhsh_t *hash, const char *name, nxt_uint_t n)
639384Szelenkov@nginx.com {
640384Szelenkov@nginx.com     nxt_mp_t                  *mp;
641384Szelenkov@nginx.com     nxt_nsec_t                start, end;
642384Szelenkov@nginx.com     nxt_uint_t                i;
643384Szelenkov@nginx.com     nxt_buf_mem_t             buf;
644384Szelenkov@nginx.com     nxt_http_request_parse_t  rp;
645384Szelenkov@nginx.com 
646384Szelenkov@nginx.com     nxt_log_error(NXT_LOG_NOTICE, thr->log,
647384Szelenkov@nginx.com                   "http parse %s request bench started: %uz bytes, %ui runs",
648384Szelenkov@nginx.com                   name, request->length, n);
649384Szelenkov@nginx.com 
650384Szelenkov@nginx.com     buf.start = request->start;
651384Szelenkov@nginx.com     buf.end = request->start + request->length;
652384Szelenkov@nginx.com 
653384Szelenkov@nginx.com     nxt_thread_time_update(thr);
654384Szelenkov@nginx.com     start = nxt_thread_monotonic_time(thr);
655384Szelenkov@nginx.com 
656384Szelenkov@nginx.com     for (i = 0; nxt_fast_path(i < n); i++) {
657384Szelenkov@nginx.com         nxt_memzero(&rp, sizeof(nxt_http_request_parse_t));
658384Szelenkov@nginx.com 
659384Szelenkov@nginx.com         mp = nxt_mp_create(1024, 128, 256, 32);
660384Szelenkov@nginx.com         if (nxt_slow_path(mp == NULL)) {
661384Szelenkov@nginx.com             return NXT_ERROR;
662384Szelenkov@nginx.com         }
663384Szelenkov@nginx.com 
664384Szelenkov@nginx.com         if (nxt_slow_path(nxt_http_parse_request_init(&rp, mp) != NXT_OK)) {
665384Szelenkov@nginx.com             return NXT_ERROR;
666384Szelenkov@nginx.com         }
667384Szelenkov@nginx.com 
668384Szelenkov@nginx.com         buf.pos = buf.start;
669384Szelenkov@nginx.com         buf.free = buf.end;
670384Szelenkov@nginx.com 
671384Szelenkov@nginx.com         if (nxt_slow_path(nxt_http_parse_request(&rp, &buf) != NXT_DONE)) {
672384Szelenkov@nginx.com             nxt_log_alert(thr->log, "http parse %s request bench failed "
673384Szelenkov@nginx.com                                     "while parsing", name);
674384Szelenkov@nginx.com             return NXT_ERROR;
675384Szelenkov@nginx.com         }
676384Szelenkov@nginx.com 
677417Svbart@nginx.com         if (nxt_slow_path(nxt_http_fields_process(rp.fields, hash, NULL)
678384Szelenkov@nginx.com                           != NXT_OK))
679384Szelenkov@nginx.com         {
680384Szelenkov@nginx.com             nxt_log_alert(thr->log, "http parse %s request bench failed "
681384Szelenkov@nginx.com                                     "while fields processing", name);
682384Szelenkov@nginx.com             return NXT_ERROR;
683384Szelenkov@nginx.com         }
684384Szelenkov@nginx.com 
685384Szelenkov@nginx.com         nxt_mp_destroy(mp);
686384Szelenkov@nginx.com     }
687384Szelenkov@nginx.com 
688384Szelenkov@nginx.com     nxt_thread_time_update(thr);
689384Szelenkov@nginx.com     end = nxt_thread_monotonic_time(thr);
690384Szelenkov@nginx.com 
691384Szelenkov@nginx.com     nxt_log_error(NXT_LOG_NOTICE, thr->log,
692384Szelenkov@nginx.com                   "http parse %s request bench: %0.3fs",
693384Szelenkov@nginx.com                   name, (end - start) / 1000000000.0);
694384Szelenkov@nginx.com 
695384Szelenkov@nginx.com     return NXT_OK;
696384Szelenkov@nginx.com }
697384Szelenkov@nginx.com 
698384Szelenkov@nginx.com 
699384Szelenkov@nginx.com static nxt_int_t
700384Szelenkov@nginx.com nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp,
701384Szelenkov@nginx.com     nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log)
702384Szelenkov@nginx.com {
703384Szelenkov@nginx.com     nxt_str_t  str;
704384Szelenkov@nginx.com 
705384Szelenkov@nginx.com     nxt_http_parse_test_request_line_t  *test = &data->request_line;
706384Szelenkov@nginx.com 
707384Szelenkov@nginx.com     if (rp->method.start != test->method.start
708384Szelenkov@nginx.com         && !nxt_strstr_eq(&rp->method, &test->method))
709384Szelenkov@nginx.com     {
710384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
711384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
712384Szelenkov@nginx.com                            " - method: \"%V\" (expected: \"%V\")",
713384Szelenkov@nginx.com                            request, &rp->method, &test->method);
714384Szelenkov@nginx.com         return NXT_ERROR;
715384Szelenkov@nginx.com     }
716384Szelenkov@nginx.com 
717384Szelenkov@nginx.com     str.length = rp->target_end - rp->target_start;
718384Szelenkov@nginx.com     str.start = rp->target_start;
719384Szelenkov@nginx.com 
720384Szelenkov@nginx.com     if (str.start != test->target.start
721384Szelenkov@nginx.com         && !nxt_strstr_eq(&str, &test->target))
722384Szelenkov@nginx.com     {
723384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
724384Szelenkov@nginx.com                             " - request:\n\"%V\"\n"
725384Szelenkov@nginx.com                             " - target: \"%V\" (expected: \"%V\")",
726384Szelenkov@nginx.com                             request, &str, &test->target);
727384Szelenkov@nginx.com         return NXT_ERROR;
728384Szelenkov@nginx.com     }
729384Szelenkov@nginx.com 
7301168Svbart@nginx.com     if (rp->exten.start != test->exten.start
7311168Svbart@nginx.com         && !nxt_strstr_eq(&rp->exten, &test->exten))
732384Szelenkov@nginx.com     {
733384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
734384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
735384Szelenkov@nginx.com                            " - exten: \"%V\" (expected: \"%V\")",
7361168Svbart@nginx.com                            request, &rp->exten, &test->exten);
737384Szelenkov@nginx.com         return NXT_ERROR;
738384Szelenkov@nginx.com     }
739384Szelenkov@nginx.com 
7401168Svbart@nginx.com     if (rp->args.start != test->args.start
7411168Svbart@nginx.com         && !nxt_strstr_eq(&rp->args, &test->args))
742384Szelenkov@nginx.com     {
743384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
744384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
745384Szelenkov@nginx.com                            " - args: \"%V\" (expected: \"%V\")",
7461168Svbart@nginx.com                            request, &rp->args, &test->args);
747384Szelenkov@nginx.com         return NXT_ERROR;
748384Szelenkov@nginx.com     }
749384Szelenkov@nginx.com 
750384Szelenkov@nginx.com     if (nxt_memcmp(rp->version.str, test->version, 8) != 0) {
751384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
752384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
753493Spluknet@nginx.com                            " - version: \"%*s\" (expected: \"%*s\")", request,
754493Spluknet@nginx.com                            (size_t) 8, rp->version.str,
755493Spluknet@nginx.com                            (size_t) 8, test->version);
756384Szelenkov@nginx.com         return NXT_ERROR;
757384Szelenkov@nginx.com     }
758384Szelenkov@nginx.com 
759384Szelenkov@nginx.com     if (rp->complex_target != test->complex_target) {
760384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
761384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
762384Szelenkov@nginx.com                            " - complex_target: %d (expected: %d)",
763384Szelenkov@nginx.com                            request, rp->complex_target, test->complex_target);
764384Szelenkov@nginx.com         return NXT_ERROR;
765384Szelenkov@nginx.com     }
766384Szelenkov@nginx.com 
767384Szelenkov@nginx.com     if (rp->quoted_target != test->quoted_target) {
768384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
769384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
770384Szelenkov@nginx.com                            " - quoted_target: %d (expected: %d)",
771384Szelenkov@nginx.com                            request, rp->quoted_target, test->quoted_target);
772384Szelenkov@nginx.com         return NXT_ERROR;
773384Szelenkov@nginx.com     }
774384Szelenkov@nginx.com 
775384Szelenkov@nginx.com     if (rp->space_in_target != test->space_in_target) {
776384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test case failed:\n"
777384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
778384Szelenkov@nginx.com                            " - space_in_target: %d (expected: %d)",
779384Szelenkov@nginx.com                            request, rp->space_in_target, test->space_in_target);
780384Szelenkov@nginx.com         return NXT_ERROR;
781384Szelenkov@nginx.com     }
782384Szelenkov@nginx.com 
783384Szelenkov@nginx.com     return NXT_OK;
784384Szelenkov@nginx.com }
785384Szelenkov@nginx.com 
786384Szelenkov@nginx.com 
787384Szelenkov@nginx.com static nxt_int_t
788384Szelenkov@nginx.com nxt_http_parse_test_fields(nxt_http_request_parse_t *rp,
789384Szelenkov@nginx.com     nxt_http_parse_test_data_t *data, nxt_str_t *request, nxt_log_t *log)
790384Szelenkov@nginx.com {
791384Szelenkov@nginx.com     nxt_int_t  rc;
792384Szelenkov@nginx.com 
793417Svbart@nginx.com     rc = nxt_http_fields_process(rp->fields, &nxt_http_test_fields_hash, NULL);
794384Szelenkov@nginx.com 
795384Szelenkov@nginx.com     if (rc != data->result) {
796384Szelenkov@nginx.com         nxt_log_alert(log, "http parse test hash failed:\n"
797384Szelenkov@nginx.com                            " - request:\n\"%V\"\n"
798384Szelenkov@nginx.com                            " - result: %i (expected: %i)",
799384Szelenkov@nginx.com                            request, rc, data->result);
800384Szelenkov@nginx.com         return NXT_ERROR;
801384Szelenkov@nginx.com     }
802384Szelenkov@nginx.com 
803384Szelenkov@nginx.com     return NXT_OK;
804384Szelenkov@nginx.com }
805384Szelenkov@nginx.com 
806384Szelenkov@nginx.com 
807384Szelenkov@nginx.com static nxt_int_t
808417Svbart@nginx.com nxt_http_test_header_return(void *ctx, nxt_http_field_t *field, uintptr_t data)
809384Szelenkov@nginx.com {
810417Svbart@nginx.com     return data;
811384Szelenkov@nginx.com }
812