| 517 | } |
| 518 | |
| 519 | void cbm_http_reply_buf(cbm_http_conn_t *c, int status, const char *extra_headers, const void *data, |
| 520 | size_t len) { |
| 521 | if (!c) |
| 522 | return; |
| 523 | c->response_status = status; |
| 524 | c->response_bytes = len; |
| 525 | char head[1024]; |
| 526 | int hn = snprintf(head, sizeof(head), |
| 527 | "HTTP/1.1 %d %s\r\n" |
| 528 | "%s" |
| 529 | "Content-Length: %zu\r\n" |
| 530 | "Connection: close\r\n" |
| 531 | "\r\n", |
| 532 | status, status_reason(status), extra_headers ? extra_headers : "", len); |
| 533 | if (hn < 0 || hn >= (int)sizeof(head)) |
| 534 | return; /* oversized extra_headers — drop the response, conn closes */ |
| 535 | if (send_all(c->fd, head, (size_t)hn) != 0) |
| 536 | return; |
| 537 | if (len > 0) |
| 538 | (void)send_all(c->fd, data, len); |
| 539 | } |
| 540 | |
| 541 | void cbm_http_replyf(cbm_http_conn_t *c, int status, const char *extra_headers, const char *fmt, |
| 542 | ...) { |
no test coverage detected