@@ -61,33 +61,41 @@ checks could be performed to get even stricter verification of the llhttp.
61
61
## Usage
62
62
63
63
``` C
64
+ #include " stdio.h"
64
65
#include " llhttp.h"
66
+ #include " string.h"
65
67
66
- llhttp_t parser;
67
- llhttp_settings_t settings;
68
+ int handle_on_message_complete (llhttp_t* parser) {
69
+ fprintf(stdout, "Message completed!\n");
70
+ return 0;
71
+ }
72
+
73
+ int main() {
74
+ llhttp_t parser;
75
+ llhttp_settings_t settings;
68
76
69
- /* Initialize user callbacks and settings */
70
- llhttp_settings_init (&settings);
77
+ /* Initialize user callbacks and settings */
78
+ llhttp_settings_init(&settings);
71
79
72
- / * Set user callback * /
73
- settings.on_message_complete = handle_on_message_complete;
80
+ /* Set user callback */
81
+ settings.on_message_complete = handle_on_message_complete;
74
82
75
- / * Initialize the parser in HTTP_BOTH mode, meaning that it will select between
76
- * HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first
77
- * input.
78
- * /
79
- llhttp_init(&parser, HTTP_BOTH, &settings);
83
+ /* Initialize the parser in HTTP_BOTH mode, meaning that it will select between
84
+ * HTTP_REQUEST and HTTP_RESPONSE parsing automatically while reading the first
85
+ * input.
86
+ */
87
+ llhttp_init(&parser, HTTP_BOTH, &settings);
80
88
81
- / * Parse request! * /
82
- const char* request = "GET / HTTP/1.1\r\n\r\n";
83
- int request_len = strlen(request);
89
+ /* Parse request! */
90
+ const char* request = "GET / HTTP/1.1\r\n\r\n";
91
+ int request_len = strlen(request);
84
92
85
- enum llhttp_errno err = llhttp_execute(&parser, request, request_len);
86
- if (err == HPE_OK) {
87
- / * Successfully parsed! * /
88
- } else {
89
- fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err),
90
- parser.reason);
93
+ enum llhttp_errno err = llhttp_execute(&parser, request, request_len);
94
+ if (err == HPE_OK) {
95
+ fprintf(stdout, " Successfully parsed!\n");
96
+ } else {
97
+ fprintf(stderr, "Parse error: %s %s\n", llhttp_errno_name(err), parser.reason);
98
+ }
91
99
}
92
100
```
93
101
For more information on API usage, please refer to [src/native/api.h](https://github.com/nodejs/llhttp/blob/main/src/native/api.h).
@@ -279,7 +287,7 @@ protocol support to highly non-compliant clients/server.
279
287
No `HPE_INVALID_HEADER_TOKEN` will be raised for incorrect header values when
280
288
lenient parsing is "on".
281
289
282
- **USE AT YOUR OWN RISK !**
290
+ **Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION !**
283
291
284
292
### `void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled)`
285
293
@@ -292,23 +300,22 @@ conjunction with `Content-Length`.
292
300
This error is important to prevent HTTP request smuggling, but may be less desirable
293
301
for small number of cases involving legacy servers.
294
302
295
- **USE AT YOUR OWN RISK !**
303
+ **Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION !**
296
304
297
305
### `void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled)`
298
306
299
307
Enables/disables lenient handling of `Connection: close` and HTTP/1.0
300
308
requests responses.
301
309
302
- Normally `llhttp` would error on (in strict mode) or discard (in loose mode)
303
- the HTTP request/response after the request/response with `Connection: close`
304
- and `Content-Length`.
310
+ Normally `llhttp` would error the HTTP request/response
311
+ after the request/response with `Connection: close` and `Content-Length`.
305
312
306
313
This is important to prevent cache poisoning attacks,
307
314
but might interact badly with outdated and insecure clients.
308
315
309
316
With this flag the extra request/response will be parsed normally.
310
317
311
- **USE AT YOUR OWN RISK !**
318
+ **Enabling this flag can pose a security issue since you will be exposed to poisoning attacks. USE WITH CAUTION !**
312
319
313
320
### `void llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled)`
314
321
@@ -323,7 +330,48 @@ avoid request smuggling.
323
330
324
331
With this flag the extra value will be parsed normally.
325
332
326
- **USE AT YOUR OWN RISK!**
333
+ **Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
334
+
335
+ ### `void llhttp_set_lenient_version(llhttp_t* parser, int enabled)`
336
+
337
+ Enables/disables lenient handling of HTTP version.
338
+
339
+ Normally `llhttp` would error when the HTTP version in the request or status line
340
+ is not `0.9`, `1.0`, `1.1` or `2.0`.
341
+ With this flag the extra value will be parsed normally.
342
+
343
+ **Enabling this flag can pose a security issue since you will allow unsupported HTTP versions. USE WITH CAUTION!**
344
+
345
+ ### `void llhttp_set_lenient_data_after_close(llhttp_t* parser, int enabled)`
346
+
347
+ Enables/disables lenient handling of additional data received after a message ends
348
+ and keep-alive is disabled.
349
+
350
+ Normally `llhttp` would error when additional unexpected data is received if the message
351
+ contains the `Connection` header with `close` value.
352
+ With this flag the extra data will discarded without throwing an error.
353
+
354
+ **Enabling this flag can pose a security issue since you will be exposed to poisoning attacks. USE WITH CAUTION!**
355
+
356
+ ### `void llhttp_set_lenient_optional_lf_after_cr(llhttp_t* parser, int enabled)`
357
+
358
+ Enables/disables lenient handling of incomplete CRLF sequences.
359
+
360
+ Normally `llhttp` would error when a CR is not followed by LF when terminating the
361
+ request line, the status line, the headers or a chunk header.
362
+ With this flag only a CR is required to terminate such sections.
363
+
364
+ **Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
365
+
366
+ ### `void llhttp_set_lenient_optional_crlf_after_chunk(llhttp_t* parser, int enabled)`
367
+
368
+ Enables/disables lenient handling of chunks not separated via CRLF.
369
+
370
+ Normally `llhttp` would error when after a chunk data a CRLF is missing before
371
+ starting a new chunk.
372
+ With this flag the new chunk can start immediately after the previous one.
373
+
374
+ **Enabling this flag can pose a security issue since you will be exposed to request smuggling attacks. USE WITH CAUTION!**
327
375
328
376
## Build Instructions
329
377
@@ -345,17 +393,34 @@ make
345
393
346
394
### Using with CMake
347
395
348
- If you want to use this library in a CMake project you can use the snippet below.
396
+ If you want to use this library in a CMake project as a shared library, you can use the snippet below.
397
+
398
+ ```
399
+ FetchContent_Declare(llhttp
400
+ URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0.tar.gz")
401
+
402
+ FetchContent_MakeAvailable(llhttp)
403
+
404
+ # Link with the llhttp_shared target
405
+ target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp_shared ${PROJECT_NAME})
406
+ ```
407
+
408
+ If you want to use this library in a CMake project as a static library, you can set some cache variables first.
349
409
350
410
```
351
411
FetchContent_Declare(llhttp
352
- URL "https://github.com/nodejs/llhttp/archive/refs/tags/v6.0.5. tar.gz") # Using version 6.0.5
412
+ URL "https://github.com/nodejs/llhttp/archive/refs/tags/release/v8.1.0. tar.gz")
353
413
414
+ set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
415
+ set(BUILD_STATIC_LIBS ON CACHE INTERNAL "")
354
416
FetchContent_MakeAvailable(llhttp)
355
417
356
- target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp ${PROJECT_NAME})
418
+ # Link with the llhttp_static target
419
+ target_link_libraries(${EXAMPLE_PROJECT_NAME} ${PROJECT_LIBRARIES} llhttp_static ${PROJECT_NAME})
357
420
```
358
421
422
+ _ Note that using the git repo directly (e.g., via a git repo url and tag) will not work with FetchContent_Declare because [ CMakeLists.txt] ( ./CMakeLists.txt ) requires string replacements (e.g., ` _RELEASE_ ` ) before it will build._
423
+
359
424
## Building on Windows
360
425
361
426
### Installation
0 commit comments