Skip to content

Commit 8787895

Browse files
committed
release: 2.2.1
1 parent f1329d6 commit 8787895

4 files changed

Lines changed: 440 additions & 577 deletions

File tree

include/llhttp.h

Lines changed: 6 additions & 30 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 3
5-
#define LLHTTP_VERSION_MINOR 0
4+
#define LLHTTP_VERSION_MAJOR 2
5+
#define LLHTTP_VERSION_MINOR 2
66
#define LLHTTP_VERSION_PATCH 1
77

88
#ifndef LLHTTP_STRICT_MODE
@@ -33,11 +33,10 @@ struct llhttp__internal_s {
3333
uint8_t http_major;
3434
uint8_t http_minor;
3535
uint8_t header_state;
36-
uint8_t lenient_flags;
37-
uint8_t upgrade;
38-
uint8_t finish;
3936
uint16_t flags;
37+
uint8_t upgrade;
4038
uint16_t status_code;
39+
uint8_t finish;
4140
void* settings;
4241
};
4342

@@ -92,16 +91,11 @@ enum llhttp_flags {
9291
F_CONTENT_LENGTH = 0x20,
9392
F_SKIPBODY = 0x40,
9493
F_TRAILING = 0x80,
94+
F_LENIENT = 0x100,
9595
F_TRANSFER_ENCODING = 0x200
9696
};
9797
typedef enum llhttp_flags llhttp_flags_t;
9898

99-
enum llhttp_lenient_flags {
100-
LENIENT_HEADERS = 0x1,
101-
LENIENT_CHUNKED_LENGTH = 0x2
102-
};
103-
typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
104-
10599
enum llhttp_type {
106100
HTTP_BOTH = 0,
107101
HTTP_REQUEST = 1,
@@ -292,11 +286,6 @@ struct llhttp_settings_s {
292286
*/
293287
llhttp_cb on_chunk_header;
294288
llhttp_cb on_chunk_complete;
295-
296-
llhttp_cb on_url_complete;
297-
llhttp_cb on_status_complete;
298-
llhttp_cb on_header_field_complete;
299-
llhttp_cb on_header_value_complete;
300289
};
301290

302291
/* Initialize the parser with specific type and user settings.
@@ -411,20 +400,7 @@ const char* llhttp_method_name(llhttp_method_t method);
411400
*
412401
* **(USE AT YOUR OWN RISK)**
413402
*/
414-
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
415-
416-
417-
/* Enables/disables lenient handling of conflicting `Transfer-Encoding` and
418-
* `Content-Length` headers (disabled by default).
419-
*
420-
* Normally `llhttp` would error when `Transfer-Encoding` is present in
421-
* conjunction with `Content-Length`. This error is important to prevent HTTP
422-
* request smuggling, but may be less desirable for small number of cases
423-
* involving legacy servers.
424-
*
425-
* **(USE AT YOUR OWN RISK)**
426-
*/
427-
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
403+
void llhttp_set_lenient(llhttp_t* parser, int enabled);
428404

429405
#ifdef __cplusplus
430406
} /* extern "C" */

src/api.c

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,11 @@ const char* llhttp_method_name(llhttp_method_t method) {
127127
}
128128

129129

130-
void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
130+
void llhttp_set_lenient(llhttp_t* parser, int enabled) {
131131
if (enabled) {
132-
parser->lenient_flags |= LENIENT_HEADERS;
132+
parser->flags |= F_LENIENT;
133133
} else {
134-
parser->lenient_flags &= ~LENIENT_HEADERS;
135-
}
136-
}
137-
138-
void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
139-
if (enabled) {
140-
parser->lenient_flags |= LENIENT_CHUNKED_LENGTH;
141-
} else {
142-
parser->lenient_flags &= ~LENIENT_CHUNKED_LENGTH;
134+
parser->flags &= ~F_LENIENT;
143135
}
144136
}
145137

@@ -161,55 +153,27 @@ int llhttp__on_url(llhttp_t* s, const char* p, const char* endp) {
161153
}
162154

163155

164-
int llhttp__on_url_complete(llhttp_t* s, const char* p, const char* endp) {
165-
int err;
166-
CALLBACK_MAYBE(s, on_url_complete, s);
167-
return err;
168-
}
169-
170-
171156
int llhttp__on_status(llhttp_t* s, const char* p, const char* endp) {
172157
int err;
173158
CALLBACK_MAYBE(s, on_status, s, p, endp - p);
174159
return err;
175160
}
176161

177162

178-
int llhttp__on_status_complete(llhttp_t* s, const char* p, const char* endp) {
179-
int err;
180-
CALLBACK_MAYBE(s, on_status_complete, s);
181-
return err;
182-
}
183-
184-
185163
int llhttp__on_header_field(llhttp_t* s, const char* p, const char* endp) {
186164
int err;
187165
CALLBACK_MAYBE(s, on_header_field, s, p, endp - p);
188166
return err;
189167
}
190168

191169

192-
int llhttp__on_header_field_complete(llhttp_t* s, const char* p, const char* endp) {
193-
int err;
194-
CALLBACK_MAYBE(s, on_header_field_complete, s);
195-
return err;
196-
}
197-
198-
199170
int llhttp__on_header_value(llhttp_t* s, const char* p, const char* endp) {
200171
int err;
201172
CALLBACK_MAYBE(s, on_header_value, s, p, endp - p);
202173
return err;
203174
}
204175

205176

206-
int llhttp__on_header_value_complete(llhttp_t* s, const char* p, const char* endp) {
207-
int err;
208-
CALLBACK_MAYBE(s, on_header_value_complete, s);
209-
return err;
210-
}
211-
212-
213177
int llhttp__on_headers_complete(llhttp_t* s, const char* p, const char* endp) {
214178
int err;
215179
CALLBACK_MAYBE(s, on_headers_complete, s);

src/http.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ int llhttp__after_headers_complete(llhttp_t* parser, const char* p,
5151
/* chunked encoding - ignore Content-Length header, prepare for a chunk */
5252
return 2;
5353
} else if (parser->flags & F_TRANSFER_ENCODING) {
54-
if (parser->type == HTTP_REQUEST &&
55-
(parser->lenient_flags & LENIENT_CHUNKED_LENGTH) == 0) {
54+
if (parser->type == HTTP_REQUEST && (parser->flags & F_LENIENT) == 0) {
5655
/* RFC 7230 3.3.3 */
5756

5857
/* If a Transfer-Encoding header field
@@ -98,7 +97,9 @@ int llhttp__after_message_complete(llhttp_t* parser, const char* p,
9897

9998
should_keep_alive = llhttp_should_keep_alive(parser);
10099
parser->finish = HTTP_FINISH_SAFE;
101-
parser->flags = 0;
100+
101+
/* Keep `F_LENIENT` flag between messages, but reset every other flag */
102+
parser->flags &= F_LENIENT;
102103

103104
/* NOTE: this is ignored in loose parsing mode */
104105
return should_keep_alive;

0 commit comments

Comments
 (0)