47 #define HTTP_PARSER_VERSION_MAJOR 2
48 #define HTTP_PARSER_VERSION_MINOR 7
49 #define HTTP_PARSER_VERSION_PATCH 1
52 #if defined(_WIN32) && !defined(__MINGW32__) && \
53 (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__)
55 typedef __int8 int8_t;
56 typedef unsigned __int8
uint8_t;
57 typedef __int16 int16_t;
58 typedef unsigned __int16 uint16_t;
59 typedef __int32 int32_t;
61 typedef __int64 int64_t;
62 typedef unsigned __int64 uint64_t;
70 #ifndef HTTP_PARSER_STRICT
71 # define HTTP_PARSER_STRICT 0
81 #ifndef HTTP_MAX_HEADER_SIZE
82 # define HTTP_MAX_HEADER_SIZE (80*1024)
112 #define HTTP_STATUS_MAP(XX) \
113 XX(100, CONTINUE, Continue) \
114 XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \
115 XX(102, PROCESSING, Processing) \
117 XX(201, CREATED, Created) \
118 XX(202, ACCEPTED, Accepted) \
119 XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \
120 XX(204, NO_CONTENT, No Content) \
121 XX(205, RESET_CONTENT, Reset Content) \
122 XX(206, PARTIAL_CONTENT, Partial Content) \
123 XX(207, MULTI_STATUS, Multi-Status) \
124 XX(208, ALREADY_REPORTED, Already Reported) \
125 XX(226, IM_USED, IM Used) \
126 XX(300, MULTIPLE_CHOICES, Multiple Choices) \
127 XX(301, MOVED_PERMANENTLY, Moved Permanently) \
128 XX(302, FOUND, Found) \
129 XX(303, SEE_OTHER, See Other) \
130 XX(304, NOT_MODIFIED, Not Modified) \
131 XX(305, USE_PROXY, Use Proxy) \
132 XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \
133 XX(308, PERMANENT_REDIRECT, Permanent Redirect) \
134 XX(400, BAD_REQUEST, Bad Request) \
135 XX(401, UNAUTHORIZED, Unauthorized) \
136 XX(402, PAYMENT_REQUIRED, Payment Required) \
137 XX(403, FORBIDDEN, Forbidden) \
138 XX(404, NOT_FOUND, Not Found) \
139 XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \
140 XX(406, NOT_ACCEPTABLE, Not Acceptable) \
141 XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \
142 XX(408, REQUEST_TIMEOUT, Request Timeout) \
143 XX(409, CONFLICT, Conflict) \
144 XX(410, GONE, Gone) \
145 XX(411, LENGTH_REQUIRED, Length Required) \
146 XX(412, PRECONDITION_FAILED, Precondition Failed) \
147 XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \
148 XX(414, URI_TOO_LONG, URI Too Long) \
149 XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \
150 XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \
151 XX(417, EXPECTATION_FAILED, Expectation Failed) \
152 XX(421, MISDIRECTED_REQUEST, Misdirected Request) \
153 XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \
154 XX(423, LOCKED, Locked) \
155 XX(424, FAILED_DEPENDENCY, Failed Dependency) \
156 XX(426, UPGRADE_REQUIRED, Upgrade Required) \
157 XX(428, PRECONDITION_REQUIRED, Precondition Required) \
158 XX(429, TOO_MANY_REQUESTS, Too Many Requests) \
159 XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
160 XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \
161 XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \
162 XX(501, NOT_IMPLEMENTED, Not Implemented) \
163 XX(502, BAD_GATEWAY, Bad Gateway) \
164 XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \
165 XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \
166 XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \
167 XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \
168 XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \
169 XX(508, LOOP_DETECTED, Loop Detected) \
170 XX(510, NOT_EXTENDED, Not Extended) \
171 XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
175 #define XX(num, name, string) HTTP_STATUS_##name = num,
182 #define HTTP_METHOD_MAP(XX) \
183 XX(0, DELETE, DELETE) \
189 XX(5, CONNECT, CONNECT) \
190 XX(6, OPTIONS, OPTIONS) \
191 XX(7, TRACE, TRACE) \
195 XX(10, MKCOL, MKCOL) \
197 XX(12, PROPFIND, PROPFIND) \
198 XX(13, PROPPATCH, PROPPATCH) \
199 XX(14, SEARCH, SEARCH) \
200 XX(15, UNLOCK, UNLOCK) \
202 XX(17, REBIND, REBIND) \
203 XX(18, UNBIND, UNBIND) \
206 XX(20, REPORT, REPORT) \
207 XX(21, MKACTIVITY, MKACTIVITY) \
208 XX(22, CHECKOUT, CHECKOUT) \
209 XX(23, MERGE, MERGE) \
211 XX(24, MSEARCH, M-SEARCH) \
212 XX(25, NOTIFY, NOTIFY) \
213 XX(26, SUBSCRIBE, SUBSCRIBE) \
214 XX(27, UNSUBSCRIBE, UNSUBSCRIBE) \
216 XX(28, PATCH, PATCH) \
217 XX(29, PURGE, PURGE) \
219 XX(30, MKCALENDAR, MKCALENDAR) \
222 XX(32, UNLINK, UNLINK) \
226 #define XX(num, name, string) HTTP_##name = num,
252 #define HTTP_ERRNO_MAP(XX) \
257 XX(CB_message_begin, "the on_message_begin callback failed") \
258 XX(CB_url, "the on_url callback failed") \
259 XX(CB_header_field, "the on_header_field callback failed") \
260 XX(CB_header_value, "the on_header_value callback failed") \
261 XX(CB_headers_complete, "the on_headers_complete callback failed") \
262 XX(CB_body, "the on_body callback failed") \
263 XX(CB_message_complete, "the on_message_complete callback failed") \
264 XX(CB_status, "the on_status callback failed") \
265 XX(CB_chunk_header, "the on_chunk_header callback failed") \
266 XX(CB_chunk_complete, "the on_chunk_complete callback failed") \
269 XX(INVALID_EOF_STATE, "stream ended at an unexpected time") \
270 XX(HEADER_OVERFLOW, \
271 "too many header bytes seen; overflow detected") \
272 XX(CLOSED_CONNECTION, \
273 "data received after completed connection: close message") \
274 XX(INVALID_VERSION, "invalid HTTP version") \
275 XX(INVALID_STATUS, "invalid HTTP status code") \
276 XX(INVALID_METHOD, "invalid HTTP method") \
277 XX(INVALID_URL, "invalid URL") \
278 XX(INVALID_HOST, "invalid host") \
279 XX(INVALID_PORT, "invalid port") \
280 XX(INVALID_PATH, "invalid path") \
281 XX(INVALID_QUERY_STRING, "invalid query string") \
282 XX(INVALID_FRAGMENT, "invalid fragment") \
283 XX(LF_EXPECTED, "LF character expected") \
284 XX(INVALID_HEADER_TOKEN, "invalid character in header") \
285 XX(INVALID_CONTENT_LENGTH, \
286 "invalid character in content-length header") \
287 XX(UNEXPECTED_CONTENT_LENGTH, \
288 "unexpected content-length header") \
289 XX(INVALID_CHUNK_SIZE, \
290 "invalid character in chunk size header") \
291 XX(INVALID_CONSTANT, "invalid constant string") \
292 XX(INVALID_INTERNAL_STATE, "encountered unexpected internal state")\
293 XX(STRICT, "strict mode assertion failed") \
294 XX(PAUSED, "parser is paused") \
295 XX(UNKNOWN, "an unknown error occurred")
299 #define HTTP_ERRNO_GEN(n, s) HPE_##n,
303 #undef HTTP_ERRNO_GEN
307 #define HTTP_PARSER_ERRNO(p) ((enum http_errno) (p)->http_errno)
#define HTTP_ERRNO_MAP(XX)
http_data_cb on_header_field
http_cb on_headers_complete
unsigned short http_minor
const char * http_method_str(enum http_method m)
#define HTTP_METHOD_MAP(XX)
void http_parser_pause(http_parser *parser, int paused)
unsigned int header_state
int(* http_cb)(http_parser *)
#define XX(num, name, string)
int(* http_data_cb)(http_parser *, const char *at, size_t length)
unsigned int lenient_http_headers
size_t http_parser_execute(http_parser *parser, const http_parser_settings *settings, const char *data, size_t len)
unsigned short http_major
READ-ONLY.
#define HTTP_STATUS_MAP(XX)
int http_parser_parse_url(const char *buf, size_t buflen, int is_connect, struct http_parser_url *u)
http_data_cb on_header_value
void http_parser_settings_init(http_parser_settings *settings)
#define HTTP_ERRNO_GEN(n, s)
void http_parser_url_init(struct http_parser_url *u)
http_cb on_chunk_complete
const char * http_errno_name(enum http_errno err)
int http_should_keep_alive(const http_parser *parser)
const char * http_errno_description(enum http_errno err)
int http_body_is_final(const http_parser *parser)
struct http_parser_url::@1 field_data[UF_MAX]
unsigned int type
PRIVATE.
http_cb on_message_complete
void http_parser_init(http_parser *parser, enum http_parser_type type)
unsigned long http_parser_version(void)