47#ifndef __NILOREA_HTTP_SERVER_HEADER
48#define __NILOREA_HTTP_SERVER_HEADER
#define N_HTTP_REQ_PATH_MAX
Longest origin-form request target ('/'-prefixed, query included).
a response under construction (fields are private, use the functions)
int body_timeout_ms
body deadline, ms (default 60000)
int header_timeout_ms
request head deadline from its first byte, ms (default 10000)
unsigned long long requests
requests answered
unsigned long long timeouts
connections ended by a deadline
int body_status
after a failed body read: the status to answer (408, 413...)
char target[2048u+2]
private: storage for path and query
const char * raw
the raw head, for n_http_server_header()
size_t max_requests_per_conn
requests served on one connection before it is closed (default 1000)
unsigned long long active
connections being served now
size_t workers
worker threads = most concurrent connections (default 32)
const char * port
port to bind ("7430")
int write_timeout_ms
deadline to write one response, ms (default 60000)
unsigned long long accepted
connections accepted
size_t query_len
length of query
long long max_body
largest Content-Length accepted at all (default 32 MiB); handlers pass their own, lower cap to the bo...
const char * tls_key_file
PEM private key, NULL for plain HTTP.
const char * tls_cert_file
PEM certificate chain, NULL for plain HTTP.
const char * path
the path, without the query string, still percent-encoded
n_http_server_handler handler
the application
const char * addr
address to bind ("127.0.0.1")
size_t max_per_ip
most connections from one peer address, 0 for no limit (default 0: behind a reverse proxy every conne...
n_http_request head
the parsed head (method, version_minor, content_length, headers)
size_t path_len
length of path
void * conn
private: the connection
int require_host
refuse HTTP/1.1 requests without exactly one Host (default 1)
unsigned long long refused
connections refused (queue full, per-IP cap)
const char * peer_ip
peer address as text
const char * query
the query string without '?
void * user
passed to the handler
int idle_timeout_ms
wait for the next request on a kept-alive connection, ms (default 15000)
unsigned long long tls_failures
failed TLS handshakes
unsigned long long bad_requests
400 / 413 / 417 / 431 answered by the server
int handshake_timeout_ms
TLS handshake deadline, ms (default 10000).
void n_http_server_stats(N_HTTP_SERVER *srv, N_HTTP_SERVER_STATS *out)
copy of the counters
int n_http_server_read_body_to_fd(N_HTTP_SERVER_REQUEST *req, long long max, int fd)
read the whole body into an open file descriptor (for uploads)
int n_http_server_run(N_HTTP_SERVER *srv)
serve until n_http_server_stop(): start the workers, accept, then stop accepting, let the workers fin...
const char * n_http_server_header(const N_HTTP_SERVER_REQUEST *req, const char *name, size_t *len)
a request header, see n_http_request_header()
N_HTTP_SERVER * n_http_server_new(const N_HTTP_SERVER_CONFIG *cfg)
bind the listening socket and load the TLS context
N_HTTP_RESP *(* n_http_server_handler)(struct N_HTTP_SERVER_REQUEST *req, void *user)
the application: build the response for a request; NULL means 500
void n_http_server_stop(N_HTTP_SERVER *srv)
ask the server to stop; async-signal-safe, any thread
int n_http_server_read_body(N_HTTP_SERVER_REQUEST *req, long long max, N_STR **out)
read the whole body into memory
void n_http_server_free(N_HTTP_SERVER **srv)
free a stopped server and set *srv to NULL
void n_http_server_config_defaults(N_HTTP_SERVER_CONFIG *cfg)
fill a config with the defaults documented on each field
server settings; start from n_http_server_config_defaults()
a request as the handler sees it (fields are read-only)
counters, see n_http_server_stats()
A box including a string and his lenght.
Pure, strict, bounded parser for an HTTP/1.1 request head.
HTTP/1.1 response: validated headers, memory or file body, framing.
N_STR and string function declaration.