![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
HTTP/1.1 request-head parser (see n_http_req.h). More...
Go to the source code of this file.
Functions | |
| static int | lc (int c) |
| n_http_req_status | n_http_request_parse (const char *buf, size_t len, n_http_request *out) |
| parse an HTTP/1.1 request head from [buf, buf+len) | |
| static int | name_eq (const char *s, size_t n, const char *lit) |
| static int | name_token_ok (const char *s, size_t n) |
| static int | parse_body_len (const char *s, size_t n, long long *out) |
| static int | target_ok (unsigned char c) |
HTTP/1.1 request-head parser (see n_http_req.h).
A small, strict scanner, bounded and over-read safe on every path.
Definition in file n_http_req.c.
|
static |
Definition at line 31 of file n_http_req.c.
Referenced by name_eq().
| n_http_req_status n_http_request_parse | ( | const char * | buf, |
| size_t | len, | ||
| n_http_request * | out ) |
parse an HTTP/1.1 request head from [buf, buf+len)
Returns N_HTTP_REQ_OK only when a complete head (through CRLFCRLF) is present and every rule holds: the method is GET or POST; the target is origin-form ('/'-prefixed, no spaces or control bytes, no fragment, within N_HTTP_REQ_PATH_MAX); the version is HTTP/1.0 or 1.1; at most N_HTTP_REQ_HEADERS_MAX headers; no Transfer-Encoding; at most one Content-Length, a valid non-negative integer within N_HTTP_REQ_BODY_MAX. On OK, out is filled and out->head_len marks the body start.
Returns N_HTTP_REQ_INCOMPLETE when no CRLFCRLF has arrived yet and the buffered bytes are still under N_HTTP_REQ_HEAD_MAX (read more), and N_HTTP_REQ_ERROR for anything malformed, unsupported, or over the head cap. Bounded and over-read safe on every path.
| buf | the received bytes (may be NULL) |
| len | number of bytes in buf |
| out | the request head to fill (zeroed first) |
Definition at line 83 of file n_http_req.c.
References n_http_request::authorization, n_http_request::content_length, n_http_request::head_len, le(), n_http_request::method, N_HTTP_REQ_AUTH_MAX, N_HTTP_REQ_ERROR, N_HTTP_REQ_GET, N_HTTP_REQ_HEAD_MAX, N_HTTP_REQ_HEADERS_MAX, N_HTTP_REQ_INCOMPLETE, N_HTTP_REQ_OK, N_HTTP_REQ_PATH_MAX, N_HTTP_REQ_POST, name_eq(), name_token_ok(), parse_body_len(), n_http_request::path, and target_ok().
Referenced by main(), and parse().
|
static |
Definition at line 37 of file n_http_req.c.
References lc().
Referenced by n_http_request_parse().
|
static |
Definition at line 48 of file n_http_req.c.
Referenced by n_http_request_parse().
|
static |
Definition at line 61 of file n_http_req.c.
References N_HTTP_REQ_BODY_MAX.
Referenced by n_http_request_parse().
|
static |
Definition at line 79 of file n_http_req.c.
Referenced by n_http_request_parse().