42#ifndef __NILOREA_HTTP_RESPONSE_HEADER
43#define __NILOREA_HTTP_RESPONSE_HEADER
60#define N_HTTP_RESPONSE_HEADERS_MAX 64
62#define N_HTTP_RESPONSE_VALUE_MAX 8192
static N_GUI_MOUSE_EVENT last
the last event the widget was told of, and how many
int version_minor
HTTP/1.x minor version of the request (0 or 1).
long long fd_length
file body length
int status
status code, 100..599
int fd
file body descriptor (owned, closed on free), or -1
size_t nb_headers
number of headers
char * names[64]
header names, nb_headers of them
long long fd_offset
file body start offset
int head_only
non-zero: send headers only (HEAD request)
char * values[64]
header values
N_STR * body
memory body, or NULL
int keep_alive
non-zero: the connection stays open after this response
N_HTTP_RANGE n_http_parse_range(const char *value, size_t len, long long total, long long *first, long long *last)
interpret a Range header for a body of total bytes
#define N_HTTP_RESPONSE_HEADERS_MAX
most headers a response may carry
int n_http_response_append(N_HTTP_RESP *r, const void *data, size_t len)
append bytes to the memory body (drops a file body)
const char * n_http_status_reason(int status)
reason phrase of a status code ("Not Found"); a generic class phrase for an unlisted code,...
int n_http_response_head(const N_HTTP_RESP *r, N_STR **out)
append the status line and headers, through the blank line
int n_http_response_set_header(N_HTTP_RESP *r, const char *name, const char *value)
set a header: remove every header of that name (ASCII case-insensitive), then add it; same refusals a...
ssize_t(* n_http_write_fn)(void *ctx, const void *buf, size_t len)
a write function: write up to len bytes, return how many were written (at least 1) or -1 on a fatal e...
int n_http_response_add_header(N_HTTP_RESP *r, const char *name, const char *value)
add a header line (repeats allowed, e.g.
int n_http_response_file(N_HTTP_RESP *r, int fd, long long offset, long long length)
use a file range as the body; the response owns fd from now on (it is closed on free,...
int n_http_response_set_status(N_HTTP_RESP *r, int status)
change the status code
long long n_http_response_body_length(const N_HTTP_RESP *r)
body length the response declares (Content-Length), 0 for a bodiless status
size_t n_http_response_remove_header(N_HTTP_RESP *r, const char *name)
remove every header of that name (ASCII case-insensitive)
N_HTTP_RANGE
result of n_http_parse_range()
int n_http_response_write(const N_HTTP_RESP *r, n_http_write_fn fn, void *ctx)
write the whole response (head, then body unless HEAD or bodiless)
int n_http_response_set_connection(N_HTTP_RESP *r, int keep_alive, int version_minor, int head_only)
connection handling for this response
void n_http_response_free(N_HTTP_RESP **r)
free a response (closing its file body) and set *r to NULL
const char * n_http_response_get_header(const N_HTTP_RESP *r, const char *name)
value of the first header of that name (ASCII case-insensitive)
N_HTTP_RESP * n_http_response_new(int status)
new response with a status, keep-alive off, HTTP/1.1
@ N_HTTP_RANGE_NONE
no usable Range: send the whole body (200)
@ N_HTTP_RANGE_UNSATISFIABLE
send 416, with a Content-Range that gives only the total
@ N_HTTP_RANGE_OK
one satisfiable range: send 206
a response under construction (fields are private, use the functions)
A box including a string and his lenght.
N_STR and string function declaration.