| 743 | } |
| 744 | |
| 745 | void cbm_http_reply_buf(cbm_http_conn_t *c, int status, const char *extra_headers, const void *data, |
| 746 | size_t len) { |
| 747 | if (!c) |
| 748 | return; |
| 749 | atomic_store_explicit(&c->response_started, true, memory_order_release); |
| 750 | c->response_status = status; |
| 751 | c->response_bytes = len; |
| 752 | char head[1024]; |
| 753 | int hn = snprintf(head, sizeof(head), |
| 754 | "HTTP/1.1 %d %s\r\n" |
| 755 | "%s" |
| 756 | "Content-Length: %zu\r\n" |
| 757 | "Connection: close\r\n" |
| 758 | "\r\n", |
| 759 | status, status_reason(status), extra_headers ? extra_headers : "", len); |
| 760 | if (hn < 0 || hn >= (int)sizeof(head)) |
| 761 | return; /* oversized extra_headers — drop the response, conn closes */ |
| 762 | int64_t deadline = now_ms() + c->send_deadline_ms; |
| 763 | if (send_all(c, head, (size_t)hn, deadline) != 0) |
| 764 | return; |
| 765 | if (len > 0) |
| 766 | (void)send_all(c, data, len, deadline); |
| 767 | } |
| 768 | |
| 769 | void cbm_http_replyf(cbm_http_conn_t *c, int status, const char *extra_headers, const char *fmt, |
| 770 | ...) { |