nxt_http_parse_test.c (1171:968424f2804c) nxt_http_parse_test.c (1214:c3666b232602)
1
2/*
3 * Copyright (C) NGINX, Inc.
4 * Copyright (C) Valentin V. Bartenev
5 */
6
7#include <nxt_main.h>
8#include "nxt_tests.h"
9
10
11typedef struct {
12 nxt_str_t method;
13 nxt_str_t target;
1
2/*
3 * Copyright (C) NGINX, Inc.
4 * Copyright (C) Valentin V. Bartenev
5 */
6
7#include <nxt_main.h>
8#include "nxt_tests.h"
9
10
11typedef struct {
12 nxt_str_t method;
13 nxt_str_t target;
14 nxt_str_t exten;
15 nxt_str_t args;
16 u_char version[8];
17
18 /* target with "/." */
19 unsigned complex_target:1;
20 /* target with "%" */
21 unsigned quoted_target:1;
22 /* target with " " */

--- 38 unchanged lines hidden (view full) ---

61 {
62 nxt_string("GET / HTTP/1.0\r\n\r\n"),
63 NXT_DONE,
64 &nxt_http_parse_test_request_line,
65 { .request_line = {
66 nxt_string("GET"),
67 nxt_string("/"),
68 nxt_null_string,
14 nxt_str_t args;
15 u_char version[8];
16
17 /* target with "/." */
18 unsigned complex_target:1;
19 /* target with "%" */
20 unsigned quoted_target:1;
21 /* target with " " */

--- 38 unchanged lines hidden (view full) ---

60 {
61 nxt_string("GET / HTTP/1.0\r\n\r\n"),
62 NXT_DONE,
63 &nxt_http_parse_test_request_line,
64 { .request_line = {
65 nxt_string("GET"),
66 nxt_string("/"),
67 nxt_null_string,
69 nxt_null_string,
70 "HTTP/1.0",
71 0, 0, 0
72 }}
73 },
74 {
75 nxt_string("XXX-METHOD /d.ir/fi+le.ext?key=val HTTP/1.2\n\n"),
76 NXT_DONE,
77 &nxt_http_parse_test_request_line,
78 { .request_line = {
79 nxt_string("XXX-METHOD"),
80 nxt_string("/d.ir/fi+le.ext?key=val"),
68 "HTTP/1.0",
69 0, 0, 0
70 }}
71 },
72 {
73 nxt_string("XXX-METHOD /d.ir/fi+le.ext?key=val HTTP/1.2\n\n"),
74 NXT_DONE,
75 &nxt_http_parse_test_request_line,
76 { .request_line = {
77 nxt_string("XXX-METHOD"),
78 nxt_string("/d.ir/fi+le.ext?key=val"),
81 nxt_string("ext"),
82 nxt_string("key=val"),
83 "HTTP/1.2",
84 0, 0, 0
85 }}
86 },
87 {
88 nxt_string("GET /di.r/? HTTP/1.0\r\n\r\n"),
89 NXT_DONE,
90 &nxt_http_parse_test_request_line,
91 { .request_line = {
92 nxt_string("GET"),
93 nxt_string("/di.r/?"),
79 nxt_string("key=val"),
80 "HTTP/1.2",
81 0, 0, 0
82 }}
83 },
84 {
85 nxt_string("GET /di.r/? HTTP/1.0\r\n\r\n"),
86 NXT_DONE,
87 &nxt_http_parse_test_request_line,
88 { .request_line = {
89 nxt_string("GET"),
90 nxt_string("/di.r/?"),
94 nxt_null_string,
95 nxt_string(""),
96 "HTTP/1.0",
97 0, 0, 0
98 }}
99 },
100 {
101 nxt_string("GEt / HTTP/1.0\r\n\r\n"),
102 NXT_HTTP_PARSE_INVALID,

--- 27 unchanged lines hidden (view full) ---

130 {
131 nxt_string("GET /. HTTP/1.0\r\n\r\n"),
132 NXT_DONE,
133 &nxt_http_parse_test_request_line,
134 { .request_line = {
135 nxt_string("GET"),
136 nxt_string("/."),
137 nxt_null_string,
91 nxt_string(""),
92 "HTTP/1.0",
93 0, 0, 0
94 }}
95 },
96 {
97 nxt_string("GEt / HTTP/1.0\r\n\r\n"),
98 NXT_HTTP_PARSE_INVALID,

--- 27 unchanged lines hidden (view full) ---

126 {
127 nxt_string("GET /. HTTP/1.0\r\n\r\n"),
128 NXT_DONE,
129 &nxt_http_parse_test_request_line,
130 { .request_line = {
131 nxt_string("GET"),
132 nxt_string("/."),
133 nxt_null_string,
138 nxt_null_string,
139 "HTTP/1.0",
140 1, 0, 0
141 }}
142 },
143 {
144 nxt_string("GET /# HTTP/1.0\r\n\r\n"),
145 NXT_DONE,
146 &nxt_http_parse_test_request_line,
147 { .request_line = {
148 nxt_string("GET"),
149 nxt_string("/#"),
150 nxt_null_string,
134 "HTTP/1.0",
135 1, 0, 0
136 }}
137 },
138 {
139 nxt_string("GET /# HTTP/1.0\r\n\r\n"),
140 NXT_DONE,
141 &nxt_http_parse_test_request_line,
142 { .request_line = {
143 nxt_string("GET"),
144 nxt_string("/#"),
145 nxt_null_string,
151 nxt_null_string,
152 "HTTP/1.0",
153 1, 0, 0
154 }}
155 },
156 {
157 nxt_string("GET /?# HTTP/1.0\r\n\r\n"),
158 NXT_DONE,
159 &nxt_http_parse_test_request_line,
160 { .request_line = {
161 nxt_string("GET"),
162 nxt_string("/?#"),
146 "HTTP/1.0",
147 1, 0, 0
148 }}
149 },
150 {
151 nxt_string("GET /?# HTTP/1.0\r\n\r\n"),
152 NXT_DONE,
153 &nxt_http_parse_test_request_line,
154 { .request_line = {
155 nxt_string("GET"),
156 nxt_string("/?#"),
163 nxt_null_string,
164 nxt_string(""),
165 "HTTP/1.0",
166 1, 0, 0
167 }}
168 },
169 {
170 nxt_string("GET // HTTP/1.0\r\n\r\n"),
171 NXT_DONE,
172 &nxt_http_parse_test_request_line,
173 { .request_line = {
174 nxt_string("GET"),
175 nxt_string("//"),
176 nxt_null_string,
157 nxt_string(""),
158 "HTTP/1.0",
159 1, 0, 0
160 }}
161 },
162 {
163 nxt_string("GET // HTTP/1.0\r\n\r\n"),
164 NXT_DONE,
165 &nxt_http_parse_test_request_line,
166 { .request_line = {
167 nxt_string("GET"),
168 nxt_string("//"),
169 nxt_null_string,
177 nxt_null_string,
178 "HTTP/1.0",
179 1, 0, 0
180 }}
181 },
182 {
183 nxt_string("GET /%20 HTTP/1.0\r\n\r\n"),
184 NXT_DONE,
185 &nxt_http_parse_test_request_line,
186 { .request_line = {
187 nxt_string("GET"),
188 nxt_string("/%20"),
189 nxt_null_string,
170 "HTTP/1.0",
171 1, 0, 0
172 }}
173 },
174 {
175 nxt_string("GET /%20 HTTP/1.0\r\n\r\n"),
176 NXT_DONE,
177 &nxt_http_parse_test_request_line,
178 { .request_line = {
179 nxt_string("GET"),
180 nxt_string("/%20"),
181 nxt_null_string,
190 nxt_null_string,
191 "HTTP/1.0",
192 0, 1, 0
193 }}
194 },
195 {
196 nxt_string("GET / a HTTP/1.0\r\n\r\n"),
197 NXT_DONE,
198 &nxt_http_parse_test_request_line,
199 { .request_line = {
200 nxt_string("GET"),
201 nxt_string("/ a"),
202 nxt_null_string,
182 "HTTP/1.0",
183 0, 1, 0
184 }}
185 },
186 {
187 nxt_string("GET / a HTTP/1.0\r\n\r\n"),
188 NXT_DONE,
189 &nxt_http_parse_test_request_line,
190 { .request_line = {
191 nxt_string("GET"),
192 nxt_string("/ a"),
193 nxt_null_string,
203 nxt_null_string,
204 "HTTP/1.0",
205 0, 0, 1
206 }}
207 },
208 {
209 nxt_string("GET /na %20me.ext?args HTTP/1.0\r\n\r\n"),
210 NXT_DONE,
211 &nxt_http_parse_test_request_line,
212 { .request_line = {
213 nxt_string("GET"),
214 nxt_string("/na %20me.ext?args"),
194 "HTTP/1.0",
195 0, 0, 1
196 }}
197 },
198 {
199 nxt_string("GET /na %20me.ext?args HTTP/1.0\r\n\r\n"),
200 NXT_DONE,
201 &nxt_http_parse_test_request_line,
202 { .request_line = {
203 nxt_string("GET"),
204 nxt_string("/na %20me.ext?args"),
215 nxt_string("ext"),
216 nxt_string("args"),
217 "HTTP/1.0",
218 0, 1, 1
219 }}
220 },
221 {
222 nxt_string("GET / HTTP/1.0 HTTP/1.1\r\n\r\n"),
223 NXT_DONE,
224 &nxt_http_parse_test_request_line,
225 { .request_line = {
226 nxt_string("GET"),
227 nxt_string("/ HTTP/1.0"),
205 nxt_string("args"),
206 "HTTP/1.0",
207 0, 1, 1
208 }}
209 },
210 {
211 nxt_string("GET / HTTP/1.0 HTTP/1.1\r\n\r\n"),
212 NXT_DONE,
213 &nxt_http_parse_test_request_line,
214 { .request_line = {
215 nxt_string("GET"),
216 nxt_string("/ HTTP/1.0"),
228 nxt_string("0"),
229 nxt_null_string,
230 "HTTP/1.1",
231 0, 0, 1
232 }}
233 },
234 {
235 nxt_string("GET / HTTP/1.1\r\n"
236 "Host: example.com\r\n\r\n"),

--- 498 unchanged lines hidden (view full) ---

735 {
736 nxt_log_alert(log, "http parse test case failed:\n"
737 " - request:\n\"%V\"\n"
738 " - target: \"%V\" (expected: \"%V\")",
739 request, &str, &test->target);
740 return NXT_ERROR;
741 }
742
217 nxt_null_string,
218 "HTTP/1.1",
219 0, 0, 1
220 }}
221 },
222 {
223 nxt_string("GET / HTTP/1.1\r\n"
224 "Host: example.com\r\n\r\n"),

--- 498 unchanged lines hidden (view full) ---

723 {
724 nxt_log_alert(log, "http parse test case failed:\n"
725 " - request:\n\"%V\"\n"
726 " - target: \"%V\" (expected: \"%V\")",
727 request, &str, &test->target);
728 return NXT_ERROR;
729 }
730
743 if (rp->exten.start != test->exten.start
744 && !nxt_strstr_eq(&rp->exten, &test->exten))
745 {
746 nxt_log_alert(log, "http parse test case failed:\n"
747 " - request:\n\"%V\"\n"
748 " - exten: \"%V\" (expected: \"%V\")",
749 request, &rp->exten, &test->exten);
750 return NXT_ERROR;
751 }
752
753 if (rp->args.start != test->args.start
754 && !nxt_strstr_eq(&rp->args, &test->args))
755 {
756 nxt_log_alert(log, "http parse test case failed:\n"
757 " - request:\n\"%V\"\n"
758 " - args: \"%V\" (expected: \"%V\")",
759 request, &rp->args, &test->args);
760 return NXT_ERROR;

--- 64 unchanged lines hidden ---
731 if (rp->args.start != test->args.start
732 && !nxt_strstr_eq(&rp->args, &test->args))
733 {
734 nxt_log_alert(log, "http parse test case failed:\n"
735 " - request:\n\"%V\"\n"
736 " - args: \"%V\" (expected: \"%V\")",
737 request, &rp->args, &test->args);
738 return NXT_ERROR;

--- 64 unchanged lines hidden ---