@@ -61,33 +61,41 @@ checks could be performed to get even stricter verification of the llhttp.
6161## Usage
6262
6363``` C
64+ #include " stdio.h"
6465#include " llhttp.h"
66+ #include " string.h"
6567
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;
6876
69- /* Initialize user callbacks and settings */
70- llhttp_settings_init (&settings);
77+ /* Initialize user callbacks and settings */
78+ llhttp_settings_init(&settings);
7179
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;
7482
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);
8088
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);
8492
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+ }
9199}
92100```
93101For more information on API usage, please refer to [src/native/api.h](https://github.com/nodejs/llhttp/blob/main/src/native/api.h).
0 commit comments