Skip to content

Commit a74a904

Browse files
committed
release: 4.1.0
1 parent 7e2c65d commit a74a904

3 files changed

Lines changed: 31 additions & 224 deletions

File tree

include/llhttp.h

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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
};
8485
typedef enum llhttp_errno llhttp_errno_t;
8586

@@ -98,8 +99,7 @@ typedef enum llhttp_flags llhttp_flags_t;
9899

99100
enum llhttp_lenient_flags {
100101
LENIENT_HEADERS = 0x1,
101-
LENIENT_CHUNKED_LENGTH = 0x2,
102-
LENIENT_KEEP_ALIVE = 0x4
102+
LENIENT_CHUNKED_LENGTH = 0x2
103103
};
104104
typedef 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-
265260
typedef llhttp__internal_t llhttp_t;
266261
typedef 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
316310
void 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
351316
void llhttp_reset(llhttp_t* parser);
352317

353318
/* Initialize the settings object */
354-
LLHTTP_EXPORT
355319
void 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
374337
llhttp_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
385347
llhttp_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
391352
int 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
397357
int 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
406365
void 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
414372
void 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
422379
void llhttp_resume_after_upgrade(llhttp_t* parser);
423380

424381
/* Returns the latest return error */
425-
LLHTTP_EXPORT
426382
llhttp_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
434389
const 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
442396
void 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
450403
const char* llhttp_get_error_pos(const llhttp_t* parser);
451404

452405
/* Returns textual name of error code */
453-
LLHTTP_EXPORT
454406
const char* llhttp_errno_name(llhttp_errno_t err);
455407

456408
/* Returns textual name of HTTP method */
457-
LLHTTP_EXPORT
458409
const 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
471421
void 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
485434
void 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

src/api.c

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -24,70 +24,6 @@ void llhttp_init(llhttp_t* parser, llhttp_type_t type,
2424
}
2525

2626

27-
#if defined(__wasm__)
28-
29-
extern int wasm_on_message_begin(llhttp_t * p);
30-
extern int wasm_on_url(llhttp_t* p, const char* at, size_t length);
31-
extern int wasm_on_status(llhttp_t* p, const char* at, size_t length);
32-
extern int wasm_on_header_field(llhttp_t* p, const char* at, size_t length);
33-
extern int wasm_on_header_value(llhttp_t* p, const char* at, size_t length);
34-
extern int wasm_on_headers_complete(llhttp_t * p);
35-
extern int wasm_on_body(llhttp_t* p, const char* at, size_t length);
36-
extern int wasm_on_message_complete(llhttp_t * p);
37-
38-
const llhttp_settings_t wasm_settings = {
39-
wasm_on_message_begin,
40-
wasm_on_url,
41-
wasm_on_status,
42-
wasm_on_header_field,
43-
wasm_on_header_value,
44-
wasm_on_headers_complete,
45-
wasm_on_body,
46-
wasm_on_message_complete,
47-
NULL,
48-
NULL,
49-
};
50-
51-
52-
llhttp_t* llhttp_alloc(llhttp_type_t type) {
53-
llhttp_t* parser = malloc(sizeof(llhttp_t));
54-
llhttp_init(parser, type, &wasm_settings);
55-
return parser;
56-
}
57-
58-
void llhttp_free(llhttp_t* parser) {
59-
free(parser);
60-
}
61-
62-
/* Some getters required to get stuff from the parser */
63-
64-
uint8_t llhttp_get_type(llhttp_t* parser) {
65-
return parser->type;
66-
}
67-
68-
uint8_t llhttp_get_http_major(llhttp_t* parser) {
69-
return parser->http_major;
70-
}
71-
72-
uint8_t llhttp_get_http_minor(llhttp_t* parser) {
73-
return parser->http_minor;
74-
}
75-
76-
uint8_t llhttp_get_method(llhttp_t* parser) {
77-
return parser->method;
78-
}
79-
80-
int llhttp_get_status_code(llhttp_t* parser) {
81-
return parser->status_code;
82-
}
83-
84-
uint8_t llhttp_get_upgrade(llhttp_t* parser) {
85-
return parser->upgrade;
86-
}
87-
88-
#endif // defined(__wasm__)
89-
90-
9127
void llhttp_reset(llhttp_t* parser) {
9228
llhttp_type_t type = parser->type;
9329
const llhttp_settings_t* settings = parser->settings;
@@ -214,7 +150,6 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
214150
}
215151
}
216152

217-
218153
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
219154
if (enabled) {
220155
parser->lenient_flags |= LENIENT_CHUNKED_LENGTH;
@@ -224,14 +159,6 @@ void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
224159
}
225160

226161

227-
void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled) {
228-
if (enabled) {
229-
parser->lenient_flags |= LENIENT_KEEP_ALIVE;
230-
} else {
231-
parser->lenient_flags &= ~LENIENT_KEEP_ALIVE;
232-
}
233-
}
234-
235162
/* Callbacks */
236163

237164

0 commit comments

Comments
 (0)