llhttp-ffi 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/llhttp/llhttp.h CHANGED
@@ -1,32 +1,9 @@
1
- // This software is licensed under the MIT License.
2
-
3
- // Copyright Fedor Indutny, 2018.
4
-
5
- // Permission is hereby granted, free of charge, to any person obtaining a
6
- // copy of this software and associated documentation files (the
7
- // "Software"), to deal in the Software without restriction, including
8
- // without limitation the rights to use, copy, modify, merge, publish,
9
- // distribute, sublicense, and/or sell copies of the Software, and to permit
10
- // persons to whom the Software is furnished to do so, subject to the
11
- // following conditions:
12
-
13
- // The above copyright notice and this permission notice shall be included
14
- // in all copies or substantial portions of the Software.
15
-
16
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
- // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
19
- // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20
- // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21
- // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22
- // USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
24
1
  #ifndef INCLUDE_LLHTTP_H_
25
2
  #define INCLUDE_LLHTTP_H_
26
3
 
27
- #define LLHTTP_VERSION_MAJOR 6
28
- #define LLHTTP_VERSION_MINOR 0
29
- #define LLHTTP_VERSION_PATCH 1
4
+ #define LLHTTP_VERSION_MAJOR 8
5
+ #define LLHTTP_VERSION_MINOR 1
6
+ #define LLHTTP_VERSION_PATCH 0
30
7
 
31
8
  #ifndef LLHTTP_STRICT_MODE
32
9
  # define LLHTTP_STRICT_MODE 0
@@ -61,6 +38,7 @@ struct llhttp__internal_s {
61
38
  uint8_t finish;
62
39
  uint16_t flags;
63
40
  uint16_t status_code;
41
+ uint8_t initial_message_completed;
64
42
  void* settings;
65
43
  };
66
44
 
@@ -82,8 +60,10 @@ enum llhttp_errno {
82
60
  HPE_OK = 0,
83
61
  HPE_INTERNAL = 1,
84
62
  HPE_STRICT = 2,
63
+ HPE_CR_EXPECTED = 25,
85
64
  HPE_LF_EXPECTED = 3,
86
65
  HPE_UNEXPECTED_CONTENT_LENGTH = 4,
66
+ HPE_UNEXPECTED_SPACE = 30,
87
67
  HPE_CLOSED_CONNECTION = 5,
88
68
  HPE_INVALID_METHOD = 6,
89
69
  HPE_INVALID_URL = 7,
@@ -103,7 +83,16 @@ enum llhttp_errno {
103
83
  HPE_PAUSED = 21,
104
84
  HPE_PAUSED_UPGRADE = 22,
105
85
  HPE_PAUSED_H2_UPGRADE = 23,
106
- HPE_USER = 24
86
+ HPE_USER = 24,
87
+ HPE_CB_URL_COMPLETE = 26,
88
+ HPE_CB_STATUS_COMPLETE = 27,
89
+ HPE_CB_METHOD_COMPLETE = 32,
90
+ HPE_CB_VERSION_COMPLETE = 33,
91
+ HPE_CB_HEADER_FIELD_COMPLETE = 28,
92
+ HPE_CB_HEADER_VALUE_COMPLETE = 29,
93
+ HPE_CB_CHUNK_EXTENSION_NAME_COMPLETE = 34,
94
+ HPE_CB_CHUNK_EXTENSION_VALUE_COMPLETE = 35,
95
+ HPE_CB_RESET = 31
107
96
  };
108
97
  typedef enum llhttp_errno llhttp_errno_t;
109
98
 
@@ -123,7 +112,9 @@ typedef enum llhttp_flags llhttp_flags_t;
123
112
  enum llhttp_lenient_flags {
124
113
  LENIENT_HEADERS = 0x1,
125
114
  LENIENT_CHUNKED_LENGTH = 0x2,
126
- LENIENT_KEEP_ALIVE = 0x4
115
+ LENIENT_KEEP_ALIVE = 0x4,
116
+ LENIENT_TRANSFER_ENCODING = 0x8,
117
+ LENIENT_VERSION = 0x10
127
118
  };
128
119
  typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
129
120
 
@@ -191,12 +182,117 @@ enum llhttp_method {
191
182
  };
192
183
  typedef enum llhttp_method llhttp_method_t;
193
184
 
185
+ enum llhttp_status {
186
+ HTTP_STATUS_CONTINUE = 100,
187
+ HTTP_STATUS_SWITCHING_PROTOCOLS = 101,
188
+ HTTP_STATUS_PROCESSING = 102,
189
+ HTTP_STATUS_EARLY_HINTS = 103,
190
+ HTTP_STATUS_RESPONSE_IS_STALE = 110,
191
+ HTTP_STATUS_REVALIDATION_FAILED = 111,
192
+ HTTP_STATUS_DISCONNECTED_OPERATION = 112,
193
+ HTTP_STATUS_HEURISTIC_EXPIRATION = 113,
194
+ HTTP_STATUS_MISCELLANEOUS_WARNING = 199,
195
+ HTTP_STATUS_OK = 200,
196
+ HTTP_STATUS_CREATED = 201,
197
+ HTTP_STATUS_ACCEPTED = 202,
198
+ HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION = 203,
199
+ HTTP_STATUS_NO_CONTENT = 204,
200
+ HTTP_STATUS_RESET_CONTENT = 205,
201
+ HTTP_STATUS_PARTIAL_CONTENT = 206,
202
+ HTTP_STATUS_MULTI_STATUS = 207,
203
+ HTTP_STATUS_ALREADY_REPORTED = 208,
204
+ HTTP_STATUS_TRANSFORMATION_APPLIED = 214,
205
+ HTTP_STATUS_IM_USED = 226,
206
+ HTTP_STATUS_MISCELLANEOUS_PERSISTENT_WARNING = 299,
207
+ HTTP_STATUS_MULTIPLE_CHOICES = 300,
208
+ HTTP_STATUS_MOVED_PERMANENTLY = 301,
209
+ HTTP_STATUS_FOUND = 302,
210
+ HTTP_STATUS_SEE_OTHER = 303,
211
+ HTTP_STATUS_NOT_MODIFIED = 304,
212
+ HTTP_STATUS_USE_PROXY = 305,
213
+ HTTP_STATUS_SWITCH_PROXY = 306,
214
+ HTTP_STATUS_TEMPORARY_REDIRECT = 307,
215
+ HTTP_STATUS_PERMANENT_REDIRECT = 308,
216
+ HTTP_STATUS_BAD_REQUEST = 400,
217
+ HTTP_STATUS_UNAUTHORIZED = 401,
218
+ HTTP_STATUS_PAYMENT_REQUIRED = 402,
219
+ HTTP_STATUS_FORBIDDEN = 403,
220
+ HTTP_STATUS_NOT_FOUND = 404,
221
+ HTTP_STATUS_METHOD_NOT_ALLOWED = 405,
222
+ HTTP_STATUS_NOT_ACCEPTABLE = 406,
223
+ HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED = 407,
224
+ HTTP_STATUS_REQUEST_TIMEOUT = 408,
225
+ HTTP_STATUS_CONFLICT = 409,
226
+ HTTP_STATUS_GONE = 410,
227
+ HTTP_STATUS_LENGTH_REQUIRED = 411,
228
+ HTTP_STATUS_PRECONDITION_FAILED = 412,
229
+ HTTP_STATUS_PAYLOAD_TOO_LARGE = 413,
230
+ HTTP_STATUS_URI_TOO_LONG = 414,
231
+ HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415,
232
+ HTTP_STATUS_RANGE_NOT_SATISFIABLE = 416,
233
+ HTTP_STATUS_EXPECTATION_FAILED = 417,
234
+ HTTP_STATUS_IM_A_TEAPOT = 418,
235
+ HTTP_STATUS_PAGE_EXPIRED = 419,
236
+ HTTP_STATUS_ENHANCE_YOUR_CALM = 420,
237
+ HTTP_STATUS_MISDIRECTED_REQUEST = 421,
238
+ HTTP_STATUS_UNPROCESSABLE_ENTITY = 422,
239
+ HTTP_STATUS_LOCKED = 423,
240
+ HTTP_STATUS_FAILED_DEPENDENCY = 424,
241
+ HTTP_STATUS_TOO_EARLY = 425,
242
+ HTTP_STATUS_UPGRADE_REQUIRED = 426,
243
+ HTTP_STATUS_PRECONDITION_REQUIRED = 428,
244
+ HTTP_STATUS_TOO_MANY_REQUESTS = 429,
245
+ HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL = 430,
246
+ HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
247
+ HTTP_STATUS_LOGIN_TIMEOUT = 440,
248
+ HTTP_STATUS_NO_RESPONSE = 444,
249
+ HTTP_STATUS_RETRY_WITH = 449,
250
+ HTTP_STATUS_BLOCKED_BY_PARENTAL_CONTROL = 450,
251
+ HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS = 451,
252
+ HTTP_STATUS_CLIENT_CLOSED_LOAD_BALANCED_REQUEST = 460,
253
+ HTTP_STATUS_INVALID_X_FORWARDED_FOR = 463,
254
+ HTTP_STATUS_REQUEST_HEADER_TOO_LARGE = 494,
255
+ HTTP_STATUS_SSL_CERTIFICATE_ERROR = 495,
256
+ HTTP_STATUS_SSL_CERTIFICATE_REQUIRED = 496,
257
+ HTTP_STATUS_HTTP_REQUEST_SENT_TO_HTTPS_PORT = 497,
258
+ HTTP_STATUS_INVALID_TOKEN = 498,
259
+ HTTP_STATUS_CLIENT_CLOSED_REQUEST = 499,
260
+ HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
261
+ HTTP_STATUS_NOT_IMPLEMENTED = 501,
262
+ HTTP_STATUS_BAD_GATEWAY = 502,
263
+ HTTP_STATUS_SERVICE_UNAVAILABLE = 503,
264
+ HTTP_STATUS_GATEWAY_TIMEOUT = 504,
265
+ HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED = 505,
266
+ HTTP_STATUS_VARIANT_ALSO_NEGOTIATES = 506,
267
+ HTTP_STATUS_INSUFFICIENT_STORAGE = 507,
268
+ HTTP_STATUS_LOOP_DETECTED = 508,
269
+ HTTP_STATUS_BANDWIDTH_LIMIT_EXCEEDED = 509,
270
+ HTTP_STATUS_NOT_EXTENDED = 510,
271
+ HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED = 511,
272
+ HTTP_STATUS_WEB_SERVER_UNKNOWN_ERROR = 520,
273
+ HTTP_STATUS_WEB_SERVER_IS_DOWN = 521,
274
+ HTTP_STATUS_CONNECTION_TIMEOUT = 522,
275
+ HTTP_STATUS_ORIGIN_IS_UNREACHABLE = 523,
276
+ HTTP_STATUS_TIMEOUT_OCCURED = 524,
277
+ HTTP_STATUS_SSL_HANDSHAKE_FAILED = 525,
278
+ HTTP_STATUS_INVALID_SSL_CERTIFICATE = 526,
279
+ HTTP_STATUS_RAILGUN_ERROR = 527,
280
+ HTTP_STATUS_SITE_IS_OVERLOADED = 529,
281
+ HTTP_STATUS_SITE_IS_FROZEN = 530,
282
+ HTTP_STATUS_IDENTITY_PROVIDER_AUTHENTICATION_ERROR = 561,
283
+ HTTP_STATUS_NETWORK_READ_TIMEOUT = 598,
284
+ HTTP_STATUS_NETWORK_CONNECT_TIMEOUT = 599
285
+ };
286
+ typedef enum llhttp_status llhttp_status_t;
287
+
194
288
  #define HTTP_ERRNO_MAP(XX) \
195
289
  XX(0, OK, OK) \
196
290
  XX(1, INTERNAL, INTERNAL) \
197
291
  XX(2, STRICT, STRICT) \
292
+ XX(25, CR_EXPECTED, CR_EXPECTED) \
198
293
  XX(3, LF_EXPECTED, LF_EXPECTED) \
199
294
  XX(4, UNEXPECTED_CONTENT_LENGTH, UNEXPECTED_CONTENT_LENGTH) \
295
+ XX(30, UNEXPECTED_SPACE, UNEXPECTED_SPACE) \
200
296
  XX(5, CLOSED_CONNECTION, CLOSED_CONNECTION) \
201
297
  XX(6, INVALID_METHOD, INVALID_METHOD) \
202
298
  XX(7, INVALID_URL, INVALID_URL) \
@@ -217,6 +313,15 @@ typedef enum llhttp_method llhttp_method_t;
217
313
  XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
218
314
  XX(23, PAUSED_H2_UPGRADE, PAUSED_H2_UPGRADE) \
219
315
  XX(24, USER, USER) \
316
+ XX(26, CB_URL_COMPLETE, CB_URL_COMPLETE) \
317
+ XX(27, CB_STATUS_COMPLETE, CB_STATUS_COMPLETE) \
318
+ XX(32, CB_METHOD_COMPLETE, CB_METHOD_COMPLETE) \
319
+ XX(33, CB_VERSION_COMPLETE, CB_VERSION_COMPLETE) \
320
+ XX(28, CB_HEADER_FIELD_COMPLETE, CB_HEADER_FIELD_COMPLETE) \
321
+ XX(29, CB_HEADER_VALUE_COMPLETE, CB_HEADER_VALUE_COMPLETE) \
322
+ XX(34, CB_CHUNK_EXTENSION_NAME_COMPLETE, CB_CHUNK_EXTENSION_NAME_COMPLETE) \
323
+ XX(35, CB_CHUNK_EXTENSION_VALUE_COMPLETE, CB_CHUNK_EXTENSION_VALUE_COMPLETE) \
324
+ XX(31, CB_RESET, CB_RESET) \
220
325
 
221
326
 
222
327
  #define HTTP_METHOD_MAP(XX) \
@@ -322,6 +427,108 @@ typedef enum llhttp_method llhttp_method_t;
322
427
  XX(45, FLUSH, FLUSH) \
323
428
 
324
429
 
430
+ #define HTTP_STATUS_MAP(XX) \
431
+ XX(100, CONTINUE, CONTINUE) \
432
+ XX(101, SWITCHING_PROTOCOLS, SWITCHING_PROTOCOLS) \
433
+ XX(102, PROCESSING, PROCESSING) \
434
+ XX(103, EARLY_HINTS, EARLY_HINTS) \
435
+ XX(110, RESPONSE_IS_STALE, RESPONSE_IS_STALE) \
436
+ XX(111, REVALIDATION_FAILED, REVALIDATION_FAILED) \
437
+ XX(112, DISCONNECTED_OPERATION, DISCONNECTED_OPERATION) \
438
+ XX(113, HEURISTIC_EXPIRATION, HEURISTIC_EXPIRATION) \
439
+ XX(199, MISCELLANEOUS_WARNING, MISCELLANEOUS_WARNING) \
440
+ XX(200, OK, OK) \
441
+ XX(201, CREATED, CREATED) \
442
+ XX(202, ACCEPTED, ACCEPTED) \
443
+ XX(203, NON_AUTHORITATIVE_INFORMATION, NON_AUTHORITATIVE_INFORMATION) \
444
+ XX(204, NO_CONTENT, NO_CONTENT) \
445
+ XX(205, RESET_CONTENT, RESET_CONTENT) \
446
+ XX(206, PARTIAL_CONTENT, PARTIAL_CONTENT) \
447
+ XX(207, MULTI_STATUS, MULTI_STATUS) \
448
+ XX(208, ALREADY_REPORTED, ALREADY_REPORTED) \
449
+ XX(214, TRANSFORMATION_APPLIED, TRANSFORMATION_APPLIED) \
450
+ XX(226, IM_USED, IM_USED) \
451
+ XX(299, MISCELLANEOUS_PERSISTENT_WARNING, MISCELLANEOUS_PERSISTENT_WARNING) \
452
+ XX(300, MULTIPLE_CHOICES, MULTIPLE_CHOICES) \
453
+ XX(301, MOVED_PERMANENTLY, MOVED_PERMANENTLY) \
454
+ XX(302, FOUND, FOUND) \
455
+ XX(303, SEE_OTHER, SEE_OTHER) \
456
+ XX(304, NOT_MODIFIED, NOT_MODIFIED) \
457
+ XX(305, USE_PROXY, USE_PROXY) \
458
+ XX(306, SWITCH_PROXY, SWITCH_PROXY) \
459
+ XX(307, TEMPORARY_REDIRECT, TEMPORARY_REDIRECT) \
460
+ XX(308, PERMANENT_REDIRECT, PERMANENT_REDIRECT) \
461
+ XX(400, BAD_REQUEST, BAD_REQUEST) \
462
+ XX(401, UNAUTHORIZED, UNAUTHORIZED) \
463
+ XX(402, PAYMENT_REQUIRED, PAYMENT_REQUIRED) \
464
+ XX(403, FORBIDDEN, FORBIDDEN) \
465
+ XX(404, NOT_FOUND, NOT_FOUND) \
466
+ XX(405, METHOD_NOT_ALLOWED, METHOD_NOT_ALLOWED) \
467
+ XX(406, NOT_ACCEPTABLE, NOT_ACCEPTABLE) \
468
+ XX(407, PROXY_AUTHENTICATION_REQUIRED, PROXY_AUTHENTICATION_REQUIRED) \
469
+ XX(408, REQUEST_TIMEOUT, REQUEST_TIMEOUT) \
470
+ XX(409, CONFLICT, CONFLICT) \
471
+ XX(410, GONE, GONE) \
472
+ XX(411, LENGTH_REQUIRED, LENGTH_REQUIRED) \
473
+ XX(412, PRECONDITION_FAILED, PRECONDITION_FAILED) \
474
+ XX(413, PAYLOAD_TOO_LARGE, PAYLOAD_TOO_LARGE) \
475
+ XX(414, URI_TOO_LONG, URI_TOO_LONG) \
476
+ XX(415, UNSUPPORTED_MEDIA_TYPE, UNSUPPORTED_MEDIA_TYPE) \
477
+ XX(416, RANGE_NOT_SATISFIABLE, RANGE_NOT_SATISFIABLE) \
478
+ XX(417, EXPECTATION_FAILED, EXPECTATION_FAILED) \
479
+ XX(418, IM_A_TEAPOT, IM_A_TEAPOT) \
480
+ XX(419, PAGE_EXPIRED, PAGE_EXPIRED) \
481
+ XX(420, ENHANCE_YOUR_CALM, ENHANCE_YOUR_CALM) \
482
+ XX(421, MISDIRECTED_REQUEST, MISDIRECTED_REQUEST) \
483
+ XX(422, UNPROCESSABLE_ENTITY, UNPROCESSABLE_ENTITY) \
484
+ XX(423, LOCKED, LOCKED) \
485
+ XX(424, FAILED_DEPENDENCY, FAILED_DEPENDENCY) \
486
+ XX(425, TOO_EARLY, TOO_EARLY) \
487
+ XX(426, UPGRADE_REQUIRED, UPGRADE_REQUIRED) \
488
+ XX(428, PRECONDITION_REQUIRED, PRECONDITION_REQUIRED) \
489
+ XX(429, TOO_MANY_REQUESTS, TOO_MANY_REQUESTS) \
490
+ XX(430, REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL, REQUEST_HEADER_FIELDS_TOO_LARGE_UNOFFICIAL) \
491
+ XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, REQUEST_HEADER_FIELDS_TOO_LARGE) \
492
+ XX(440, LOGIN_TIMEOUT, LOGIN_TIMEOUT) \
493
+ XX(444, NO_RESPONSE, NO_RESPONSE) \
494
+ XX(449, RETRY_WITH, RETRY_WITH) \
495
+ XX(450, BLOCKED_BY_PARENTAL_CONTROL, BLOCKED_BY_PARENTAL_CONTROL) \
496
+ XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, UNAVAILABLE_FOR_LEGAL_REASONS) \
497
+ XX(460, CLIENT_CLOSED_LOAD_BALANCED_REQUEST, CLIENT_CLOSED_LOAD_BALANCED_REQUEST) \
498
+ XX(463, INVALID_X_FORWARDED_FOR, INVALID_X_FORWARDED_FOR) \
499
+ XX(494, REQUEST_HEADER_TOO_LARGE, REQUEST_HEADER_TOO_LARGE) \
500
+ XX(495, SSL_CERTIFICATE_ERROR, SSL_CERTIFICATE_ERROR) \
501
+ XX(496, SSL_CERTIFICATE_REQUIRED, SSL_CERTIFICATE_REQUIRED) \
502
+ XX(497, HTTP_REQUEST_SENT_TO_HTTPS_PORT, HTTP_REQUEST_SENT_TO_HTTPS_PORT) \
503
+ XX(498, INVALID_TOKEN, INVALID_TOKEN) \
504
+ XX(499, CLIENT_CLOSED_REQUEST, CLIENT_CLOSED_REQUEST) \
505
+ XX(500, INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR) \
506
+ XX(501, NOT_IMPLEMENTED, NOT_IMPLEMENTED) \
507
+ XX(502, BAD_GATEWAY, BAD_GATEWAY) \
508
+ XX(503, SERVICE_UNAVAILABLE, SERVICE_UNAVAILABLE) \
509
+ XX(504, GATEWAY_TIMEOUT, GATEWAY_TIMEOUT) \
510
+ XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP_VERSION_NOT_SUPPORTED) \
511
+ XX(506, VARIANT_ALSO_NEGOTIATES, VARIANT_ALSO_NEGOTIATES) \
512
+ XX(507, INSUFFICIENT_STORAGE, INSUFFICIENT_STORAGE) \
513
+ XX(508, LOOP_DETECTED, LOOP_DETECTED) \
514
+ XX(509, BANDWIDTH_LIMIT_EXCEEDED, BANDWIDTH_LIMIT_EXCEEDED) \
515
+ XX(510, NOT_EXTENDED, NOT_EXTENDED) \
516
+ XX(511, NETWORK_AUTHENTICATION_REQUIRED, NETWORK_AUTHENTICATION_REQUIRED) \
517
+ XX(520, WEB_SERVER_UNKNOWN_ERROR, WEB_SERVER_UNKNOWN_ERROR) \
518
+ XX(521, WEB_SERVER_IS_DOWN, WEB_SERVER_IS_DOWN) \
519
+ XX(522, CONNECTION_TIMEOUT, CONNECTION_TIMEOUT) \
520
+ XX(523, ORIGIN_IS_UNREACHABLE, ORIGIN_IS_UNREACHABLE) \
521
+ XX(524, TIMEOUT_OCCURED, TIMEOUT_OCCURED) \
522
+ XX(525, SSL_HANDSHAKE_FAILED, SSL_HANDSHAKE_FAILED) \
523
+ XX(526, INVALID_SSL_CERTIFICATE, INVALID_SSL_CERTIFICATE) \
524
+ XX(527, RAILGUN_ERROR, RAILGUN_ERROR) \
525
+ XX(529, SITE_IS_OVERLOADED, SITE_IS_OVERLOADED) \
526
+ XX(530, SITE_IS_FROZEN, SITE_IS_FROZEN) \
527
+ XX(561, IDENTITY_PROVIDER_AUTHENTICATION_ERROR, IDENTITY_PROVIDER_AUTHENTICATION_ERROR) \
528
+ XX(598, NETWORK_READ_TIMEOUT, NETWORK_READ_TIMEOUT) \
529
+ XX(599, NETWORK_CONNECT_TIMEOUT, NETWORK_CONNECT_TIMEOUT) \
530
+
531
+
325
532
  #ifdef __cplusplus
326
533
  } /* extern "C" */
327
534
  #endif
@@ -353,8 +560,12 @@ struct llhttp_settings_s {
353
560
  /* Possible return values 0, -1, HPE_USER */
354
561
  llhttp_data_cb on_url;
355
562
  llhttp_data_cb on_status;
563
+ llhttp_data_cb on_method;
564
+ llhttp_data_cb on_version;
356
565
  llhttp_data_cb on_header_field;
357
566
  llhttp_data_cb on_header_value;
567
+ llhttp_data_cb on_chunk_extension_name;
568
+ llhttp_data_cb on_chunk_extension_value;
358
569
 
359
570
  /* Possible return values:
360
571
  * 0 - Proceed normally
@@ -372,6 +583,14 @@ struct llhttp_settings_s {
372
583
 
373
584
  /* Possible return values 0, -1, `HPE_PAUSED` */
374
585
  llhttp_cb on_message_complete;
586
+ llhttp_cb on_url_complete;
587
+ llhttp_cb on_status_complete;
588
+ llhttp_cb on_method_complete;
589
+ llhttp_cb on_version_complete;
590
+ llhttp_cb on_header_field_complete;
591
+ llhttp_cb on_header_value_complete;
592
+ llhttp_cb on_chunk_extension_name_complete;
593
+ llhttp_cb on_chunk_extension_value_complete;
375
594
 
376
595
  /* When on_chunk_header is called, the current chunk length is stored
377
596
  * in parser->content_length.
@@ -379,12 +598,7 @@ struct llhttp_settings_s {
379
598
  */
380
599
  llhttp_cb on_chunk_header;
381
600
  llhttp_cb on_chunk_complete;
382
-
383
- /* Information-only callbacks, return value is ignored */
384
- llhttp_cb on_url_complete;
385
- llhttp_cb on_status_complete;
386
- llhttp_cb on_header_field_complete;
387
- llhttp_cb on_header_value_complete;
601
+ llhttp_cb on_reset;
388
602
  };
389
603
 
390
604
  /* Initialize the parser with specific type and user settings.
@@ -397,8 +611,6 @@ LLHTTP_EXPORT
397
611
  void llhttp_init(llhttp_t* parser, llhttp_type_t type,
398
612
  const llhttp_settings_t* settings);
399
613
 
400
- #if defined(__wasm__)
401
-
402
614
  LLHTTP_EXPORT
403
615
  llhttp_t* llhttp_alloc(llhttp_type_t type);
404
616
 
@@ -423,8 +635,6 @@ int llhttp_get_status_code(llhttp_t* parser);
423
635
  LLHTTP_EXPORT
424
636
  uint8_t llhttp_get_upgrade(llhttp_t* parser);
425
637
 
426
- #endif // defined(__wasm__)
427
-
428
638
  /* Reset an already initialized parser back to the start state, preserving the
429
639
  * existing parser type, callback settings, user data, and lenient flags.
430
640
  */
@@ -538,6 +748,9 @@ const char* llhttp_errno_name(llhttp_errno_t err);
538
748
  LLHTTP_EXPORT
539
749
  const char* llhttp_method_name(llhttp_method_t method);
540
750
 
751
+ /* Returns textual name of HTTP status */
752
+ LLHTTP_EXPORT
753
+ const char* llhttp_status_name(llhttp_status_t status);
541
754
 
542
755
  /* Enables/disables lenient header value parsing (disabled by default).
543
756
  *
@@ -577,8 +790,23 @@ void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
577
790
  *
578
791
  * **(USE AT YOUR OWN RISK)**
579
792
  */
793
+ LLHTTP_EXPORT
580
794
  void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled);
581
795
 
796
+ /* Enables/disables lenient handling of `Transfer-Encoding` header.
797
+ *
798
+ * Normally `llhttp` would error when a `Transfer-Encoding` has `chunked` value
799
+ * and another value after it (either in a single header or in multiple
800
+ * headers whose value are internally joined using `, `).
801
+ * This is mandated by the spec to reliably determine request body size and thus
802
+ * avoid request smuggling.
803
+ * With this flag the extra value will be parsed normally.
804
+ *
805
+ * **(USE AT YOUR OWN RISK)**
806
+ */
807
+ LLHTTP_EXPORT
808
+ void llhttp_set_lenient_transfer_encoding(llhttp_t* parser, int enabled);
809
+
582
810
  #ifdef __cplusplus
583
811
  } /* extern "C" */
584
812
  #endif
data/lib/llhttp/parser.rb CHANGED
@@ -117,12 +117,18 @@ module LLHttp
117
117
  LLHttp.llhttp_should_keep_alive(@pointer) == 1
118
118
  end
119
119
 
120
- # [public] Get ready to parse the next request.
120
+ # [public] Tells the parser we are finished.
121
121
  #
122
122
  def finish
123
123
  LLHttp.llhttp_finish(@pointer)
124
124
  end
125
125
 
126
+ # [public] Get ready to parse the next request/response.
127
+ #
128
+ def reset
129
+ LLHttp.llhttp_reset(@pointer)
130
+ end
131
+
126
132
  CALLBACKS.each do |callback|
127
133
  class_eval(
128
134
  <<~RB, __FILE__, __LINE__ + 1
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LLHttp
4
- VERSION = "0.3.1"
4
+ VERSION = "0.5.0"
5
5
 
6
6
  # [public] LLHttp's current version.
7
7
  #
data/lib/llhttp.rb CHANGED
@@ -45,4 +45,5 @@ module LLHttp
45
45
  attach_function :llhttp_get_error_reason, [:pointer], :string
46
46
  attach_function :llhttp_should_keep_alive, [:pointer], :int
47
47
  attach_function :llhttp_finish, [:pointer], :int
48
+ attach_function :llhttp_reset, [:pointer], :void
48
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: llhttp-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-26 00:00:00.000000000 Z
11
+ date: 2023-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi-compiler
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '13.0'
41
41
  description: Ruby FFI bindings for llhttp.
42
- email: bryan@metabahn.com
42
+ email: bryan@bryanp.org
43
43
  executables: []
44
44
  extensions:
45
45
  - ext/Rakefile
@@ -49,6 +49,11 @@ files:
49
49
  - LICENSE
50
50
  - README.md
51
51
  - ext/Rakefile
52
+ - ext/aarch64-darwin/libllhttp-ext.bundle
53
+ - ext/aarch64-darwin/llhttp/api.o
54
+ - ext/aarch64-darwin/llhttp/http.o
55
+ - ext/aarch64-darwin/llhttp/llhttp.o
56
+ - ext/aarch64-darwin/llhttp/llhttp_ext.o
52
57
  - ext/llhttp/api.c
53
58
  - ext/llhttp/extconf.rb
54
59
  - ext/llhttp/http.c
@@ -60,7 +65,7 @@ files:
60
65
  - lib/llhttp/error.rb
61
66
  - lib/llhttp/parser.rb
62
67
  - lib/llhttp/version.rb
63
- homepage: https://github.com/metabahn/llhttp/
68
+ homepage: https://github.com/bryanp/llhttp/
64
69
  licenses:
65
70
  - MPL-2.0
66
71
  metadata: {}
@@ -79,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
84
  - !ruby/object:Gem::Version
80
85
  version: '0'
81
86
  requirements: []
82
- rubygems_version: 3.2.15
87
+ rubygems_version: 3.4.9
83
88
  signing_key:
84
89
  specification_version: 4
85
90
  summary: Ruby FFI bindings for llhttp.