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)
53 struct http_parser_settings;
74 typedef int (*http_data_cb) (http_parser*,
const char *at,
size_t length);
75 typedef int (*http_cb) (http_parser*);
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,
201 enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
207 , F_CONNECTION_KEEP_ALIVE = 1 << 1
208 , F_CONNECTION_CLOSE = 1 << 2
209 , F_CONNECTION_UPGRADE = 1 << 3
210 , F_TRAILING = 1 << 4
212 , F_SKIPBODY = 1 << 6
213 , F_CONTENTLENGTH = 1 << 7
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,
270 HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
272 #undef HTTP_ERRNO_GEN
276 #define HTTP_PARSER_ERRNO(p) ((::wpi::http_errno) (p)->http_errno)
282 unsigned int flags : 8;
283 unsigned int state : 7;
284 unsigned int header_state : 7;
285 unsigned int index : 7;
286 unsigned int lenient_http_headers : 1;
289 uint64_t content_length;
293 unsigned short http_minor;
294 unsigned int status_code : 16;
295 unsigned int method : 8;
296 unsigned int http_errno : 7;
303 unsigned int upgrade : 1;
311 http_cb on_message_begin;
313 http_data_cb on_status;
314 http_data_cb on_header_field;
315 http_data_cb on_header_value;
316 http_cb on_headers_complete;
317 http_data_cb on_body;
318 http_cb on_message_complete;
322 http_cb on_chunk_header;
323 http_cb on_chunk_complete;
327 enum http_parser_url_fields
353 } field_data[UF_MAX];
367 unsigned long http_parser_version(
void);
369 void http_parser_init(http_parser *parser,
enum http_parser_type type);
379 size_t http_parser_execute(http_parser *parser,
391 int http_should_keep_alive(
const http_parser *parser);
394 const char *http_method_str(
enum http_method m);
397 const char *http_status_str(
enum http_status s);
400 const char *http_errno_name(
enum http_errno err);
403 const char *http_errno_description(
enum http_errno err);
409 int http_parser_parse_url(
const char *buf,
size_t buflen,
414 void http_parser_pause(http_parser *parser,
int paused);
417 int http_body_is_final(
const http_parser *parser);
Definition: http_parser.h:310
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
Definition: http_parser.h:346
unsigned short http_major
READ-ONLY.
Definition: http_parser.h:292
unsigned int type
PRIVATE.
Definition: http_parser.h:281
void * data
PUBLIC.
Definition: http_parser.h:306