| 207 |
207 |
| 208 http_parser_free(parser); |
208 http_parser_free(parser); |
| 209 header_array_free(header); |
209 header_array_free(header); |
| 210 } |
210 } |
| 211 |
211 |
| |
212 #define _CX_STR(s) { s, sizeof(s)-1 } |
| |
213 |
| |
214 static cxstring req0 = _CX_STR( |
| |
215 "GET / HTTP/1.1\r\n" |
| |
216 "Host: example.com\r\n" |
| |
217 "\r\n"); |
| |
218 |
| |
219 static cxstring req1 = _CX_STR("GET /api/data?id=42 HTTP/1.1\r\n" |
| |
220 "Host: api.example.com\r\n" |
| |
221 "User-Agent: TestClient/1.0\r\n" |
| |
222 "Accept: application/json\r\n" |
| |
223 "Accept-Language: en-US,en;q=0.9\r\n" |
| |
224 "Connection: keep-alive\r\n" |
| |
225 "Cache-Control: no-cache\r\n" |
| |
226 "\r\n"); |
| |
227 |
| |
228 static cxstring req2 = _CX_STR("GET /search?q=network+testing HTTP/1.1\r\n" |
| |
229 "Host: www.example.com\r\n" |
| |
230 "User-Agent: Mozilla/5.0 (X11; Linux x86_64) TestBrowser/99.0\r\n" |
| |
231 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" |
| |
232 "Accept-Language: en-US,en;q=0.9,de;q=0.8\r\n" |
| |
233 "Accept-Encoding: gzip, deflate, br\r\n" |
| |
234 "Connection: keep-alive\r\n" |
| |
235 "Cache-Control: max-age=0\r\n" |
| |
236 "Upgrade-Insecure-Requests: 1\r\n" |
| |
237 "Pragma: no-cache\r\n" |
| |
238 "DNT: 1\r\n" |
| |
239 "Sec-Fetch-Dest: document\r\n" |
| |
240 "Sec-Fetch-Mode: navigate\r\n" |
| |
241 "Sec-Fetch-Site: none\r\n" |
| |
242 "Sec-Fetch-User: ?1\r\n" |
| |
243 "Referer: https://www.example.com/\r\n" |
| |
244 "X-Forwarded-For: 203.0.113.195\r\n" |
| |
245 "X-Request-ID: 123e4567-e89b-12d3-a456-426614174000\r\n" |
| |
246 "\r\n"); |
| |
247 |
| 212 CX_TEST(test_http_parser_process_full) { |
248 CX_TEST(test_http_parser_process_full) { |
| 213 CX_TEST_DO { |
249 CX_TEST_DO { |
| 214 cxstring req0 = cx_str( |
|
| 215 "GET / HTTP/1.1\r\n" |
|
| 216 "Host: example.com\r\n" |
|
| 217 "\r\n"); |
|
| 218 |
|
| 219 cxstring req1 = cx_str("GET /api/data?id=42 HTTP/1.1\r\n" |
|
| 220 "Host: api.example.com\r\n" |
|
| 221 "User-Agent: TestClient/1.0\r\n" |
|
| 222 "Accept: application/json\r\n" |
|
| 223 "Accept-Language: en-US,en;q=0.9\r\n" |
|
| 224 "Connection: keep-alive\r\n" |
|
| 225 "Cache-Control: no-cache\r\n" |
|
| 226 "\r\n"); |
|
| 227 |
|
| 228 cxstring req2 = cx_str("GET /search?q=network+testing HTTP/1.1\r\n" |
|
| 229 "Host: www.example.com\r\n" |
|
| 230 "User-Agent: Mozilla/5.0 (X11; Linux x86_64) TestBrowser/99.0\r\n" |
|
| 231 "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\n" |
|
| 232 "Accept-Language: en-US,en;q=0.9,de;q=0.8\r\n" |
|
| 233 "Accept-Encoding: gzip, deflate, br\r\n" |
|
| 234 "Connection: keep-alive\r\n" |
|
| 235 "Cache-Control: max-age=0\r\n" |
|
| 236 "Upgrade-Insecure-Requests: 1\r\n" |
|
| 237 "Pragma: no-cache\r\n" |
|
| 238 "DNT: 1\r\n" |
|
| 239 "Sec-Fetch-Dest: document\r\n" |
|
| 240 "Sec-Fetch-Mode: navigate\r\n" |
|
| 241 "Sec-Fetch-Site: none\r\n" |
|
| 242 "Sec-Fetch-User: ?1\r\n" |
|
| 243 "Referer: https://www.example.com/\r\n" |
|
| 244 "X-Forwarded-For: 203.0.113.195\r\n" |
|
| 245 "X-Request-ID: 123e4567-e89b-12d3-a456-426614174000\r\n" |
|
| 246 "\r\n"); |
|
| 247 |
|
| 248 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, req0.length); |
250 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, req0.length); |
| 249 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, req1.length); |
251 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, req1.length); |
| 250 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, req2.length); |
252 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, req2.length); |
| 251 } |
253 } |
| 252 } |
254 } |
| |
255 |
| |
256 CX_TEST(test_http_parser_process_chunk_1b) { |
| |
257 CX_TEST_DO { |
| |
258 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, 1); |
| |
259 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, 1); |
| |
260 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, 1); |
| |
261 } |
| |
262 } |
| |
263 |
| |
264 CX_TEST(test_http_parser_process_chunk_2b) { |
| |
265 CX_TEST_DO { |
| |
266 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, 2); |
| |
267 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, 2); |
| |
268 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, 2); |
| |
269 } |
| |
270 } |
| |
271 |
| |
272 CX_TEST(test_http_parser_process_chunk_3b) { |
| |
273 CX_TEST_DO { |
| |
274 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, 3); |
| |
275 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, 3); |
| |
276 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, 3); |
| |
277 } |
| |
278 } |
| |
279 |
| |
280 CX_TEST(test_http_parser_process_chunk_4b) { |
| |
281 CX_TEST_DO { |
| |
282 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req0, 4); |
| |
283 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req1, 4); |
| |
284 CX_TEST_CALL_SUBROUTINE(test_http_parser_process, req2, 4); |
| |
285 } |
| |
286 } |