12typedef int (*
KlWriteFn)(
void *ctx,
const char *data,
size_t len);
KlBodyMode
Definition response.h:14
@ KL_BODY_NONE
Definition response.h:15
@ KL_BODY_FILE
Definition response.h:17
@ KL_BODY_STREAM
Definition response.h:18
@ KL_BODY_BUFFER
Definition response.h:16
int kl_response_end_stream(KlResponse *res)
End chunked stream (sends final zero-length chunk).
int(* KlWriteFn)(void *ctx, const char *data, size_t len)
Pluggable write callback — same signature as sh_json's ShJsonWriteFn.
Definition response.h:12
void kl_response_file(KlResponse *res, int fd, off_t size)
Set a file body for zero-copy sendfile transfer.
int kl_response_init(KlResponse *res, KlAllocator *alloc)
Initialize a response, allocating the header buffer.
void kl_response_body_borrow(KlResponse *res, const char *data, size_t len)
Set a buffered body (pointer is borrowed, not copied).
int kl_response_error(KlResponse *res, int code, const char *message)
Convenience: set status, Content-Type: text/plain, and error message.
int kl_response_enable_drain(KlResponse *res, KlAllocator *alloc, size_t max_size)
Enable drain-based backpressure for chunked streaming.
void kl_response_status(KlResponse *res, int code)
Set the HTTP status code (default 200).
void kl_response_reset(KlResponse *res)
Fast reinit for keep-alive — reuses header buffer, no alloc.
int kl_response_json(KlResponse *res, int code, const char *json, size_t len)
Convenience: set status, Content-Type: application/json, and body.
int kl_response_begin_stream(KlResponse *res, int status, KlWriteFn *out_write, void **out_ctx)
Begin chunked streaming response.
int kl_response_send(KlResponse *res)
Flush headers + body to the connection fd.
int kl_response_header(KlResponse *res, const char *name, const char *value)
Append a header. Both name and value must be null-terminated. Strings containing CR or LF are rejecte...
void kl_response_free(KlResponse *res)
Free response resources (header buffer, close file fd).
int kl_response_body_copy(KlResponse *res, const char *data, size_t len)
Set a buffered body by copying data into an owned buffer.
Bring-your-own allocator vtable.
Definition allocator.h:12
Backpressure write buffer.
Definition drain.h:33
int drain_enabled
Definition response.h:47
const char * body
Definition response.h:33
off_t file_size
Definition response.h:40
int stream_ended
Definition response.h:44
int stream_error
Definition response.h:43
size_t hdr_cap
Definition response.h:27
KlTls * tls
Definition response.h:54
int head_request
Definition response.h:52
int conn_fd
Definition response.h:23
size_t body_len
Definition response.h:34
int headers_sent
Definition response.h:30
off_t file_offset
Definition response.h:41
int status
Definition response.h:29
int file_fd
Definition response.h:39
size_t hdr_len
Definition response.h:26
char * hdr_buf
Definition response.h:25
KlAllocator * alloc
Definition response.h:22
KlBodyMode body_mode
Definition response.h:31
char * body_owned
Definition response.h:36
int keep_alive
Definition response.h:51
size_t send_offset
Definition response.h:49
size_t body_owned_size
Definition response.h:37
KlDrain drain
Definition response.h:46