| 429 | -------------------------------------------------------------------------*/ |
| 430 | |
| 431 | int |
| 432 | http_hdr_print(HTTPHdrImpl const *hdr, char *buf, int bufsize, int *bufindex, int *dumpoffset) |
| 433 | { |
| 434 | #define TRY(x) \ |
| 435 | if (!x) \ |
| 436 | return 0 |
| 437 | |
| 438 | int tmplen, hdrstat; |
| 439 | char tmpbuf[32]; |
| 440 | char *p; |
| 441 | |
| 442 | ink_assert((hdr->m_polarity == HTTP_TYPE_REQUEST) || (hdr->m_polarity == HTTP_TYPE_RESPONSE)); |
| 443 | |
| 444 | if (hdr->m_polarity == HTTP_TYPE_REQUEST) { |
| 445 | if (hdr->u.req.m_ptr_method == nullptr) { |
| 446 | return 1; |
| 447 | } |
| 448 | |
| 449 | if ((buf != nullptr) && (*dumpoffset == 0) && (bufsize - *bufindex >= hdr->u.req.m_len_method + 1)) { // fastpath |
| 450 | |
| 451 | p = buf + *bufindex; |
| 452 | memcpy(p, hdr->u.req.m_ptr_method, hdr->u.req.m_len_method); |
| 453 | p += hdr->u.req.m_len_method; |
| 454 | *p++ = ' '; |
| 455 | *bufindex += hdr->u.req.m_len_method + 1; |
| 456 | |
| 457 | if (hdr->u.req.m_url_impl) { |
| 458 | TRY(url_print(hdr->u.req.m_url_impl, buf, bufsize, bufindex, dumpoffset)); |
| 459 | if (bufsize - *bufindex >= 1) { |
| 460 | if (hdr->u.req.m_method_wks_idx == HTTP_WKSIDX_CONNECT) { |
| 461 | *bufindex -= 1; // remove trailing slash for CONNECT request |
| 462 | } |
| 463 | p = buf + *bufindex; |
| 464 | *p++ = ' '; |
| 465 | *bufindex += 1; |
| 466 | } else { |
| 467 | return 0; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if (bufsize - *bufindex >= 9) { |
| 472 | http_hdr_version_to_string(hdr->m_version, p); |
| 473 | *bufindex += 9 - 1; // overwrite '\0'; |
| 474 | } else { |
| 475 | TRY(http_version_print(hdr->m_version, buf, bufsize, bufindex, dumpoffset)); |
| 476 | } |
| 477 | |
| 478 | if (bufsize - *bufindex >= 2) { |
| 479 | p = buf + *bufindex; |
| 480 | *p++ = '\r'; |
| 481 | *p++ = '\n'; |
| 482 | *bufindex += 2; |
| 483 | } else { |
| 484 | TRY(mime_mem_print("\r\n", 2, buf, bufsize, bufindex, dumpoffset)); |
| 485 | } |
| 486 | |
| 487 | TRY(mime_hdr_print(hdr->m_fields_impl, buf, bufsize, bufindex, dumpoffset)); |
| 488 |
no test coverage detected