| 1 |
#include <stdlib.h> |
| 2 |
|
| 3 |
#include "fixture.h" |
| 4 |
|
| 5 |
int llhttp__on_url(llparse_t* s, const char* p, const char* endp) { |
| 6 |
if (llparse__in_bench) |
| 7 |
return 0; |
| 8 |
|
| 9 |
return llparse__print_span("url", p, endp); |
| 10 |
} |
| 11 |
|
| 12 |
|
| 13 |
int llhttp__on_url_complete(llparse_t* s, const char* p, const char* endp) { |
| 14 |
if (llparse__in_bench) |
| 15 |
return 0; |
| 16 |
|
| 17 |
llparse__print(p, endp, "url complete"); |
| 18 |
|
| 19 |
#ifdef LLHTTP__TEST_PAUSE_ON_URL_COMPLETE |
| 20 |
return LLPARSE__ERROR_PAUSE; |
| 21 |
#else |
| 22 |
return 0; |
| 23 |
#endif |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
int llhttp__on_url_schema(llparse_t* s, const char* p, const char* endp) { |
| 28 |
if (llparse__in_bench) |
| 29 |
return 0; |
| 30 |
|
| 31 |
return llparse__print_span("url.schema", p, endp); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
int llhttp__on_url_host(llparse_t* s, const char* p, const char* endp) { |
| 36 |
if (llparse__in_bench) |
| 37 |
return 0; |
| 38 |
|
| 39 |
return llparse__print_span("url.host", p, endp); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
int llhttp__on_url_path(llparse_t* s, const char* p, const char* endp) { |
| 44 |
if (llparse__in_bench) |
| 45 |
return 0; |
| 46 |
|
| 47 |
return llparse__print_span("url.path", p, endp); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
int llhttp__on_url_query(llparse_t* s, const char* p, const char* endp) { |
| 52 |
if (llparse__in_bench) |
| 53 |
return 0; |
| 54 |
|
| 55 |
return llparse__print_span("url.query", p, endp); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
int llhttp__on_url_fragment(llparse_t* s, const char* p, const char* endp) { |
| 60 |
if (llparse__in_bench) |
| 61 |
return 0; |
| 62 |
|
| 63 |
return llparse__print_span("url.fragment", p, endp); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
#ifdef LLHTTP__TEST_HTTP |
| 68 |
|
| 69 |
void llhttp__test_init_request(llparse_t* s) { |
| 70 |
s->type = HTTP_REQUEST; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
void llhttp__test_init_response(llparse_t* s) { |
| 75 |
s->type = HTTP_RESPONSE; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
void llhttp__test_init_request_lenient_all(llparse_t* s) { |
| 80 |
llhttp__test_init_request(s); |
| 81 |
s->lenient_flags |= |
| 82 |
LENIENT_HEADERS | LENIENT_CHUNKED_LENGTH | LENIENT_KEEP_ALIVE | |
| 83 |
LENIENT_TRANSFER_ENCODING | LENIENT_VERSION | LENIENT_DATA_AFTER_CLOSE | |
| 84 |
LENIENT_OPTIONAL_LF_AFTER_CR | LENIENT_OPTIONAL_CR_BEFORE_LF | |
| 85 |
LENIENT_OPTIONAL_CRLF_AFTER_CHUNK; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
void llhttp__test_init_response_lenient_all(llparse_t* s) { |
| 90 |
llhttp__test_init_response(s); |
| 91 |
s->lenient_flags |= |
| 92 |
LENIENT_HEADERS | LENIENT_CHUNKED_LENGTH | LENIENT_KEEP_ALIVE | |
| 93 |
LENIENT_TRANSFER_ENCODING | LENIENT_VERSION | LENIENT_DATA_AFTER_CLOSE | |
| 94 |
LENIENT_OPTIONAL_LF_AFTER_CR | LENIENT_OPTIONAL_CR_BEFORE_LF | |
| 95 |
LENIENT_OPTIONAL_CRLF_AFTER_CHUNK; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
void llhttp__test_init_request_lenient_headers(llparse_t* s) { |
| 100 |
llhttp__test_init_request(s); |
| 101 |
s->lenient_flags |= LENIENT_HEADERS; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
void llhttp__test_init_request_lenient_chunked_length(llparse_t* s) { |
| 106 |
llhttp__test_init_request(s); |
| 107 |
s->lenient_flags |= LENIENT_CHUNKED_LENGTH; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
void llhttp__test_init_request_lenient_keep_alive(llparse_t* s) { |
| 112 |
llhttp__test_init_request(s); |
| 113 |
s->lenient_flags |= LENIENT_KEEP_ALIVE; |
| 114 |
} |
| 115 |
|
| 116 |
void llhttp__test_init_request_lenient_transfer_encoding(llparse_t* s) { |
| 117 |
llhttp__test_init_request(s); |
| 118 |
s->lenient_flags |= LENIENT_TRANSFER_ENCODING; |
| 119 |
} |
| 120 |
|
| 121 |
|
| 122 |
void llhttp__test_init_request_lenient_version(llparse_t* s) { |
| 123 |
llhttp__test_init_request(s); |
| 124 |
s->lenient_flags |= LENIENT_VERSION; |
| 125 |
} |
| 126 |
|
| 127 |
|
| 128 |
void llhttp__test_init_response_lenient_keep_alive(llparse_t* s) { |
| 129 |
llhttp__test_init_response(s); |
| 130 |
s->lenient_flags |= LENIENT_KEEP_ALIVE; |
| 131 |
} |
| 132 |
|
| 133 |
void llhttp__test_init_response_lenient_version(llparse_t* s) { |
| 134 |
llhttp__test_init_response(s); |
| 135 |
s->lenient_flags |= LENIENT_VERSION; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
void llhttp__test_init_response_lenient_headers(llparse_t* s) { |
| 140 |
llhttp__test_init_response(s); |
| 141 |
s->lenient_flags |= LENIENT_HEADERS; |
| 142 |
} |
| 143 |
|
| 144 |
void llhttp__test_init_request_lenient_data_after_close(llparse_t* s) { |
| 145 |
llhttp__test_init_request(s); |
| 146 |
s->lenient_flags |= LENIENT_DATA_AFTER_CLOSE; |
| 147 |
} |
| 148 |
|
| 149 |
void llhttp__test_init_response_lenient_data_after_close(llparse_t* s) { |
| 150 |
llhttp__test_init_response(s); |
| 151 |
s->lenient_flags |= LENIENT_DATA_AFTER_CLOSE; |
| 152 |
} |
| 153 |
|
| 154 |
void llhttp__test_init_request_lenient_optional_lf_after_cr(llparse_t* s) { |
| 155 |
llhttp__test_init_request(s); |
| 156 |
s->lenient_flags |= LENIENT_OPTIONAL_LF_AFTER_CR; |
| 157 |
} |
| 158 |
|
| 159 |
void llhttp__test_init_response_lenient_optional_lf_after_cr(llparse_t* s) { |
| 160 |
llhttp__test_init_response(s); |
| 161 |
s->lenient_flags |= LENIENT_OPTIONAL_LF_AFTER_CR; |
| 162 |
} |
| 163 |
|
| 164 |
void llhttp__test_init_request_lenient_optional_cr_before_lf(llparse_t* s) { |
| 165 |
llhttp__test_init_request(s); |
| 166 |
s->lenient_flags |= LENIENT_OPTIONAL_CR_BEFORE_LF; |
| 167 |
} |
| 168 |
|
| 169 |
void llhttp__test_init_response_lenient_optional_cr_before_lf(llparse_t* s) { |
| 170 |
llhttp__test_init_response(s); |
| 171 |
s->lenient_flags |= LENIENT_OPTIONAL_CR_BEFORE_LF; |
| 172 |
} |
| 173 |
|
| 174 |
void llhttp__test_init_request_lenient_optional_crlf_after_chunk(llparse_t* s) { |
| 175 |
llhttp__test_init_request(s); |
| 176 |
s->lenient_flags |= LENIENT_OPTIONAL_CRLF_AFTER_CHUNK; |
| 177 |
} |
| 178 |
|
| 179 |
void llhttp__test_init_response_lenient_optional_crlf_after_chunk(llparse_t* s) { |
| 180 |
llhttp__test_init_response(s); |
| 181 |
s->lenient_flags |= LENIENT_OPTIONAL_CRLF_AFTER_CHUNK; |
| 182 |
} |
| 183 |
|
| 184 |
void llhttp__test_init_request_lenient_spaces_after_chunk_size(llparse_t* s) { |
| 185 |
llhttp__test_init_request(s); |
| 186 |
s->lenient_flags |= LENIENT_SPACES_AFTER_CHUNK_SIZE; |
| 187 |
} |
| 188 |
|
| 189 |
void llhttp__test_init_response_lenient_spaces_after_chunk_size(llparse_t* s) { |
| 190 |
llhttp__test_init_response(s); |
| 191 |
s->lenient_flags |= LENIENT_SPACES_AFTER_CHUNK_SIZE; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
void llhttp__test_finish(llparse_t* s) { |
| 196 |
llparse__print(NULL, NULL, "finish=%d", s->finish); |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
int llhttp__on_message_begin(llparse_t* s, const char* p, const char* endp) { |
| 201 |
if (llparse__in_bench) |
| 202 |
return 0; |
| 203 |
|
| 204 |
llparse__print(p, endp, "message begin"); |
| 205 |
|
| 206 |
#ifdef LLHTTP__TEST_PAUSE_ON_MESSAGE_BEGIN |
| 207 |
return LLPARSE__ERROR_PAUSE; |
| 208 |
#else |
| 209 |
return 0; |
| 210 |
#endif |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
int llhttp__on_message_complete(llparse_t* s, const char* p, const char* endp) { |
| 215 |
if (llparse__in_bench) |
| 216 |
return 0; |
| 217 |
|
| 218 |
llparse__print(p, endp, "message complete"); |
| 219 |
|
| 220 |
#ifdef LLHTTP__TEST_PAUSE_ON_MESSAGE_COMPLETE |
| 221 |
return LLPARSE__ERROR_PAUSE; |
| 222 |
#else |
| 223 |
return 0; |
| 224 |
#endif |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
int llhttp__on_status(llparse_t* s, const char* p, const char* endp) { |
| 229 |
if (llparse__in_bench) |
| 230 |
return 0; |
| 231 |
|
| 232 |
return llparse__print_span("status", p, endp); |
| 233 |
} |
| 234 |
|
| 235 |
|
| 236 |
int llhttp__on_status_complete(llparse_t* s, const char* p, const char* endp) { |
| 237 |
if (llparse__in_bench) |
| 238 |
return 0; |
| 239 |
|
| 240 |
llparse__print(p, endp, "status complete"); |
| 241 |
|
| 242 |
#ifdef LLHTTP__TEST_PAUSE_ON_STATUS_COMPLETE |
| 243 |
return LLPARSE__ERROR_PAUSE; |
| 244 |
#else |
| 245 |
return 0; |
| 246 |
#endif |
| 247 |
} |
| 248 |
|
| 249 |
|
| 250 |
int llhttp__on_method(llparse_t* s, const char* p, const char* endp) { |
| 251 |
if (llparse__in_bench || s->type != HTTP_REQUEST) |
| 252 |
return 0; |
| 253 |
|
| 254 |
return llparse__print_span("method", p, endp); |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
int llhttp__on_method_complete(llparse_t* s, const char* p, const char* endp) { |
| 259 |
if (llparse__in_bench) |
| 260 |
return 0; |
| 261 |
|
| 262 |
llparse__print(p, endp, "method complete"); |
| 263 |
|
| 264 |
#ifdef LLHTTP__TEST_PAUSE_ON_METHOD_COMPLETE |
| 265 |
return LLPARSE__ERROR_PAUSE; |
| 266 |
#else |
| 267 |
return 0; |
| 268 |
#endif |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
int llhttp__on_version(llparse_t* s, const char* p, const char* endp) { |
| 273 |
if (llparse__in_bench) |
| 274 |
return 0; |
| 275 |
|
| 276 |
return llparse__print_span("version", p, endp); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
int llhttp__on_version_complete(llparse_t* s, const char* p, const char* endp) { |
| 281 |
if (llparse__in_bench) |
| 282 |
return 0; |
| 283 |
|
| 284 |
llparse__print(p, endp, "version complete"); |
| 285 |
|
| 286 |
#ifdef LLHTTP__TEST_PAUSE_ON_VERSION_COMPLETE |
| 287 |
return LLPARSE__ERROR_PAUSE; |
| 288 |
#else |
| 289 |
return 0; |
| 290 |
#endif |
| 291 |
} |
| 292 |
|
| 293 |
int llhttp__on_header_field(llparse_t* s, const char* p, const char* endp) { |
| 294 |
if (llparse__in_bench) |
| 295 |
return 0; |
| 296 |
|
| 297 |
return llparse__print_span("header_field", p, endp); |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
int llhttp__on_header_field_complete(llparse_t* s, const char* p, const char* endp) { |
| 302 |
if (llparse__in_bench) |
| 303 |
return 0; |
| 304 |
|
| 305 |
llparse__print(p, endp, "header_field complete"); |
| 306 |
|
| 307 |
#ifdef LLHTTP__TEST_PAUSE_ON_HEADER_FIELD_COMPLETE |
| 308 |
return LLPARSE__ERROR_PAUSE; |
| 309 |
#else |
| 310 |
return 0; |
| 311 |
#endif |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
int llhttp__on_header_value(llparse_t* s, const char* p, const char* endp) { |
| 316 |
if (llparse__in_bench) |
| 317 |
return 0; |
| 318 |
|
| 319 |
return llparse__print_span("header_value", p, endp); |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
int llhttp__on_header_value_complete(llparse_t* s, const char* p, const char* endp) { |
| 324 |
if (llparse__in_bench) |
| 325 |
return 0; |
| 326 |
|
| 327 |
llparse__print(p, endp, "header_value complete"); |
| 328 |
|
| 329 |
#ifdef LLHTTP__TEST_PAUSE_ON_HEADER_VALUE_COMPLETE |
| 330 |
return LLPARSE__ERROR_PAUSE; |
| 331 |
#else |
| 332 |
return 0; |
| 333 |
#endif |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
int llhttp__on_headers_complete(llparse_t* s, const char* p, const char* endp) { |
| 338 |
if (llparse__in_bench) |
| 339 |
return 0; |
| 340 |
|
| 341 |
if (s->type == HTTP_REQUEST) { |
| 342 |
llparse__print(p, endp, |
| 343 |
"headers complete method=%d v=%d/%d flags=%x content_length=%llu", |
| 344 |
s->method, s->http_major, s->http_minor, s->flags, s->content_length); |
| 345 |
} else if (s->type == HTTP_RESPONSE) { |
| 346 |
llparse__print(p, endp, |
| 347 |
"headers complete status=%d v=%d/%d flags=%x content_length=%llu", |
| 348 |
s->status_code, s->http_major, s->http_minor, s->flags, |
| 349 |
s->content_length); |
| 350 |
} else { |
| 351 |
llparse__print(p, endp, "invalid headers complete"); |
| 352 |
} |
| 353 |
|
| 354 |
#ifdef LLHTTP__TEST_PAUSE_ON_HEADERS_COMPLETE |
| 355 |
return LLPARSE__ERROR_PAUSE; |
| 356 |
#elif defined(LLHTTP__TEST_SKIP_BODY) |
| 357 |
llparse__print(p, endp, "skip body"); |
| 358 |
return 1; |
| 359 |
#else |
| 360 |
return 0; |
| 361 |
#endif |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
int llhttp__on_body(llparse_t* s, const char* p, const char* endp) { |
| 366 |
if (llparse__in_bench) |
| 367 |
return 0; |
| 368 |
|
| 369 |
return llparse__print_span("body", p, endp); |
| 370 |
} |
| 371 |
|
| 372 |
|
| 373 |
int llhttp__on_chunk_header(llparse_t* s, const char* p, const char* endp) { |
| 374 |
if (llparse__in_bench) |
| 375 |
return 0; |
| 376 |
|
| 377 |
llparse__print(p, endp, "chunk header len=%d", (int) s->content_length); |
| 378 |
|
| 379 |
#ifdef LLHTTP__TEST_PAUSE_ON_CHUNK_HEADER |
| 380 |
return LLPARSE__ERROR_PAUSE; |
| 381 |
#else |
| 382 |
return 0; |
| 383 |
#endif |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
int llhttp__on_chunk_extension_name(llparse_t* s, const char* p, const char* endp) { |
| 388 |
if (llparse__in_bench) |
| 389 |
return 0; |
| 390 |
|
| 391 |
return llparse__print_span("chunk_extension_name", p, endp); |
| 392 |
} |
| 393 |
|
| 394 |
|
| 395 |
int llhttp__on_chunk_extension_name_complete(llparse_t* s, const char* p, const char* endp) { |
| 396 |
if (llparse__in_bench) |
| 397 |
return 0; |
| 398 |
|
| 399 |
llparse__print(p, endp, "chunk_extension_name complete"); |
| 400 |
|
| 401 |
#ifdef LLHTTP__TEST_PAUSE_ON_CHUNK_EXTENSION_NAME |
| 402 |
return LLPARSE__ERROR_PAUSE; |
| 403 |
#else |
| 404 |
return 0; |
| 405 |
#endif |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
int llhttp__on_chunk_extension_value(llparse_t* s, const char* p, const char* endp) { |
| 410 |
if (llparse__in_bench) |
| 411 |
return 0; |
| 412 |
|
| 413 |
return llparse__print_span("chunk_extension_value", p, endp); |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
int llhttp__on_chunk_extension_value_complete(llparse_t* s, const char* p, const char* endp) { |
| 418 |
if (llparse__in_bench) |
| 419 |
return 0; |
| 420 |
|
| 421 |
llparse__print(p, endp, "chunk_extension_value complete"); |
| 422 |
|
| 423 |
#ifdef LLHTTP__TEST_PAUSE_ON_CHUNK_EXTENSION_VALUE |
| 424 |
return LLPARSE__ERROR_PAUSE; |
| 425 |
#else |
| 426 |
return 0; |
| 427 |
#endif |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
int llhttp__on_chunk_complete(llparse_t* s, const char* p, const char* endp) { |
| 432 |
if (llparse__in_bench) |
| 433 |
return 0; |
| 434 |
|
| 435 |
llparse__print(p, endp, "chunk complete"); |
| 436 |
|
| 437 |
#ifdef LLHTTP__TEST_PAUSE_ON_CHUNK_COMPLETE |
| 438 |
return LLPARSE__ERROR_PAUSE; |
| 439 |
#else |
| 440 |
return 0; |
| 441 |
#endif |
| 442 |
} |
| 443 |
|
| 444 |
int llhttp__on_reset(llparse_t* s, const char* p, const char* endp) { |
| 445 |
if (llparse__in_bench) |
| 446 |
return 0; |
| 447 |
|
| 448 |
llparse__print(p, endp, "reset"); |
| 449 |
|
| 450 |
#ifdef LLHTTP__TEST_PAUSE_ON_RESET |
| 451 |
return LLPARSE__ERROR_PAUSE; |
| 452 |
#else |
| 453 |
return 0; |
| 454 |
#endif |
| 455 |
} |
| 456 |
|
| 457 |
#endif /* LLHTTP__TEST_HTTP */ |