Common code invoked for both HSE_REQ_SEND_RESPONSE_HEADER and * the newer HSE_REQ_SEND_RESPONSE_HEADER_EX ServerSupportFunction(s) * as well as other functions that write responses and presume that * the support functions above are optional. * * Other callers trying to split headers and body bytes should pass * head/headlen alone (leaving stat/statlen NULL/0), so that they * get a proper co
| 623 | * isn't counted as the head bytes are. |
| 624 | */ |
| 625 | static apr_ssize_t send_response_header(isapi_cid *cid, |
| 626 | const char *stat, |
| 627 | const char *head, |
| 628 | apr_size_t statlen, |
| 629 | apr_size_t headlen) |
| 630 | { |
| 631 | int head_present = 1; |
| 632 | int termarg; |
| 633 | int res; |
| 634 | int old_status; |
| 635 | const char *termch; |
| 636 | apr_size_t ate = 0; |
| 637 | |
| 638 | if (!head || headlen == 0 || !*head) { |
| 639 | head = stat; |
| 640 | stat = NULL; |
| 641 | headlen = statlen; |
| 642 | statlen = 0; |
| 643 | head_present = 0; /* Don't eat the header */ |
| 644 | } |
| 645 | |
| 646 | if (!stat || statlen == 0 || !*stat) { |
| 647 | if (head && headlen && *head && ((stat = memchr(head, '\r', headlen)) |
| 648 | || (stat = memchr(head, '\n', headlen)) |
| 649 | || (stat = memchr(head, '\0', headlen)) |
| 650 | || (stat = head + headlen))) { |
| 651 | statlen = stat - head; |
| 652 | if (memchr(head, ':', statlen)) { |
| 653 | stat = "Status: 200 OK"; |
| 654 | statlen = strlen(stat); |
| 655 | } |
| 656 | else { |
| 657 | const char *flip = head; |
| 658 | head = stat; |
| 659 | stat = flip; |
| 660 | headlen -= statlen; |
| 661 | ate += statlen; |
| 662 | if (*head == '\r' && headlen) |
| 663 | ++head, --headlen, ++ate; |
| 664 | if (*head == '\n' && headlen) |
| 665 | ++head, --headlen, ++ate; |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | if (stat && (statlen > 0) && *stat) { |
| 671 | char *newstat; |
| 672 | if (!apr_isdigit(*stat)) { |
| 673 | const char *stattok = stat; |
| 674 | int toklen = statlen; |
| 675 | while (toklen && *stattok && !apr_isspace(*stattok)) { |
| 676 | ++stattok; --toklen; |
| 677 | } |
| 678 | while (toklen && apr_isspace(*stattok)) { |
| 679 | ++stattok; --toklen; |
| 680 | } |
| 681 | /* Now decide if we follow the xxx message |
| 682 | * or the http/x.x xxx message format |
no test coverage detected