11#ifndef INCLUDE_LLHTTP_H_
22#define INCLUDE_LLHTTP_H_
33
4- #define LLHTTP_VERSION_MAJOR 5
5- #define LLHTTP_VERSION_MINOR 0
4+ #define LLHTTP_VERSION_MAJOR 4
5+ #define LLHTTP_VERSION_MINOR 1
66#define LLHTTP_VERSION_PATCH 0
77
88#ifndef LLHTTP_STRICT_MODE
@@ -79,7 +79,8 @@ enum llhttp_errno {
7979 HPE_CB_CHUNK_COMPLETE = 20 ,
8080 HPE_PAUSED = 21 ,
8181 HPE_PAUSED_UPGRADE = 22 ,
82- HPE_USER = 23
82+ HPE_PAUSED_H2_UPGRADE = 23 ,
83+ HPE_USER = 24
8384};
8485typedef enum llhttp_errno llhttp_errno_t ;
8586
@@ -98,8 +99,7 @@ typedef enum llhttp_flags llhttp_flags_t;
9899
99100enum llhttp_lenient_flags {
100101 LENIENT_HEADERS = 0x1 ,
101- LENIENT_CHUNKED_LENGTH = 0x2 ,
102- LENIENT_KEEP_ALIVE = 0x4
102+ LENIENT_CHUNKED_LENGTH = 0x2
103103};
104104typedef enum llhttp_lenient_flags llhttp_lenient_flags_t ;
105105
@@ -191,7 +191,8 @@ typedef enum llhttp_method llhttp_method_t;
191191 XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
192192 XX(21, PAUSED, PAUSED) \
193193 XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
194- XX(23, USER, USER) \
194+ XX(23, PAUSED_H2_UPGRADE, PAUSED_H2_UPGRADE) \
195+ XX(24, USER, USER) \
195196
196197
197198#define HTTP_METHOD_MAP (XX ) \
@@ -256,12 +257,6 @@ extern "C" {
256257#endif
257258#include <stddef.h>
258259
259- #if defined(__wasm__ )
260- #define LLHTTP_EXPORT __attribute__((visibility("default")))
261- #else
262- #define LLHTTP_EXPORT
263- #endif
264-
265260typedef llhttp__internal_t llhttp_t ;
266261typedef struct llhttp_settings_s llhttp_settings_t ;
267262
@@ -312,46 +307,15 @@ struct llhttp_settings_s {
312307 * the `parser` here. In practice, `settings` has to be either a static
313308 * variable or be allocated with `malloc`, `new`, etc.
314309 */
315- LLHTTP_EXPORT
316310void llhttp_init (llhttp_t * parser , llhttp_type_t type ,
317311 const llhttp_settings_t * settings );
318312
319- #if defined(__wasm__ )
320-
321- LLHTTP_EXPORT
322- llhttp_t * llhttp_alloc (llhttp_type_t type );
323-
324- LLHTTP_EXPORT
325- void llhttp_free (llhttp_t * parser );
326-
327- LLHTTP_EXPORT
328- uint8_t llhttp_get_type (llhttp_t * parser );
329-
330- LLHTTP_EXPORT
331- uint8_t llhttp_get_http_major (llhttp_t * parser );
332-
333- LLHTTP_EXPORT
334- uint8_t llhttp_get_http_minor (llhttp_t * parser );
335-
336- LLHTTP_EXPORT
337- uint8_t llhttp_get_method (llhttp_t * parser );
338-
339- LLHTTP_EXPORT
340- int llhttp_get_status_code (llhttp_t * parser );
341-
342- LLHTTP_EXPORT
343- uint8_t llhttp_get_upgrade (llhttp_t * parser );
344-
345- #endif // defined(__wasm__)
346-
347313/* Reset an already initialized parser back to the start state, preserving the
348314 * existing parser type, callback settings, user data, and lenient flags.
349315 */
350- LLHTTP_EXPORT
351316void llhttp_reset (llhttp_t * parser );
352317
353318/* Initialize the settings object */
354- LLHTTP_EXPORT
355319void llhttp_settings_init (llhttp_settings_t * settings );
356320
357321/* Parse full or partial request/response, invoking user callbacks along the
@@ -370,7 +334,6 @@ void llhttp_settings_init(llhttp_settings_t* settings);
370334 * to return the same error upon each successive call up until `llhttp_init()`
371335 * is called.
372336 */
373- LLHTTP_EXPORT
374337llhttp_errno_t llhttp_execute (llhttp_t * parser , const char * data , size_t len );
375338
376339/* This method should be called when the other side has no further bytes to
@@ -381,19 +344,16 @@ llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
381344 * connection. This method will invoke `on_message_complete()` callback if the
382345 * request was terminated safely. Otherwise a error code would be returned.
383346 */
384- LLHTTP_EXPORT
385347llhttp_errno_t llhttp_finish (llhttp_t * parser );
386348
387349/* Returns `1` if the incoming message is parsed until the last byte, and has
388350 * to be completed by calling `llhttp_finish()` on EOF
389351 */
390- LLHTTP_EXPORT
391352int llhttp_message_needs_eof (const llhttp_t * parser );
392353
393354/* Returns `1` if there might be any other messages following the last that was
394355 * successfully parsed.
395356 */
396- LLHTTP_EXPORT
397357int llhttp_should_keep_alive (const llhttp_t * parser );
398358
399359/* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
@@ -402,59 +362,50 @@ int llhttp_should_keep_alive(const llhttp_t* parser);
402362 * Important: do not call this from user callbacks! User callbacks must return
403363 * `HPE_PAUSED` if pausing is required.
404364 */
405- LLHTTP_EXPORT
406365void llhttp_pause (llhttp_t * parser );
407366
408367/* Might be called to resume the execution after the pause in user's callback.
409368 * See `llhttp_execute()` above for details.
410369 *
411370 * Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
412371 */
413- LLHTTP_EXPORT
414372void llhttp_resume (llhttp_t * parser );
415373
416374/* Might be called to resume the execution after the pause in user's callback.
417375 * See `llhttp_execute()` above for details.
418376 *
419377 * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
420378 */
421- LLHTTP_EXPORT
422379void llhttp_resume_after_upgrade (llhttp_t * parser );
423380
424381/* Returns the latest return error */
425- LLHTTP_EXPORT
426382llhttp_errno_t llhttp_get_errno (const llhttp_t * parser );
427383
428384/* Returns the verbal explanation of the latest returned error.
429385 *
430386 * Note: User callback should set error reason when returning the error. See
431387 * `llhttp_set_error_reason()` for details.
432388 */
433- LLHTTP_EXPORT
434389const char * llhttp_get_error_reason (const llhttp_t * parser );
435390
436391/* Assign verbal description to the returned error. Must be called in user
437392 * callbacks right before returning the errno.
438393 *
439394 * Note: `HPE_USER` error code might be useful in user callbacks.
440395 */
441- LLHTTP_EXPORT
442396void llhttp_set_error_reason (llhttp_t * parser , const char * reason );
443397
444398/* Returns the pointer to the last parsed byte before the returned error. The
445399 * pointer is relative to the `data` argument of `llhttp_execute()`.
446400 *
447401 * Note: this method might be useful for counting the number of parsed bytes.
448402 */
449- LLHTTP_EXPORT
450403const char * llhttp_get_error_pos (const llhttp_t * parser );
451404
452405/* Returns textual name of error code */
453- LLHTTP_EXPORT
454406const char * llhttp_errno_name (llhttp_errno_t err );
455407
456408/* Returns textual name of HTTP method */
457- LLHTTP_EXPORT
458409const char * llhttp_method_name (llhttp_method_t method );
459410
460411
@@ -467,7 +418,6 @@ const char* llhttp_method_name(llhttp_method_t method);
467418 *
468419 * **(USE AT YOUR OWN RISK)**
469420 */
470- LLHTTP_EXPORT
471421void llhttp_set_lenient_headers (llhttp_t * parser , int enabled );
472422
473423
@@ -481,23 +431,8 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
481431 *
482432 * **(USE AT YOUR OWN RISK)**
483433 */
484- LLHTTP_EXPORT
485434void llhttp_set_lenient_chunked_length (llhttp_t * parser , int enabled );
486435
487-
488- /* Enables/disables lenient handling of `Connection: close` and HTTP/1.0
489- * requests responses.
490- *
491- * Normally `llhttp` would error on (in strict mode) or discard (in loose mode)
492- * the HTTP request/response after the request/response with `Connection: close`
493- * and `Content-Length`. This is important to prevent cache poisoning attacks,
494- * but might interact badly with outdated and insecure clients. With this flag
495- * the extra request/response will be parsed normally.
496- *
497- * **(USE AT YOUR OWN RISK)**
498- */
499- void llhttp_set_lenient_keep_alive (llhttp_t * parser , int enabled );
500-
501436#ifdef __cplusplus
502437} /* extern "C" */
503438#endif
0 commit comments