21#ifndef wpi_http_parser_h
22#define wpi_http_parser_h
25#define HTTP_PARSER_VERSION_MAJOR 2
26#define HTTP_PARSER_VERSION_MINOR 8
27#define HTTP_PARSER_VERSION_PATCH 1
35#ifndef HTTP_PARSER_STRICT
36# define HTTP_PARSER_STRICT 1
46#ifndef HTTP_MAX_HEADER_SIZE
47# define HTTP_MAX_HEADER_SIZE (80*1024)
53struct http_parser_settings;
74typedef int (*
http_data_cb) (http_parser*,
const char *at,
size_t length);
79#define HTTP_STATUS_MAP(XX) \
80 XX(100, CONTINUE, Continue) \
81 XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \
82 XX(102, PROCESSING, Processing) \
84 XX(201, CREATED, Created) \
85 XX(202, ACCEPTED, Accepted) \
86 XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \
87 XX(204, NO_CONTENT, No Content) \
88 XX(205, RESET_CONTENT, Reset Content) \
89 XX(206, PARTIAL_CONTENT, Partial Content) \
90 XX(207, MULTI_STATUS, Multi-Status) \
91 XX(208, ALREADY_REPORTED, Already Reported) \
92 XX(226, IM_USED, IM Used) \
93 XX(300, MULTIPLE_CHOICES, Multiple Choices) \
94 XX(301, MOVED_PERMANENTLY, Moved Permanently) \
95 XX(302, FOUND, Found) \
96 XX(303, SEE_OTHER, See Other) \
97 XX(304, NOT_MODIFIED, Not Modified) \
98 XX(305, USE_PROXY, Use Proxy) \
99 XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \
100 XX(308, PERMANENT_REDIRECT, Permanent Redirect) \
101 XX(400, BAD_REQUEST, Bad Request) \
102 XX(401, UNAUTHORIZED, Unauthorized) \
103 XX(402, PAYMENT_REQUIRED, Payment Required) \
104 XX(403, FORBIDDEN, Forbidden) \
105 XX(404, NOT_FOUND, Not Found) \
106 XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \
107 XX(406, NOT_ACCEPTABLE, Not Acceptable) \
108 XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \
109 XX(408, REQUEST_TIMEOUT, Request Timeout) \
110 XX(409, CONFLICT, Conflict) \
111 XX(410, GONE, Gone) \
112 XX(411, LENGTH_REQUIRED, Length Required) \
113 XX(412, PRECONDITION_FAILED, Precondition Failed) \
114 XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \
115 XX(414, URI_TOO_LONG, URI Too Long) \
116 XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \
117 XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \
118 XX(417, EXPECTATION_FAILED, Expectation Failed) \
119 XX(421, MISDIRECTED_REQUEST, Misdirected Request) \
120 XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \
121 XX(423, LOCKED, Locked) \
122 XX(424, FAILED_DEPENDENCY, Failed Dependency) \
123 XX(426, UPGRADE_REQUIRED, Upgrade Required) \
124 XX(428, PRECONDITION_REQUIRED, Precondition Required) \
125 XX(429, TOO_MANY_REQUESTS, Too Many Requests) \
126 XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
127 XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \
128 XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \
129 XX(501, NOT_IMPLEMENTED, Not Implemented) \
130 XX(502, BAD_GATEWAY, Bad Gateway) \
131 XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \
132 XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \
133 XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \
134 XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \
135 XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \
136 XX(508, LOOP_DETECTED, Loop Detected) \
137 XX(510, NOT_EXTENDED, Not Extended) \
138 XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
142#define XX(num, name, string) HTTP_STATUS_##name = num,
149#define HTTP_METHOD_MAP(XX) \
150 XX(0, DELETE, DELETE) \
156 XX(5, CONNECT, CONNECT) \
157 XX(6, OPTIONS, OPTIONS) \
158 XX(7, TRACE, TRACE) \
162 XX(10, MKCOL, MKCOL) \
164 XX(12, PROPFIND, PROPFIND) \
165 XX(13, PROPPATCH, PROPPATCH) \
166 XX(14, SEARCH, SEARCH) \
167 XX(15, UNLOCK, UNLOCK) \
169 XX(17, REBIND, REBIND) \
170 XX(18, UNBIND, UNBIND) \
173 XX(20, REPORT, REPORT) \
174 XX(21, MKACTIVITY, MKACTIVITY) \
175 XX(22, CHECKOUT, CHECKOUT) \
176 XX(23, MERGE, MERGE) \
178 XX(24, MSEARCH, M-SEARCH) \
179 XX(25, NOTIFY, NOTIFY) \
180 XX(26, SUBSCRIBE, SUBSCRIBE) \
181 XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
183 XX(28, PATCH, PATCH) \
184 XX(29, PURGE, PURGE) \
186 XX(30, MKCALENDAR, MKCALENDAR) \
189 XX(32, UNLINK, UNLINK) \
191 XX(33, SOURCE, SOURCE) \
195#define XX(num, name, string) HTTP_##name = num,
221#define HTTP_ERRNO_MAP(XX) \
226 XX(CB_message_begin, "the on_message_begin callback failed") \
227 XX(CB_url, "the on_url callback failed") \
228 XX(CB_header_field, "the on_header_field callback failed") \
229 XX(CB_header_value, "the on_header_value callback failed") \
230 XX(CB_headers_complete, "the on_headers_complete callback failed") \
231 XX(CB_body, "the on_body callback failed") \
232 XX(CB_message_complete, "the on_message_complete callback failed") \
233 XX(CB_status, "the on_status callback failed") \
234 XX(CB_chunk_header, "the on_chunk_header callback failed") \
235 XX(CB_chunk_complete, "the on_chunk_complete callback failed") \
238 XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
239 XX(HEADER_OVERFLOW, \
240 "too many header bytes seen; overflow detected") \
241 XX(CLOSED_CONNECTION, \
242 "data received after completed connection: close message") \
243 XX(INVALID_VERSION, "invalid HTTP version") \
244 XX(INVALID_STATUS, "invalid HTTP status code") \
245 XX(INVALID_METHOD, "invalid HTTP method") \
246 XX(INVALID_URL, "invalid URL") \
247 XX(INVALID_HOST, "invalid host") \
248 XX(INVALID_PORT, "invalid port") \
249 XX(INVALID_PATH, "invalid path") \
250 XX(INVALID_QUERY_STRING, "invalid query string") \
251 XX(INVALID_FRAGMENT, "invalid fragment") \
252 XX(LF_EXPECTED, "LF character expected") \
253 XX(INVALID_HEADER_TOKEN, "invalid character in header") \
254 XX(INVALID_CONTENT_LENGTH, \
255 "invalid character in content-length header") \
256 XX(UNEXPECTED_CONTENT_LENGTH, \
257 "unexpected content-length header") \
258 XX(INVALID_CHUNK_SIZE, \
259 "invalid character in chunk size header") \
260 XX(INVALID_CONSTANT, "invalid constant string") \
261 XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
262 XX(STRICT, "strict mode assertion failed") \
263 XX(PAUSED, "parser is paused") \
264 XX(UNKNOWN, "an unknown error occurred")
268#define HTTP_ERRNO_GEN(n, s) HPE_##n,
276#define HTTP_PARSER_ERRNO(p) ((::wpi::http_errno) (p)->http_errno)
#define XX(num, name, string)
Definition: http_parser.h:195
#define HTTP_METHOD_MAP(XX)
Definition: http_parser.h:149
#define HTTP_ERRNO_MAP(XX)
Definition: http_parser.h:221
#define HTTP_ERRNO_GEN(n, s)
Definition: http_parser.h:268
#define HTTP_STATUS_MAP(XX)
Definition: http_parser.h:79
type
Definition: core.h:556
Definition: ntcore_cpp.h:26
unsigned long http_parser_version(void)
const char * http_errno_description(enum http_errno err)
void http_parser_url_init(struct http_parser_url *u)
int http_parser_parse_url(const char *buf, size_t buflen, int is_connect, struct http_parser_url *u)
const char * http_method_str(enum http_method m)
size_t http_parser_execute(http_parser *parser, const http_parser_settings *settings, const char *data, size_t len)
void http_parser_settings_init(http_parser_settings *settings)
const char * http_errno_name(enum http_errno err)
int http_body_is_final(const http_parser *parser)
int http_should_keep_alive(const http_parser *parser)
void http_parser_init(http_parser *parser, enum http_parser_type type)
const char * http_status_str(enum http_status s)
void http_parser_pause(http_parser *parser, int paused)
Definition: http_parser.h:310
http_cb on_message_begin
Definition: http_parser.h:311
http_data_cb on_header_value
Definition: http_parser.h:315
http_data_cb on_status
Definition: http_parser.h:313
http_data_cb on_header_field
Definition: http_parser.h:314
http_cb on_chunk_complete
Definition: http_parser.h:323
http_cb on_headers_complete
Definition: http_parser.h:316
http_cb on_chunk_header
Definition: http_parser.h:322
http_cb on_message_complete
Definition: http_parser.h:318
http_data_cb on_url
Definition: http_parser.h:312
http_data_cb on_body
Definition: http_parser.h:317
Definition: http_parser.h:346
struct wpi::http_parser_url::@17 field_data[UF_MAX]
uint16_t off
Definition: http_parser.h:351
uint16_t field_set
Definition: http_parser.h:347
uint16_t port
Definition: http_parser.h:348
uint16_t len
Definition: http_parser.h:352
Definition: http_parser.h:279
unsigned int http_errno
Definition: http_parser.h:296
unsigned int lenient_http_headers
Definition: http_parser.h:286
unsigned int method
Definition: http_parser.h:295
unsigned int type
PRIVATE.
Definition: http_parser.h:281
unsigned int index
Definition: http_parser.h:285
uint32_t nread
Definition: http_parser.h:288
unsigned int upgrade
Definition: http_parser.h:303
unsigned int state
Definition: http_parser.h:283
unsigned short http_major
READ-ONLY.
Definition: http_parser.h:292
unsigned int flags
Definition: http_parser.h:282
unsigned int header_state
Definition: http_parser.h:284
unsigned short http_minor
Definition: http_parser.h:293
unsigned int status_code
Definition: http_parser.h:294
uint64_t content_length
Definition: http_parser.h:289
void * data
PUBLIC.
Definition: http_parser.h:306
http_errno
Definition: http_parser.h:269
int(* http_cb)(http_parser *)
Definition: http_parser.h:75
http_method
Definition: http_parser.h:194
flags
Definition: http_parser.h:206
@ F_SKIPBODY
Definition: http_parser.h:212
@ F_CHUNKED
Definition: http_parser.h:206
@ F_CONNECTION_UPGRADE
Definition: http_parser.h:209
@ F_CONTENTLENGTH
Definition: http_parser.h:213
@ F_CONNECTION_CLOSE
Definition: http_parser.h:208
@ F_TRAILING
Definition: http_parser.h:210
@ F_UPGRADE
Definition: http_parser.h:211
@ F_CONNECTION_KEEP_ALIVE
Definition: http_parser.h:207
http_parser_type
Definition: http_parser.h:201
@ HTTP_BOTH
Definition: http_parser.h:201
@ HTTP_REQUEST
Definition: http_parser.h:201
@ HTTP_RESPONSE
Definition: http_parser.h:201
http_status
Definition: http_parser.h:141
int(* http_data_cb)(http_parser *, const char *at, size_t length)
Definition: http_parser.h:74
http_parser_url_fields
Definition: http_parser.h:328
@ UF_QUERY
Definition: http_parser.h:332
@ UF_SCHEMA
Definition: http_parser.h:328
@ UF_PATH
Definition: http_parser.h:331
@ UF_FRAGMENT
Definition: http_parser.h:333
@ UF_MAX
Definition: http_parser.h:335
@ UF_USERINFO
Definition: http_parser.h:334
@ UF_HOST
Definition: http_parser.h:329
@ UF_PORT
Definition: http_parser.h:330