28#define HTTP_PARSER_VERSION_MAJOR 2
29#define HTTP_PARSER_VERSION_MINOR 9
30#define HTTP_PARSER_VERSION_PATCH 4
33#if defined(_WIN32) && !defined(__MINGW32__) && \
34 (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__)
37typedef unsigned __int8 uint8_t;
38typedef __int16 int16_t;
39typedef unsigned __int16 uint16_t;
40typedef __int32 int32_t;
41typedef unsigned __int32 uint32_t;
42typedef __int64 int64_t;
43typedef unsigned __int64 uint64_t;
51#ifndef HTTP_PARSER_STRICT
52# define HTTP_PARSER_STRICT 1
62#ifndef HTTP_MAX_HEADER_SIZE
63# define HTTP_MAX_HEADER_SIZE (80*1024)
93#define HTTP_STATUS_MAP(XX) \
94 XX(100, CONTINUE, Continue) \
95 XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \
96 XX(102, PROCESSING, Processing) \
98 XX(201, CREATED, Created) \
99 XX(202, ACCEPTED, Accepted) \
100 XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \
101 XX(204, NO_CONTENT, No Content) \
102 XX(205, RESET_CONTENT, Reset Content) \
103 XX(206, PARTIAL_CONTENT, Partial Content) \
104 XX(207, MULTI_STATUS, Multi-Status) \
105 XX(208, ALREADY_REPORTED, Already Reported) \
106 XX(226, IM_USED, IM Used) \
107 XX(300, MULTIPLE_CHOICES, Multiple Choices) \
108 XX(301, MOVED_PERMANENTLY, Moved Permanently) \
109 XX(302, FOUND, Found) \
110 XX(303, SEE_OTHER, See Other) \
111 XX(304, NOT_MODIFIED, Not Modified) \
112 XX(305, USE_PROXY, Use Proxy) \
113 XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \
114 XX(308, PERMANENT_REDIRECT, Permanent Redirect) \
115 XX(400, BAD_REQUEST, Bad Request) \
116 XX(401, UNAUTHORIZED, Unauthorized) \
117 XX(402, PAYMENT_REQUIRED, Payment Required) \
118 XX(403, FORBIDDEN, Forbidden) \
119 XX(404, NOT_FOUND, Not Found) \
120 XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \
121 XX(406, NOT_ACCEPTABLE, Not Acceptable) \
122 XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \
123 XX(408, REQUEST_TIMEOUT, Request Timeout) \
124 XX(409, CONFLICT, Conflict) \
125 XX(410, GONE, Gone) \
126 XX(411, LENGTH_REQUIRED, Length Required) \
127 XX(412, PRECONDITION_FAILED, Precondition Failed) \
128 XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \
129 XX(414, URI_TOO_LONG, URI Too Long) \
130 XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \
131 XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \
132 XX(417, EXPECTATION_FAILED, Expectation Failed) \
133 XX(421, MISDIRECTED_REQUEST, Misdirected Request) \
134 XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \
135 XX(423, LOCKED, Locked) \
136 XX(424, FAILED_DEPENDENCY, Failed Dependency) \
137 XX(426, UPGRADE_REQUIRED, Upgrade Required) \
138 XX(428, PRECONDITION_REQUIRED, Precondition Required) \
139 XX(429, TOO_MANY_REQUESTS, Too Many Requests) \
140 XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
141 XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \
142 XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \
143 XX(501, NOT_IMPLEMENTED, Not Implemented) \
144 XX(502, BAD_GATEWAY, Bad Gateway) \
145 XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \
146 XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \
147 XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \
148 XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \
149 XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \
150 XX(508, LOOP_DETECTED, Loop Detected) \
151 XX(510, NOT_EXTENDED, Not Extended) \
152 XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
156#define XX(num, name, string) HTTP_STATUS_##name = num,
163#define HTTP_METHOD_MAP(XX) \
164 XX(0, DELETE, DELETE) \
170 XX(5, CONNECT, CONNECT) \
171 XX(6, OPTIONS, OPTIONS) \
172 XX(7, TRACE, TRACE) \
176 XX(10, MKCOL, MKCOL) \
178 XX(12, PROPFIND, PROPFIND) \
179 XX(13, PROPPATCH, PROPPATCH) \
180 XX(14, SEARCH, SEARCH) \
181 XX(15, UNLOCK, UNLOCK) \
183 XX(17, REBIND, REBIND) \
184 XX(18, UNBIND, UNBIND) \
187 XX(20, REPORT, REPORT) \
188 XX(21, MKACTIVITY, MKACTIVITY) \
189 XX(22, CHECKOUT, CHECKOUT) \
190 XX(23, MERGE, MERGE) \
192 XX(24, MSEARCH, M-SEARCH) \
193 XX(25, NOTIFY, NOTIFY) \
194 XX(26, SUBSCRIBE, SUBSCRIBE) \
195 XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
197 XX(28, PATCH, PATCH) \
198 XX(29, PURGE, PURGE) \
200 XX(30, MKCALENDAR, MKCALENDAR) \
203 XX(32, UNLINK, UNLINK) \
205 XX(33, SOURCE, SOURCE) \
209#define XX(num, name, string) HTTP_##name = num,
236#define HTTP_ERRNO_MAP(XX) \
241 XX(CB_message_begin, "the on_message_begin callback failed") \
242 XX(CB_url, "the on_url callback failed") \
243 XX(CB_header_field, "the on_header_field callback failed") \
244 XX(CB_header_value, "the on_header_value callback failed") \
245 XX(CB_headers_complete, "the on_headers_complete callback failed") \
246 XX(CB_body, "the on_body callback failed") \
247 XX(CB_message_complete, "the on_message_complete callback failed") \
248 XX(CB_status, "the on_status callback failed") \
249 XX(CB_chunk_header, "the on_chunk_header callback failed") \
250 XX(CB_chunk_complete, "the on_chunk_complete callback failed") \
253 XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
254 XX(HEADER_OVERFLOW, \
255 "too many header bytes seen; overflow detected") \
256 XX(CLOSED_CONNECTION, \
257 "data received after completed connection: close message") \
258 XX(INVALID_VERSION, "invalid HTTP version") \
259 XX(INVALID_STATUS, "invalid HTTP status code") \
260 XX(INVALID_METHOD, "invalid HTTP method") \
261 XX(INVALID_URL, "invalid URL") \
262 XX(INVALID_HOST, "invalid host") \
263 XX(INVALID_PORT, "invalid port") \
264 XX(INVALID_PATH, "invalid path") \
265 XX(INVALID_QUERY_STRING, "invalid query string") \
266 XX(INVALID_FRAGMENT, "invalid fragment") \
267 XX(LF_EXPECTED, "LF character expected") \
268 XX(INVALID_HEADER_TOKEN, "invalid character in header") \
269 XX(INVALID_CONTENT_LENGTH, \
270 "invalid character in content-length header") \
271 XX(UNEXPECTED_CONTENT_LENGTH, \
272 "unexpected content-length header") \
273 XX(INVALID_CHUNK_SIZE, \
274 "invalid character in chunk size header") \
275 XX(INVALID_CONSTANT, "invalid constant string") \
276 XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
277 XX(STRICT, "strict mode assertion failed") \
278 XX(PAUSED, "parser is paused") \
279 XX(UNKNOWN, "an unknown error occurred") \
280 XX(INVALID_TRANSFER_ENCODING, \
281 "request has invalid transfer-encoding") \
285#define HTTP_ERRNO_GEN(n, s) HPE_##n,
293#define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
#define XX(num, name, string)
Definition http_parser.h:156
void http_parser_settings_init(http_parser_settings *settings)
Definition http_parser.cpp:2229
#define HTTP_METHOD_MAP(XX)
Definition http_parser.h:163
void http_parser_init(http_parser *parser, enum http_parser_type type)
Definition http_parser.cpp:2218
http_errno
Definition http_parser.h:286
unsigned long http_parser_version(void)
Definition http_parser.cpp:2559
const char * http_status_str(enum http_status s)
Definition http_parser.cpp:2207
size_t http_parser_execute(http_parser *parser, const http_parser_settings *settings, const char *data, size_t len)
Definition http_parser.cpp:641
#define HTTP_ERRNO_MAP(XX)
Definition http_parser.h:236
void http_parser_url_init(struct http_parser_url *u)
Definition http_parser.cpp:2411
#define HTTP_ERRNO_GEN(n, s)
Definition http_parser.h:285
int(* http_data_cb)(http_parser *, const char *at, size_t length)
Definition http_parser.h:88
const char * http_errno_description(enum http_errno err)
Definition http_parser.cpp:2241
http_parser_url_fields
Definition http_parser.h:346
@ UF_FRAGMENT
Definition http_parser.h:351
@ UF_PORT
Definition http_parser.h:348
@ UF_MAX
Definition http_parser.h:353
@ UF_PATH
Definition http_parser.h:349
@ UF_SCHEMA
Definition http_parser.h:346
@ UF_QUERY
Definition http_parser.h:350
@ UF_USERINFO
Definition http_parser.h:352
@ UF_HOST
Definition http_parser.h:347
int(* http_cb)(http_parser *)
Definition http_parser.h:89
http_method
Definition http_parser.h:208
void http_parser_pause(http_parser *parser, int paused)
Definition http_parser.cpp:2539
flags
Definition http_parser.h:220
@ F_CHUNKED
Definition http_parser.h:220
@ F_CONNECTION_CLOSE
Definition http_parser.h:222
@ F_CONNECTION_KEEP_ALIVE
Definition http_parser.h:221
@ F_UPGRADE
Definition http_parser.h:225
@ F_TRANSFER_ENCODING
Definition http_parser.h:228
@ F_CONTENTLENGTH
Definition http_parser.h:227
@ F_TRAILING
Definition http_parser.h:224
@ F_SKIPBODY
Definition http_parser.h:226
@ F_CONNECTION_UPGRADE
Definition http_parser.h:223
const char * http_method_str(enum http_method m)
Definition http_parser.cpp:2201
http_status
Definition http_parser.h:155
int http_should_keep_alive(const http_parser *parser)
Definition http_parser.cpp:2182
void http_parser_set_max_header_size(uint32_t size)
Definition http_parser.cpp:2566
#define HTTP_STATUS_MAP(XX)
Definition http_parser.h:93
const char * http_errno_name(enum http_errno err)
Definition http_parser.cpp:2235
int http_parser_parse_url(const char *buf, size_t buflen, int is_connect, struct http_parser_url *u)
Definition http_parser.cpp:2416
int http_body_is_final(const http_parser *parser)
http_parser_type
Definition http_parser.h:215
@ HTTP_RESPONSE
Definition http_parser.h:215
@ HTTP_REQUEST
Definition http_parser.h:215
@ HTTP_BOTH
Definition http_parser.h:215
Definition http_parser.h:328
http_data_cb on_header_value
Definition http_parser.h:333
http_cb on_chunk_header
Definition http_parser.h:340
http_data_cb on_status
Definition http_parser.h:331
http_cb on_headers_complete
Definition http_parser.h:334
http_data_cb on_url
Definition http_parser.h:330
http_data_cb on_body
Definition http_parser.h:335
http_cb on_chunk_complete
Definition http_parser.h:341
http_cb on_message_begin
Definition http_parser.h:329
http_data_cb on_header_field
Definition http_parser.h:332
http_cb on_message_complete
Definition http_parser.h:336
Definition http_parser.h:364
struct http_parser_url::@1 field_data[UF_MAX]
uint16_t len
Definition http_parser.h:370
uint16_t off
Definition http_parser.h:369
uint16_t field_set
Definition http_parser.h:365
uint16_t port
Definition http_parser.h:366
Definition http_parser.h:296
unsigned int flags
Definition http_parser.h:299
unsigned int state
Definition http_parser.h:300
unsigned int index
Definition http_parser.h:302
unsigned int upgrade
Definition http_parser.h:321
uint32_t nread
Definition http_parser.h:306
unsigned int method
Definition http_parser.h:313
void * data
Definition http_parser.h:324
uint64_t content_length
Definition http_parser.h:307
unsigned int status_code
Definition http_parser.h:312
unsigned int http_errno
Definition http_parser.h:314
unsigned int header_state
Definition http_parser.h:301
unsigned int type
Definition http_parser.h:298
unsigned short http_major
Definition http_parser.h:310
unsigned int lenient_http_headers
Definition http_parser.h:304
unsigned int extra_flags
Definition http_parser.h:303
unsigned short http_minor
Definition http_parser.h:311