4#ifndef PROTOCORE_HTTP_PARSER_H
5#define PROTOCORE_HTTP_PARSER_H
19EMBED_ENUM_BYTE(ParseState, PARSE_METHOD, PARSE_PATH, PARSE_QUERY, PARSE_VERSION, PARSE_HEADER_KEY, PARSE_HEADER_VAL,
20 PARSE_EXPECT_LF, PARSE_EXPECT_BODY_LF, PARSE_BODY, PARSE_COMPLETE, PARSE_ERROR, PARSE_ENTITY_TOO_LARGE,
56#if PROTOCORE_CAPTURE_AUTH_HEADER
59 embed_bool cur_is_auth;
77#if PROTOCORE_ENABLE_STREAM_BODY
78 embed_bool body_streaming;
102 const char *(*get_header)(
const uint8_t *,
const HttpReq *,
const char *);
105 const char *(*get_query)(
const uint8_t *,
const HttpReq *,
const char *);
106 embed_bool (*
get_form)(
const uint8_t *,
const HttpReq *,
const char *,
char *, size_t);
107 const char *(*get_param)(
const uint8_t *,
const HttpReq *,
const char *);
110 get_form, get_param);
163 embed_bool *is_https);
#define MAX_VAL_LEN
Maximum header field-value length.
#define MAX_QUERY_PARAMS
Maximum number of parsed query-string parameters.
#define MAX_QUERY_LEN
Maximum raw query-string length (everything after ?).
#define QUERY_VAL_LEN
Maximum query-parameter value length.
#define BODY_BUF_SIZE
Maximum request body bytes stored in HttpReq::body.
#define PROTOCORE_AUTH_HDR_CAP
#define MAX_HEADERS
Maximum HTTP headers stored per request.
#define MAX_PATH_LEN
Maximum URL path length (including leading /).
#define QUERY_KEY_LEN
Maximum query-parameter key length.
#define MAX_KEY_LEN
Maximum header field-name length (e.g. "Content-Type").
#define PROTOCORE_METHOD_BUF_SIZE
HTTP method-token buffer size (bytes, including the NUL).
#define MAX_PATH_PARAMS
Maximum number of :name path parameters captured per route match.
embed_bool protocore_http_parser_get_form(const uint8_t *work, const HttpReq *req, const char *key, char *out, size_t out_size)
Get_form.
void protocore_http_parser_reset(uint8_t *work, HttpReq *req)
Reset.
const char * protocore_http_parser_get_param(const uint8_t *work, const HttpReq *req, const char *key)
Get_param.
embed_bool(* HttpStreamBeginCb)(HttpReq *req)
const char * protocore_http_parser_get_query(const uint8_t *work, const HttpReq *req, const char *key)
Get_query.
embed_bool protocore_http_parser_forwarded_client(const uint8_t *work, const HttpReq *req, char *ip_out, size_t ip_cap, embed_bool *is_https)
Forwarded_client.
void(* HttpStreamDataCb)(HttpReq *req, const uint8_t *data, size_t len)
EMBED_ENUM_BYTE(ParseState, PARSE_METHOD, PARSE_PATH, PARSE_QUERY, PARSE_VERSION, PARSE_HEADER_KEY, PARSE_HEADER_VAL, PARSE_EXPECT_LF, PARSE_EXPECT_BODY_LF, PARSE_BODY, PARSE_COMPLETE, PARSE_ERROR, PARSE_ENTITY_TOO_LARGE, PARSE_URI_TOO_LONG)
void protocore_http_parser_set_stream_hooks(uint8_t *work, HttpStreamBeginCb begin, HttpStreamDataCb data, HttpStreamAbortCb abort)
Set_stream_hooks.
void protocore_http_parser_feed(uint8_t *work, HttpReq *req, uint8_t byte)
Feed.
void(* HttpStreamAbortCb)(HttpReq *req)
HttpReq http_pool[CONN_POOL_SLOTS]
The per-slot request table every HTTP layer parses into and reads back out of.
embed_bool protocore_http_parser_get_cookie(const uint8_t *work, const HttpReq *req, const char *name, char *out, size_t out_size)
Get_cookie.
const char * protocore_http_parser_get_header(const uint8_t *work, const HttpReq *req, const char *key)
Get_header.
uint8_t * protocore_http_parser_span(void)
The PROTOCORE_HTTP_PARSER_BORROW bytes this module's state lives in.
#define PROTOCORE_UNUSED
Suppress the unused warning. Every module ends in a namespace most callers only partly use.
#define PROTOCORE_NS_LAYOUT(T,...)
Pin every dispatch slot of a table that is nothing but function pointers.
#define PROTOCORE_NS
Storage for a dispatch table. The const is load bearing.
Dispatch table. Addressed by offset, so the layout is asserted below.
void(* feed)(uint8_t *, HttpReq *, uint8_t)
void(* set_stream_hooks)(uint8_t *, HttpStreamBeginCb, HttpStreamDataCb, HttpStreamAbortCb)
embed_bool(* get_cookie)(const uint8_t *, const HttpReq *, const char *, char *, size_t)
embed_bool(* forwarded_client)(const uint8_t *, const HttpReq *, char *, size_t, embed_bool *)
void(* reset)(uint8_t *, HttpReq *)
embed_bool(* get_form)(const uint8_t *, const HttpReq *, const char *, char *, size_t)
QueryParam query_params[MAX_QUERY_PARAMS]
Header headers[MAX_HEADERS]
char query[MAX_QUERY_LEN]
uint8_t body[BODY_BUF_SIZE+1]
QueryParam path_params[MAX_PATH_PARAMS]
char cur_key[MAX_KEY_LEN]
uint8_t content_length_count
char cur_val[MAX_VAL_LEN]
char method[PROTOCORE_METHOD_BUF_SIZE]