llhttp-ffi 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1f33e54207128605b6ad1d111b5ced05ac19212b6505ed51b41ec1319bab2ce
4
- data.tar.gz: 96abf164ead2adaad57bccf119675f24ddf2e44fd56797e3e8c7f1e64bb2eaad
3
+ metadata.gz: d94d37a52b76098822327cd0c1846f919a9598cdb7dcd84d9c9545708932e269
4
+ data.tar.gz: 945819b2b1ac223cb0c417b969a682ee300368214d4b93357ee876ffcc20abaf
5
5
  SHA512:
6
- metadata.gz: 706de30bf7f6d3326531c4cbc46d9df6edfac2c7cdace55a476ef651756bf8ab5e6c01429bd9a982bf2eb5b95f66d19852cc768867e6177314c0b6e0c79f8a55
7
- data.tar.gz: 1ffb14b881ff8648524465511ac467aab7094280b40795746e94746923ce0638907c66d87bab5b2ee0f45c71d5fc9f477cde919c1a42311f1d8b7456a811cc8b
6
+ metadata.gz: 8686cc40ffb08c4934c27b6c0450ca149f30ab7d0402b5f94529e10e0fc73e52492dcc437ed90ae8a4388f29d63132e41313c46218d76ea8c350f16980571828
7
+ data.tar.gz: 6322ed1aee6023e023b502a4dd8248d0b9b1152a886a056d5813d6944f61a8a66fa699c9c585cc4c7e46cb38cc1c08811f336ec59ad1832eb38b1d9cad22f802
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## v0.1.0
2
+
3
+ *unreleased*
4
+
5
+ * `chg` [#14](https://github.com/metabahn/llhttp/pull/14) Update ffi to llhttp 5.1.0 ([bryanp](https://github.com/bryanp))
6
+
1
7
  ## [v0.0.1](https://github.com/metabahn/llhttp/releases/tag/2021-03-04)
2
8
 
3
9
  *released on 2021-03-04*
data/ext/llhttp/api.c CHANGED
@@ -47,6 +47,70 @@ void llhttp_init(llhttp_t* parser, llhttp_type_t type,
47
47
  }
48
48
 
49
49
 
50
+ #if defined(__wasm__)
51
+
52
+ extern int wasm_on_message_begin(llhttp_t * p);
53
+ extern int wasm_on_url(llhttp_t* p, const char* at, size_t length);
54
+ extern int wasm_on_status(llhttp_t* p, const char* at, size_t length);
55
+ extern int wasm_on_header_field(llhttp_t* p, const char* at, size_t length);
56
+ extern int wasm_on_header_value(llhttp_t* p, const char* at, size_t length);
57
+ extern int wasm_on_headers_complete(llhttp_t * p);
58
+ extern int wasm_on_body(llhttp_t* p, const char* at, size_t length);
59
+ extern int wasm_on_message_complete(llhttp_t * p);
60
+
61
+ const llhttp_settings_t wasm_settings = {
62
+ wasm_on_message_begin,
63
+ wasm_on_url,
64
+ wasm_on_status,
65
+ wasm_on_header_field,
66
+ wasm_on_header_value,
67
+ wasm_on_headers_complete,
68
+ wasm_on_body,
69
+ wasm_on_message_complete,
70
+ NULL,
71
+ NULL,
72
+ };
73
+
74
+
75
+ llhttp_t* llhttp_alloc(llhttp_type_t type) {
76
+ llhttp_t* parser = malloc(sizeof(llhttp_t));
77
+ llhttp_init(parser, type, &wasm_settings);
78
+ return parser;
79
+ }
80
+
81
+ void llhttp_free(llhttp_t* parser) {
82
+ free(parser);
83
+ }
84
+
85
+ /* Some getters required to get stuff from the parser */
86
+
87
+ uint8_t llhttp_get_type(llhttp_t* parser) {
88
+ return parser->type;
89
+ }
90
+
91
+ uint8_t llhttp_get_http_major(llhttp_t* parser) {
92
+ return parser->http_major;
93
+ }
94
+
95
+ uint8_t llhttp_get_http_minor(llhttp_t* parser) {
96
+ return parser->http_minor;
97
+ }
98
+
99
+ uint8_t llhttp_get_method(llhttp_t* parser) {
100
+ return parser->method;
101
+ }
102
+
103
+ int llhttp_get_status_code(llhttp_t* parser) {
104
+ return parser->status_code;
105
+ }
106
+
107
+ uint8_t llhttp_get_upgrade(llhttp_t* parser) {
108
+ return parser->upgrade;
109
+ }
110
+
111
+ #endif // defined(__wasm__)
112
+
113
+
50
114
  void llhttp_reset(llhttp_t* parser) {
51
115
  llhttp_type_t type = parser->type;
52
116
  const llhttp_settings_t* settings = parser->settings;
@@ -173,6 +237,7 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) {
173
237
  }
174
238
  }
175
239
 
240
+
176
241
  void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
177
242
  if (enabled) {
178
243
  parser->lenient_flags |= LENIENT_CHUNKED_LENGTH;
@@ -182,6 +247,14 @@ void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) {
182
247
  }
183
248
 
184
249
 
250
+ void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled) {
251
+ if (enabled) {
252
+ parser->lenient_flags |= LENIENT_KEEP_ALIVE;
253
+ } else {
254
+ parser->lenient_flags &= ~LENIENT_KEEP_ALIVE;
255
+ }
256
+ }
257
+
185
258
  /* Callbacks */
186
259
 
187
260
 
data/ext/llhttp/llhttp.c CHANGED
@@ -650,6 +650,13 @@ int llhttp__internal__c_update_finish_1(
650
650
  return 0;
651
651
  }
652
652
 
653
+ int llhttp__internal__c_test_lenient_flags(
654
+ llhttp__internal_t* state,
655
+ const unsigned char* p,
656
+ const unsigned char* endp) {
657
+ return (state->lenient_flags & 4) == 4;
658
+ }
659
+
653
660
  int llhttp__internal__c_test_flags_1(
654
661
  llhttp__internal_t* state,
655
662
  const unsigned char* p,
@@ -657,7 +664,7 @@ int llhttp__internal__c_test_flags_1(
657
664
  return (state->flags & 544) == 544;
658
665
  }
659
666
 
660
- int llhttp__internal__c_test_lenient_flags(
667
+ int llhttp__internal__c_test_lenient_flags_1(
661
668
  llhttp__internal_t* state,
662
669
  const unsigned char* p,
663
670
  const unsigned char* endp) {
@@ -825,7 +832,7 @@ int llhttp__internal__c_update_header_state_2(
825
832
  return 0;
826
833
  }
827
834
 
828
- int llhttp__internal__c_test_lenient_flags_1(
835
+ int llhttp__internal__c_test_lenient_flags_2(
829
836
  llhttp__internal_t* state,
830
837
  const unsigned char* p,
831
838
  const unsigned char* endp) {
@@ -1684,7 +1691,7 @@ static llparse_state_t llhttp__internal__run(
1684
1691
  goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2;
1685
1692
  }
1686
1693
  default: {
1687
- goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
1694
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags_2;
1688
1695
  }
1689
1696
  }
1690
1697
  /* UNREACHABLE */;
@@ -5756,10 +5763,20 @@ static llparse_state_t llhttp__internal__run(
5756
5763
  /* UNREACHABLE */;
5757
5764
  abort();
5758
5765
  }
5766
+ s_n_llhttp__internal__n_invoke_test_lenient_flags: {
5767
+ switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
5768
+ case 1:
5769
+ goto s_n_llhttp__internal__n_invoke_update_finish_2;
5770
+ default:
5771
+ goto s_n_llhttp__internal__n_closed;
5772
+ }
5773
+ /* UNREACHABLE */;
5774
+ abort();
5775
+ }
5759
5776
  s_n_llhttp__internal__n_invoke_update_finish_1: {
5760
5777
  switch (llhttp__internal__c_update_finish_1(state, p, endp)) {
5761
5778
  default:
5762
- goto s_n_llhttp__internal__n_closed;
5779
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
5763
5780
  }
5764
5781
  /* UNREACHABLE */;
5765
5782
  abort();
@@ -6121,8 +6138,8 @@ static llparse_state_t llhttp__internal__run(
6121
6138
  /* UNREACHABLE */;
6122
6139
  abort();
6123
6140
  }
6124
- s_n_llhttp__internal__n_invoke_test_lenient_flags: {
6125
- switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
6141
+ s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
6142
+ switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
6126
6143
  case 0:
6127
6144
  goto s_n_llhttp__internal__n_error_15;
6128
6145
  default:
@@ -6134,7 +6151,7 @@ static llparse_state_t llhttp__internal__run(
6134
6151
  s_n_llhttp__internal__n_invoke_test_flags_1: {
6135
6152
  switch (llhttp__internal__c_test_flags_1(state, p, endp)) {
6136
6153
  case 1:
6137
- goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
6154
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
6138
6155
  default:
6139
6156
  goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete;
6140
6157
  }
@@ -6388,8 +6405,8 @@ static llparse_state_t llhttp__internal__run(
6388
6405
  /* UNREACHABLE */;
6389
6406
  abort();
6390
6407
  }
6391
- s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
6392
- switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
6408
+ s_n_llhttp__internal__n_invoke_test_lenient_flags_2: {
6409
+ switch (llhttp__internal__c_test_lenient_flags_2(state, p, endp)) {
6393
6410
  case 1:
6394
6411
  goto s_n_llhttp__internal__n_header_value_lenient;
6395
6412
  default:
@@ -6750,7 +6767,7 @@ static llparse_state_t llhttp__internal__run(
6750
6767
  abort();
6751
6768
  }
6752
6769
  s_n_llhttp__internal__n_error_29: {
6753
- state->error = 0x16;
6770
+ state->error = 0x17;
6754
6771
  state->reason = "Pause on PRI/Upgrade";
6755
6772
  state->error_pos = (const char*) p;
6756
6773
  state->_current = (void*) (intptr_t) s_error;
@@ -7929,6 +7946,7 @@ reset:
7929
7946
 
7930
7947
  enum llparse_state_e {
7931
7948
  s_error,
7949
+ s_n_llhttp__internal__n_closed,
7932
7950
  s_n_llhttp__internal__n_invoke_llhttp__after_message_complete,
7933
7951
  s_n_llhttp__internal__n_pause_1,
7934
7952
  s_n_llhttp__internal__n_invoke_is_equal_upgrade,
@@ -8222,6 +8240,13 @@ int llhttp__internal__c_update_finish_1(
8222
8240
  return 0;
8223
8241
  }
8224
8242
 
8243
+ int llhttp__internal__c_test_lenient_flags(
8244
+ llhttp__internal_t* state,
8245
+ const unsigned char* p,
8246
+ const unsigned char* endp) {
8247
+ return (state->lenient_flags & 4) == 4;
8248
+ }
8249
+
8225
8250
  int llhttp__internal__c_test_flags_1(
8226
8251
  llhttp__internal_t* state,
8227
8252
  const unsigned char* p,
@@ -8229,7 +8254,7 @@ int llhttp__internal__c_test_flags_1(
8229
8254
  return (state->flags & 544) == 544;
8230
8255
  }
8231
8256
 
8232
- int llhttp__internal__c_test_lenient_flags(
8257
+ int llhttp__internal__c_test_lenient_flags_1(
8233
8258
  llhttp__internal_t* state,
8234
8259
  const unsigned char* p,
8235
8260
  const unsigned char* endp) {
@@ -8301,7 +8326,7 @@ int llhttp__internal__c_or_flags(
8301
8326
  return 0;
8302
8327
  }
8303
8328
 
8304
- int llhttp__internal__c_update_finish_2(
8329
+ int llhttp__internal__c_update_finish_3(
8305
8330
  llhttp__internal_t* state,
8306
8331
  const unsigned char* p,
8307
8332
  const unsigned char* endp) {
@@ -8397,7 +8422,7 @@ int llhttp__internal__c_update_header_state_2(
8397
8422
  return 0;
8398
8423
  }
8399
8424
 
8400
- int llhttp__internal__c_test_lenient_flags_1(
8425
+ int llhttp__internal__c_test_lenient_flags_2(
8401
8426
  llhttp__internal_t* state,
8402
8427
  const unsigned char* p,
8403
8428
  const unsigned char* endp) {
@@ -8597,9 +8622,21 @@ static llparse_state_t llhttp__internal__run(
8597
8622
  const unsigned char* endp) {
8598
8623
  int match;
8599
8624
  switch ((llparse_state_t) (intptr_t) state->_current) {
8625
+ case s_n_llhttp__internal__n_closed:
8626
+ s_n_llhttp__internal__n_closed: {
8627
+ if (p == endp) {
8628
+ return s_n_llhttp__internal__n_closed;
8629
+ }
8630
+ p++;
8631
+ goto s_n_llhttp__internal__n_closed;
8632
+ /* UNREACHABLE */;
8633
+ abort();
8634
+ }
8600
8635
  case s_n_llhttp__internal__n_invoke_llhttp__after_message_complete:
8601
8636
  s_n_llhttp__internal__n_invoke_llhttp__after_message_complete: {
8602
8637
  switch (llhttp__after_message_complete(state, p, endp)) {
8638
+ case 1:
8639
+ goto s_n_llhttp__internal__n_invoke_update_finish_2;
8603
8640
  default:
8604
8641
  goto s_n_llhttp__internal__n_invoke_update_finish_1;
8605
8642
  }
@@ -9068,7 +9105,7 @@ static llparse_state_t llhttp__internal__run(
9068
9105
  case 3:
9069
9106
  goto s_n_llhttp__internal__n_span_start_llhttp__on_body_1;
9070
9107
  case 4:
9071
- goto s_n_llhttp__internal__n_invoke_update_finish_2;
9108
+ goto s_n_llhttp__internal__n_invoke_update_finish_3;
9072
9109
  case 5:
9073
9110
  goto s_n_llhttp__internal__n_error_10;
9074
9111
  default:
@@ -9207,7 +9244,7 @@ static llparse_state_t llhttp__internal__run(
9207
9244
  goto s_n_llhttp__internal__n_span_end_llhttp__on_header_value_2;
9208
9245
  }
9209
9246
  default: {
9210
- goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
9247
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags_2;
9211
9248
  }
9212
9249
  }
9213
9250
  /* UNREACHABLE */;
@@ -13100,7 +13137,7 @@ static llparse_state_t llhttp__internal__run(
13100
13137
  /* UNREACHABLE */;
13101
13138
  abort();
13102
13139
  }
13103
- s_n_llhttp__internal__n_invoke_update_finish_1: {
13140
+ s_n_llhttp__internal__n_invoke_update_finish_2: {
13104
13141
  switch (llhttp__internal__c_update_finish_1(state, p, endp)) {
13105
13142
  default:
13106
13143
  goto s_n_llhttp__internal__n_start;
@@ -13108,6 +13145,24 @@ static llparse_state_t llhttp__internal__run(
13108
13145
  /* UNREACHABLE */;
13109
13146
  abort();
13110
13147
  }
13148
+ s_n_llhttp__internal__n_invoke_test_lenient_flags: {
13149
+ switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
13150
+ case 1:
13151
+ goto s_n_llhttp__internal__n_invoke_update_finish_2;
13152
+ default:
13153
+ goto s_n_llhttp__internal__n_closed;
13154
+ }
13155
+ /* UNREACHABLE */;
13156
+ abort();
13157
+ }
13158
+ s_n_llhttp__internal__n_invoke_update_finish_1: {
13159
+ switch (llhttp__internal__c_update_finish_1(state, p, endp)) {
13160
+ default:
13161
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
13162
+ }
13163
+ /* UNREACHABLE */;
13164
+ abort();
13165
+ }
13111
13166
  s_n_llhttp__internal__n_pause_5: {
13112
13167
  state->error = 0x15;
13113
13168
  state->reason = "on_message_complete pause";
@@ -13334,8 +13389,8 @@ static llparse_state_t llhttp__internal__run(
13334
13389
  /* UNREACHABLE */;
13335
13390
  abort();
13336
13391
  }
13337
- s_n_llhttp__internal__n_invoke_update_finish_2: {
13338
- switch (llhttp__internal__c_update_finish_2(state, p, endp)) {
13392
+ s_n_llhttp__internal__n_invoke_update_finish_3: {
13393
+ switch (llhttp__internal__c_update_finish_3(state, p, endp)) {
13339
13394
  default:
13340
13395
  goto s_n_llhttp__internal__n_span_start_llhttp__on_body_2;
13341
13396
  }
@@ -13447,8 +13502,8 @@ static llparse_state_t llhttp__internal__run(
13447
13502
  /* UNREACHABLE */;
13448
13503
  abort();
13449
13504
  }
13450
- s_n_llhttp__internal__n_invoke_test_lenient_flags: {
13451
- switch (llhttp__internal__c_test_lenient_flags(state, p, endp)) {
13505
+ s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
13506
+ switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
13452
13507
  case 0:
13453
13508
  goto s_n_llhttp__internal__n_error_11;
13454
13509
  default:
@@ -13460,7 +13515,7 @@ static llparse_state_t llhttp__internal__run(
13460
13515
  s_n_llhttp__internal__n_invoke_test_flags_1: {
13461
13516
  switch (llhttp__internal__c_test_flags_1(state, p, endp)) {
13462
13517
  case 1:
13463
- goto s_n_llhttp__internal__n_invoke_test_lenient_flags;
13518
+ goto s_n_llhttp__internal__n_invoke_test_lenient_flags_1;
13464
13519
  default:
13465
13520
  goto s_n_llhttp__internal__n_invoke_llhttp__before_headers_complete;
13466
13521
  }
@@ -13696,8 +13751,8 @@ static llparse_state_t llhttp__internal__run(
13696
13751
  /* UNREACHABLE */;
13697
13752
  abort();
13698
13753
  }
13699
- s_n_llhttp__internal__n_invoke_test_lenient_flags_1: {
13700
- switch (llhttp__internal__c_test_lenient_flags_1(state, p, endp)) {
13754
+ s_n_llhttp__internal__n_invoke_test_lenient_flags_2: {
13755
+ switch (llhttp__internal__c_test_lenient_flags_2(state, p, endp)) {
13701
13756
  case 1:
13702
13757
  goto s_n_llhttp__internal__n_header_value_lenient;
13703
13758
  default:
@@ -14058,7 +14113,7 @@ static llparse_state_t llhttp__internal__run(
14058
14113
  abort();
14059
14114
  }
14060
14115
  s_n_llhttp__internal__n_error_23: {
14061
- state->error = 0x16;
14116
+ state->error = 0x17;
14062
14117
  state->reason = "Pause on PRI/Upgrade";
14063
14118
  state->error_pos = (const char*) p;
14064
14119
  state->_current = (void*) (intptr_t) s_error;
data/ext/llhttp/llhttp.h CHANGED
@@ -24,8 +24,8 @@
24
24
  #ifndef INCLUDE_LLHTTP_H_
25
25
  #define INCLUDE_LLHTTP_H_
26
26
 
27
- #define LLHTTP_VERSION_MAJOR 4
28
- #define LLHTTP_VERSION_MINOR 0
27
+ #define LLHTTP_VERSION_MAJOR 5
28
+ #define LLHTTP_VERSION_MINOR 1
29
29
  #define LLHTTP_VERSION_PATCH 0
30
30
 
31
31
  #ifndef LLHTTP_STRICT_MODE
@@ -102,7 +102,8 @@ enum llhttp_errno {
102
102
  HPE_CB_CHUNK_COMPLETE = 20,
103
103
  HPE_PAUSED = 21,
104
104
  HPE_PAUSED_UPGRADE = 22,
105
- HPE_USER = 23
105
+ HPE_PAUSED_H2_UPGRADE = 23,
106
+ HPE_USER = 24
106
107
  };
107
108
  typedef enum llhttp_errno llhttp_errno_t;
108
109
 
@@ -121,7 +122,8 @@ typedef enum llhttp_flags llhttp_flags_t;
121
122
 
122
123
  enum llhttp_lenient_flags {
123
124
  LENIENT_HEADERS = 0x1,
124
- LENIENT_CHUNKED_LENGTH = 0x2
125
+ LENIENT_CHUNKED_LENGTH = 0x2,
126
+ LENIENT_KEEP_ALIVE = 0x4
125
127
  };
126
128
  typedef enum llhttp_lenient_flags llhttp_lenient_flags_t;
127
129
 
@@ -213,7 +215,8 @@ typedef enum llhttp_method llhttp_method_t;
213
215
  XX(20, CB_CHUNK_COMPLETE, CB_CHUNK_COMPLETE) \
214
216
  XX(21, PAUSED, PAUSED) \
215
217
  XX(22, PAUSED_UPGRADE, PAUSED_UPGRADE) \
216
- XX(23, USER, USER) \
218
+ XX(23, PAUSED_H2_UPGRADE, PAUSED_H2_UPGRADE) \
219
+ XX(24, USER, USER) \
217
220
 
218
221
 
219
222
  #define HTTP_METHOD_MAP(XX) \
@@ -278,6 +281,12 @@ extern "C" {
278
281
  #endif
279
282
  #include <stddef.h>
280
283
 
284
+ #if defined(__wasm__)
285
+ #define LLHTTP_EXPORT __attribute__((visibility("default")))
286
+ #else
287
+ #define LLHTTP_EXPORT
288
+ #endif
289
+
281
290
  typedef llhttp__internal_t llhttp_t;
282
291
  typedef struct llhttp_settings_s llhttp_settings_t;
283
292
 
@@ -328,15 +337,46 @@ struct llhttp_settings_s {
328
337
  * the `parser` here. In practice, `settings` has to be either a static
329
338
  * variable or be allocated with `malloc`, `new`, etc.
330
339
  */
340
+ LLHTTP_EXPORT
331
341
  void llhttp_init(llhttp_t* parser, llhttp_type_t type,
332
342
  const llhttp_settings_t* settings);
333
343
 
344
+ #if defined(__wasm__)
345
+
346
+ LLHTTP_EXPORT
347
+ llhttp_t* llhttp_alloc(llhttp_type_t type);
348
+
349
+ LLHTTP_EXPORT
350
+ void llhttp_free(llhttp_t* parser);
351
+
352
+ LLHTTP_EXPORT
353
+ uint8_t llhttp_get_type(llhttp_t* parser);
354
+
355
+ LLHTTP_EXPORT
356
+ uint8_t llhttp_get_http_major(llhttp_t* parser);
357
+
358
+ LLHTTP_EXPORT
359
+ uint8_t llhttp_get_http_minor(llhttp_t* parser);
360
+
361
+ LLHTTP_EXPORT
362
+ uint8_t llhttp_get_method(llhttp_t* parser);
363
+
364
+ LLHTTP_EXPORT
365
+ int llhttp_get_status_code(llhttp_t* parser);
366
+
367
+ LLHTTP_EXPORT
368
+ uint8_t llhttp_get_upgrade(llhttp_t* parser);
369
+
370
+ #endif // defined(__wasm__)
371
+
334
372
  /* Reset an already initialized parser back to the start state, preserving the
335
373
  * existing parser type, callback settings, user data, and lenient flags.
336
374
  */
375
+ LLHTTP_EXPORT
337
376
  void llhttp_reset(llhttp_t* parser);
338
377
 
339
378
  /* Initialize the settings object */
379
+ LLHTTP_EXPORT
340
380
  void llhttp_settings_init(llhttp_settings_t* settings);
341
381
 
342
382
  /* Parse full or partial request/response, invoking user callbacks along the
@@ -355,6 +395,7 @@ void llhttp_settings_init(llhttp_settings_t* settings);
355
395
  * to return the same error upon each successive call up until `llhttp_init()`
356
396
  * is called.
357
397
  */
398
+ LLHTTP_EXPORT
358
399
  llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
359
400
 
360
401
  /* This method should be called when the other side has no further bytes to
@@ -365,16 +406,19 @@ llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len);
365
406
  * connection. This method will invoke `on_message_complete()` callback if the
366
407
  * request was terminated safely. Otherwise a error code would be returned.
367
408
  */
409
+ LLHTTP_EXPORT
368
410
  llhttp_errno_t llhttp_finish(llhttp_t* parser);
369
411
 
370
412
  /* Returns `1` if the incoming message is parsed until the last byte, and has
371
413
  * to be completed by calling `llhttp_finish()` on EOF
372
414
  */
415
+ LLHTTP_EXPORT
373
416
  int llhttp_message_needs_eof(const llhttp_t* parser);
374
417
 
375
418
  /* Returns `1` if there might be any other messages following the last that was
376
419
  * successfully parsed.
377
420
  */
421
+ LLHTTP_EXPORT
378
422
  int llhttp_should_keep_alive(const llhttp_t* parser);
379
423
 
380
424
  /* Make further calls of `llhttp_execute()` return `HPE_PAUSED` and set
@@ -383,6 +427,7 @@ int llhttp_should_keep_alive(const llhttp_t* parser);
383
427
  * Important: do not call this from user callbacks! User callbacks must return
384
428
  * `HPE_PAUSED` if pausing is required.
385
429
  */
430
+ LLHTTP_EXPORT
386
431
  void llhttp_pause(llhttp_t* parser);
387
432
 
388
433
  /* Might be called to resume the execution after the pause in user's callback.
@@ -390,6 +435,7 @@ void llhttp_pause(llhttp_t* parser);
390
435
  *
391
436
  * Call this only if `llhttp_execute()` returns `HPE_PAUSED`.
392
437
  */
438
+ LLHTTP_EXPORT
393
439
  void llhttp_resume(llhttp_t* parser);
394
440
 
395
441
  /* Might be called to resume the execution after the pause in user's callback.
@@ -397,9 +443,11 @@ void llhttp_resume(llhttp_t* parser);
397
443
  *
398
444
  * Call this only if `llhttp_execute()` returns `HPE_PAUSED_UPGRADE`
399
445
  */
446
+ LLHTTP_EXPORT
400
447
  void llhttp_resume_after_upgrade(llhttp_t* parser);
401
448
 
402
449
  /* Returns the latest return error */
450
+ LLHTTP_EXPORT
403
451
  llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
404
452
 
405
453
  /* Returns the verbal explanation of the latest returned error.
@@ -407,6 +455,7 @@ llhttp_errno_t llhttp_get_errno(const llhttp_t* parser);
407
455
  * Note: User callback should set error reason when returning the error. See
408
456
  * `llhttp_set_error_reason()` for details.
409
457
  */
458
+ LLHTTP_EXPORT
410
459
  const char* llhttp_get_error_reason(const llhttp_t* parser);
411
460
 
412
461
  /* Assign verbal description to the returned error. Must be called in user
@@ -414,6 +463,7 @@ const char* llhttp_get_error_reason(const llhttp_t* parser);
414
463
  *
415
464
  * Note: `HPE_USER` error code might be useful in user callbacks.
416
465
  */
466
+ LLHTTP_EXPORT
417
467
  void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
418
468
 
419
469
  /* Returns the pointer to the last parsed byte before the returned error. The
@@ -421,12 +471,15 @@ void llhttp_set_error_reason(llhttp_t* parser, const char* reason);
421
471
  *
422
472
  * Note: this method might be useful for counting the number of parsed bytes.
423
473
  */
474
+ LLHTTP_EXPORT
424
475
  const char* llhttp_get_error_pos(const llhttp_t* parser);
425
476
 
426
477
  /* Returns textual name of error code */
478
+ LLHTTP_EXPORT
427
479
  const char* llhttp_errno_name(llhttp_errno_t err);
428
480
 
429
481
  /* Returns textual name of HTTP method */
482
+ LLHTTP_EXPORT
430
483
  const char* llhttp_method_name(llhttp_method_t method);
431
484
 
432
485
 
@@ -439,6 +492,7 @@ const char* llhttp_method_name(llhttp_method_t method);
439
492
  *
440
493
  * **(USE AT YOUR OWN RISK)**
441
494
  */
495
+ LLHTTP_EXPORT
442
496
  void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
443
497
 
444
498
 
@@ -452,8 +506,23 @@ void llhttp_set_lenient_headers(llhttp_t* parser, int enabled);
452
506
  *
453
507
  * **(USE AT YOUR OWN RISK)**
454
508
  */
509
+ LLHTTP_EXPORT
455
510
  void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled);
456
511
 
512
+
513
+ /* Enables/disables lenient handling of `Connection: close` and HTTP/1.0
514
+ * requests responses.
515
+ *
516
+ * Normally `llhttp` would error on (in strict mode) or discard (in loose mode)
517
+ * the HTTP request/response after the request/response with `Connection: close`
518
+ * and `Content-Length`. This is important to prevent cache poisoning attacks,
519
+ * but might interact badly with outdated and insecure clients. With this flag
520
+ * the extra request/response will be parsed normally.
521
+ *
522
+ * **(USE AT YOUR OWN RISK)**
523
+ */
524
+ void llhttp_set_lenient_keep_alive(llhttp_t* parser, int enabled);
525
+
457
526
  #ifdef __cplusplus
458
527
  } /* extern "C" */
459
528
  #endif
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LLHttp
4
- VERSION = "0.0.1"
4
+ VERSION = "0.1.0"
5
5
 
6
6
  # [public] LLHttp's current version.
7
7
  #
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.0.1
4
+ version: 0.1.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-03-04 00:00:00.000000000 Z
11
+ date: 2021-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi-compiler
@@ -55,11 +55,6 @@ files:
55
55
  - ext/llhttp/llhttp.c
56
56
  - ext/llhttp/llhttp.h
57
57
  - ext/llhttp/llhttp_ext.c
58
- - ext/x86_64-darwin/libllhttp-ext.bundle
59
- - ext/x86_64-darwin/llhttp/api.o
60
- - ext/x86_64-darwin/llhttp/http.o
61
- - ext/x86_64-darwin/llhttp/llhttp.o
62
- - ext/x86_64-darwin/llhttp/llhttp_ext.o
63
58
  - lib/llhttp.rb
64
59
  - lib/llhttp/delegate.rb
65
60
  - lib/llhttp/error.rb
Binary file
Binary file
Binary file
Binary file
Binary file