-
-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathhttp_client.rs
More file actions
723 lines (721 loc) · 20.7 KB
/
Copy pathhttp_client.rs
File metadata and controls
723 lines (721 loc) · 20.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
use super::*;
const fn cr(
method: &'static str,
runtime: &'static str,
args: &'static [NativeArgKind],
ret: NativeRetKind,
) -> NativeModSig {
NativeModSig {
module: "http",
has_receiver: true,
method,
class_filter: Some("ClientRequest"),
runtime,
args,
ret,
}
}
pub(super) const HTTP_CLIENT_ROWS: &[NativeModSig] = &[
// ========== node:http / node:https client (issue #769) ==========
// `http.request(url_or_options, cb)` / `http.get(url_or_options, cb)`
// and their `https.*` variants. Runtime impls live in
// `crates/perry-stdlib/src/http.rs` and have been declared in the FFI
// table for a while, but no `NativeModSig` entries existed — so user
// code calling `http.request(...)` fell through to the unknown-method
// path and got back `TAG_UNDEFINED`. Return is a `ClientRequest`
// handle; the let-stmt arm in `crates/perry-hir/src/lower.rs` tags
// the binding so `req.on/.end/.write/...` dispatch via the
// class-filtered entries below.
// #3226/#3227/#3228 — client factory overloads. Node accepts
// `request(url[, cb])`, `request(options[, cb])`, and
// `request(url, options[, cb])` (same for `get`). A fixed
// `[NA_F64, NA_PTR]` shape mis-routed the options object into the
// callback slot and dropped the real callback in the three-arg form.
// Pass every user arg as a JS array (`NA_VARARGS`, mirroring the
// `listen()` rows) and let the runtime `*_overload` entry points
// resolve `(url, options, callback)` by value type. Runtime impls
// live in `crates/perry-ext-http/src/lib.rs`.
NativeModSig {
module: "http",
has_receiver: false,
method: "request",
class_filter: None,
runtime: "js_http_request_overload",
args: &[NA_VARARGS],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: false,
method: "get",
class_filter: None,
runtime: "js_http_get_overload",
args: &[NA_VARARGS],
ret: NR_PTR,
},
NativeModSig {
module: "https",
has_receiver: false,
method: "request",
class_filter: None,
runtime: "js_https_request_overload",
args: &[NA_VARARGS],
ret: NR_PTR,
},
NativeModSig {
module: "https",
has_receiver: false,
method: "get",
class_filter: None,
runtime: "js_https_get_overload",
args: &[NA_VARARGS],
ret: NR_PTR,
},
// #3712 — module-level header-validation / parser-proxy helpers. Runtime
// impls live in `crates/perry-runtime/src/object/native_module_dispatch.rs`.
// `validateHeaderName`/`validateHeaderValue` throw Node-shaped error codes
// on invalid input; the two setters are deterministic no-ops returning
// undefined. Args are passed as NaN-boxed f64 (the helpers coerce/probe
// them), return is the NaN-boxed undefined value.
NativeModSig {
module: "http",
has_receiver: false,
method: "validateHeaderName",
class_filter: None,
runtime: "js_http_validate_header_name",
args: &[NA_F64, NA_F64],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: false,
method: "validateHeaderValue",
class_filter: None,
runtime: "js_http_validate_header_value",
args: &[NA_F64, NA_F64],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: false,
method: "setMaxIdleHTTPParsers",
class_filter: None,
runtime: "js_http_setter_noop",
args: &[NA_F64],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: false,
method: "setGlobalProxyFromEnv",
class_filter: None,
runtime: "js_http_setter_noop",
args: &[NA_F64],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: false,
method: "_connectionListener",
class_filter: None,
runtime: "js_http_connection_listener_noop",
args: &[NA_F64],
ret: NR_F64,
},
// ClientRequest instance methods (`req.on/.end/.write/.setHeader/.setTimeout`).
// Shared between `http` and `https` factories — both register the
// returned binding under module `"http"` in the HIR class table.
NativeModSig {
module: "http",
has_receiver: true,
method: "on",
class_filter: Some("ClientRequest"),
runtime: "js_http_on",
args: &[NA_STR, NA_PTR],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "end",
class_filter: Some("ClientRequest"),
// #4909: route to the callback-aware end so `req.end(chunk, cb)` /
// `req.end(cb)` fire their callback (and the queued write callbacks
// + `'finish'`) in Node's flush order. arg2/arg3 carry the
// `(encoding?, callback?)` tail.
runtime: "js_http_client_request_end_full",
args: &[NA_F64, NA_JSV, NA_JSV],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "write",
class_filter: Some("ClientRequest"),
// #4909: pass the trailing `(encoding?, callback?)` args as raw
// JSValues so the runtime can queue the write callback and return a
// real boolean (NR_F64 → NaN-boxed bool) for backpressure. The
// previous `js_http_client_request_write` (NA_F64 only / NR_PTR)
// dropped the callback and returned the always-truthy handle, so
// `while (req.write(buf))` producer loops never terminated.
runtime: "js_http_client_request_write_full",
args: &[NA_F64, NA_JSV, NA_JSV],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "setHeader",
class_filter: Some("ClientRequest"),
runtime: "js_http_set_header",
args: &[NA_STR, NA_STR],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "setTimeout",
class_filter: Some("ClientRequest"),
// #4909: the callback arg registers as a `'timeout'` listener and a
// real timer is armed (previously the delay was only stored, so
// `req.setTimeout(n, cb)` on a never-responding server hung forever).
runtime: "js_http_set_timeout_full",
args: &[NA_F64, NA_JSV],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "listenerCount",
class_filter: Some("ClientRequest"),
runtime: "js_http_client_request_listener_count",
args: &[NA_STR],
ret: NR_F64,
},
cr(
"getHeader",
"js_http_client_request_get_header",
&[NA_STR],
NR_F64,
),
cr(
"hasHeader",
"js_http_client_request_has_header",
&[NA_STR],
NR_F64,
),
cr(
"removeHeader",
"js_http_client_request_remove_header",
&[NA_STR],
NR_F64,
),
cr(
"getHeaderNames",
"js_http_client_request_get_header_names",
&[],
NR_F64,
),
cr(
"getHeaders",
"js_http_client_request_get_headers",
&[],
NR_F64,
),
cr(
"getRawHeaderNames",
"js_http_client_request_get_raw_header_names",
&[],
NR_F64,
),
cr("abort", "js_http_client_request_abort", &[], NR_F64),
cr(
"destroy",
"js_http_client_request_destroy",
&[NA_F64],
NR_PTR,
),
cr(
"flushHeaders",
"js_http_client_request_noop_undefined",
&[NA_F64, NA_F64],
NR_F64,
),
cr(
"cork",
"js_http_client_request_noop_undefined",
&[NA_F64, NA_F64],
NR_F64,
),
cr(
"uncork",
"js_http_client_request_noop_undefined",
&[NA_F64, NA_F64],
NR_F64,
),
cr(
"setNoDelay",
"js_http_client_request_noop_undefined",
&[NA_F64, NA_F64],
NR_F64,
),
cr(
"setSocketKeepAlive",
"js_http_client_request_noop_undefined",
&[NA_F64, NA_F64],
NR_F64,
),
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_method",
class_filter: Some("ClientRequest"),
runtime: "js_http_client_request_method",
args: &[],
ret: NR_STR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_protocol",
class_filter: Some("ClientRequest"),
runtime: "js_http_client_request_protocol",
args: &[],
ret: NR_STR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_host",
class_filter: Some("ClientRequest"),
runtime: "js_http_client_request_host",
args: &[],
ret: NR_STR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_path",
class_filter: Some("ClientRequest"),
runtime: "js_http_client_request_path",
args: &[],
ret: NR_STR,
},
cr(
"__get_aborted",
"js_http_client_request_aborted",
&[],
NR_F64,
),
cr(
"__get_destroyed",
"js_http_client_request_destroyed",
&[],
NR_F64,
),
cr(
"__get_finished",
"js_http_client_request_finished",
&[],
NR_F64,
),
cr(
"__get_reusedSocket",
"js_http_client_request_reused_socket",
&[],
NR_F64,
),
cr(
"__get_maxHeadersCount",
"js_http_client_request_max_headers_count",
&[],
NR_F64,
),
cr(
"__get_writableEnded",
"js_http_client_request_writable_ended",
&[],
NR_F64,
),
cr(
"__get_writableFinished",
"js_http_client_request_writable_finished",
&[],
NR_F64,
),
cr("__get_socket", "js_http_client_request_socket", &[], NR_F64),
cr(
"__get_connection",
"js_http_client_request_socket",
&[],
NR_F64,
),
// ========== http.Agent / https.Agent (issue #2129) ==========
// `new http.Agent(options?)` / `new https.Agent(options?)` — registered
// via the Member-callee path in lower/expr_new.rs (mirrors the
// `new net.Socket()` route). Both classes share the same instance
// surface; only the constructor differs (default protocol).
NativeModSig {
module: "http",
has_receiver: false,
method: "Agent",
class_filter: None,
runtime: "js_http_agent_new",
args: &[NA_F64],
ret: NR_PTR,
},
NativeModSig {
module: "https",
has_receiver: false,
method: "Agent",
class_filter: None,
runtime: "js_https_agent_new",
args: &[NA_F64],
ret: NR_PTR,
},
// Agent instance methods. Most are chainable no-ops today — Perry
// doesn't pool sockets, but Node's test suite asserts the methods
// exist and don't throw. `getName(options)` is the one method whose
// exact output the tests check.
NativeModSig {
module: "http",
has_receiver: true,
method: "getName",
class_filter: Some("Agent"),
runtime: "js_http_agent_get_name",
args: &[NA_F64],
ret: NR_STR,
},
// #2154: real `destroy()` flips the `destroyed` flag (no-op
// pre-#2154 — the agent had nothing to destroy because it owned no
// sockets). Still chainable: returns the receiver handle.
NativeModSig {
module: "http",
has_receiver: true,
method: "destroy",
class_filter: Some("Agent"),
runtime: "js_http_agent_destroy",
args: &[],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "keepSocketAlive",
class_filter: Some("Agent"),
runtime: "js_http_agent_noop_self",
args: &[],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "reuseSocket",
class_filter: Some("Agent"),
runtime: "js_http_agent_noop_self",
args: &[],
ret: NR_PTR,
},
// Property accessors as `__get_<name>` synthetic methods. The HIR
// rewrites bare `agent.maxSockets` reads to `agent.__get_maxSockets()`
// when the receiver is tagged as ("http"|"https", "Agent").
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_maxSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_max_sockets",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_maxFreeSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_max_free_sockets",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_maxTotalSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_max_total_sockets",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_keepAliveMsecs",
class_filter: Some("Agent"),
runtime: "js_http_agent_keep_alive_msecs",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_keepAlive",
class_filter: Some("Agent"),
runtime: "js_http_agent_keep_alive",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_protocol",
class_filter: Some("Agent"),
runtime: "js_http_agent_protocol",
args: &[],
ret: NR_STR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_defaultPort",
class_filter: Some("Agent"),
runtime: "js_http_agent_default_port",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__set_protocol",
class_filter: Some("Agent"),
runtime: "js_http_agent_set_protocol",
args: &[NA_STR],
ret: NR_VOID,
},
// Bare-name dispatch for the same property reads. Mirrors the
// belt-and-braces approach used by IncomingMessage's `statusCode` /
// `headers` rows below — covers sites where the HIR rewrite to
// `__get_<prop>` doesn't fire (e.g. an agent assigned through a
// local before the property read).
NativeModSig {
module: "http",
has_receiver: true,
method: "maxSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_max_sockets",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "maxFreeSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_max_free_sockets",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "maxTotalSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_max_total_sockets",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "keepAliveMsecs",
class_filter: Some("Agent"),
runtime: "js_http_agent_keep_alive_msecs",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "keepAlive",
class_filter: Some("Agent"),
runtime: "js_http_agent_keep_alive",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "protocol",
class_filter: Some("Agent"),
runtime: "js_http_agent_protocol",
args: &[],
ret: NR_STR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "defaultPort",
class_filter: Some("Agent"),
runtime: "js_http_agent_default_port",
args: &[],
ret: NR_F64,
},
// ========== http.Agent / https.Agent (issue #2154) ==========
// Extra surface the #2129 first PR didn't cover: sockets /
// freeSockets / requests accessors (return empty objects),
// destroyed getter + destroy(), tunable property setters with
// RangeError-throwing validation, and createConnection /
// createSocket override storage.
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_sockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_sockets",
args: &[],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "sockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_sockets",
args: &[],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_freeSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_free_sockets",
args: &[],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "freeSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_free_sockets",
args: &[],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_requests",
class_filter: Some("Agent"),
runtime: "js_http_agent_requests",
args: &[],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "requests",
class_filter: Some("Agent"),
runtime: "js_http_agent_requests",
args: &[],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_destroyed",
class_filter: Some("Agent"),
runtime: "js_http_agent_destroyed",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "destroyed",
class_filter: Some("Agent"),
runtime: "js_http_agent_destroyed",
args: &[],
ret: NR_F64,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__set_maxSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_set_max_sockets",
args: &[NA_F64],
ret: NR_VOID,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__set_maxFreeSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_set_max_free_sockets",
args: &[NA_F64],
ret: NR_VOID,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__set_maxTotalSockets",
class_filter: Some("Agent"),
runtime: "js_http_agent_set_max_total_sockets",
args: &[NA_F64],
ret: NR_VOID,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__set_keepAlive",
class_filter: Some("Agent"),
runtime: "js_http_agent_set_keep_alive",
args: &[NA_F64],
ret: NR_VOID,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__set_keepAliveMsecs",
class_filter: Some("Agent"),
runtime: "js_http_agent_set_keep_alive_msecs",
args: &[NA_F64],
ret: NR_VOID,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__set_createConnection",
class_filter: Some("Agent"),
runtime: "js_http_agent_set_create_connection",
args: &[NA_PTR],
ret: NR_VOID,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__set_createSocket",
class_filter: Some("Agent"),
runtime: "js_http_agent_set_create_socket",
args: &[NA_PTR],
ret: NR_VOID,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_createConnection",
class_filter: Some("Agent"),
runtime: "js_http_agent_create_connection",
args: &[],
ret: NR_PTR,
},
NativeModSig {
module: "http",
has_receiver: true,
method: "__get_createSocket",
class_filter: Some("Agent"),
runtime: "js_http_agent_create_socket",
args: &[],
ret: NR_PTR,
},
];