@amritk/nish-aarch64-linux 0.35.0 → 0.37.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.
- package/INSTALL.md +73 -59
- package/bin/nish +0 -0
- package/docs/AI.md +50 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +4849 -430
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +252 -15
- package/std/README.md +107 -82
- package/std/base64.ts +34 -5
- package/std/bytes.ts +279 -59
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +128 -52
- package/std/crypto/base64url.ts +29 -5
- package/std/crypto/bcrypt-batch.ts +101 -34
- package/std/crypto/bcrypt.ts +93 -27
- package/std/crypto/chacha20poly1305.ts +69 -14
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +66 -16
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +242 -37
- package/std/crypto/jwt.ts +204 -72
- package/std/crypto/p256.ts +222 -72
- package/std/crypto/p384.ts +51 -23
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +99 -30
- package/std/crypto/rsa.ts +56 -22
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +163 -24
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +133 -66
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +31 -11
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +76 -26
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +126 -51
- package/std/json-typed.ts +757 -96
- package/std/json-value.ts +438 -157
- package/std/json.ts +170 -38
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +1267 -290
- package/std/net/handler.ts +296 -80
- package/std/net/hpack.ts +290 -77
- package/std/net/http-compress.ts +152 -36
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +129 -44
- package/std/net/http1-codec.ts +279 -114
- package/std/net/http1-server.ts +409 -139
- package/std/net/http2-frame.ts +289 -51
- package/std/net/http2-tls.ts +152 -49
- package/std/net/http2.ts +314 -160
- package/std/net/http3-frame.ts +165 -27
- package/std/net/http3-server.ts +282 -131
- package/std/net/http3.ts +377 -173
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +898 -260
- package/std/net/prefork.ts +202 -65
- package/std/net/qpack.ts +120 -32
- package/std/net/quic-conn-ack.ts +60 -12
- package/std/net/quic-conn-cid.ts +135 -27
- package/std/net/quic-conn-params.ts +109 -22
- package/std/net/quic-datagram.ts +50 -3
- package/std/net/quic-frame.ts +333 -23
- package/std/net/quic-listener.ts +161 -75
- package/std/net/quic-packet.ts +373 -73
- package/std/net/quic-recovery.ts +287 -65
- package/std/net/quic-stream.ts +436 -146
- package/std/net/quic.ts +693 -323
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +167 -51
- package/std/net/tls/codec.ts +494 -68
- package/std/net/tls/record-client.ts +140 -73
- package/std/net/tls/record-server.ts +233 -105
- package/std/net/tls/record.ts +142 -36
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +161 -40
- package/std/net/tls/verify.ts +57 -10
- package/std/net/tls-tcp.ts +308 -95
- package/std/net/tls.ts +276 -102
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +109 -22
- package/std/net/websocket.ts +140 -26
- package/std/net/webtransport.ts +243 -106
- package/std/pair.ts +10 -2
- package/std/random.ts +42 -15
- package/std/regex.ts +422 -257
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +229 -56
- package/std/sync/shm.ts +203 -23
- package/std/term-io.ts +154 -78
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +77 -35
- package/std/term-rate.ts +199 -118
- package/std/term.ts +400 -175
- package/std/testing.ts +130 -32
- package/std/text.ts +84 -17
- package/std/threads.ts +248 -56
- package/std/yaml-json.ts +111 -97
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +45 -30
- package/std/yaml.ts +764 -384
|
@@ -34,19 +34,19 @@
|
|
|
34
34
|
* }
|
|
35
35
|
*
|
|
36
36
|
* The events are `HTTP1_INFORMATIONAL` (an interim 1xx response was read; the
|
|
37
|
-
* final one follows), `HTTP1_HEAD` (the final response's status line and
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* on the split —
|
|
37
|
+
* final one follows), `HTTP1_HEAD` (the final response's status line and header
|
|
38
|
+
* section are in), `HTTP1_BODY` (some body bytes, de-chunked), `HTTP1_END` (the
|
|
39
|
+
* response is complete; with `keepAlive()` the next one follows),
|
|
40
|
+
* `HTTP1_UPGRADE` (a CONNECT was answered with 2xx, or a request that
|
|
41
|
+
* `expectUpgrade` named was answered with 101, and the connection is a tunnel
|
|
42
|
+
* now: `tunnelBytes()` answers what was fed past the head), `HTTP1_CLOSED` (the
|
|
43
|
+
* connection is done: the server closed it between responses, or the last
|
|
44
|
+
* response was not kept alive) and `HTTP1_ERROR`.
|
|
45
|
+
*
|
|
46
|
+
* The last three repeat on every later call. Only complete lines are acted on,
|
|
47
|
+
* body bytes are counted, never guessed, and every refusal is decided by the
|
|
48
|
+
* same byte wherever the input was cut, so the sequence of events, the
|
|
49
|
+
* concatenated body and the error code do not depend on the split —
|
|
50
50
|
* `tests/link/net_http1_client` feeds a corpus at every split point.
|
|
51
51
|
*
|
|
52
52
|
* **How a response ends** (RFC 9112 §6.3): a response to HEAD, a 1xx, 204 or
|
|
@@ -59,16 +59,18 @@
|
|
|
59
59
|
* **What it refuses**, each with its own code in `error`: a malformed status
|
|
60
60
|
* line, an HTTP major version other than 1, a bare LF, a malformed field line
|
|
61
61
|
* (an obs-fold, whitespace before the colon, a control byte in a value), a 101
|
|
62
|
-
* to a request that did not ask to switch protocols, `Transfer-Encoding`
|
|
63
|
-
* with `Content-Length`, a transfer coding other than one `chunked` or
|
|
64
|
-
* an HTTP/1.0 response, a `Content-Length` that is not a decimal or
|
|
65
|
-
* repeats disagree, a malformed chunk, a status line, header section,
|
|
66
|
-
* count, body or trailer section over the caller's limit, a chunk-size
|
|
67
|
-
* over `HTTP1_MAX_CHUNK_LINE` and more than `HTTP1_MAX_INFORMATIONAL`
|
|
68
|
-
* responses.
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
62
|
+
* to a request that did not ask to switch protocols, `Transfer-Encoding`
|
|
63
|
+
* together with `Content-Length`, a transfer coding other than one `chunked` or
|
|
64
|
+
* one in an HTTP/1.0 response, a `Content-Length` that is not a decimal or
|
|
65
|
+
* whose repeats disagree, a malformed chunk, a status line, header section,
|
|
66
|
+
* field count, body or trailer section over the caller's limit, a chunk-size
|
|
67
|
+
* line over `HTTP1_MAX_CHUNK_LINE` and more than `HTTP1_MAX_INFORMATIONAL`
|
|
68
|
+
* interim responses.
|
|
69
|
+
*
|
|
70
|
+
* Each of these is a response-smuggling or a resource shape, and each is
|
|
71
|
+
* refused rather than repaired: a client that repairs one differently from a
|
|
72
|
+
* proxy disagrees with it about where the next response starts. An error is
|
|
73
|
+
* final.
|
|
72
74
|
*
|
|
73
75
|
* Private helpers share the importing program's flat symbol namespace
|
|
74
76
|
* (`docs/wp26-stdlib.md` §3e), which is why each one carries the module's name.
|
|
@@ -384,8 +386,19 @@ const http1ClientPutField = (out: u8[], at: i32, names: string[], values: string
|
|
|
384
386
|
* `values` of different lengths; not exactly one `Host`; a `Content-Length` or
|
|
385
387
|
* `Transfer-Encoding` among the caller's fields, since the framing is decided
|
|
386
388
|
* here; a `Connection` that lists `upgrade`, which only
|
|
387
|
-
* `http1UpgradeRequestHead` may write; and a `bodyLength` below -2.
|
|
388
|
-
*
|
|
389
|
+
* `http1UpgradeRequestHead` may write; and a `bodyLength` below -2.
|
|
390
|
+
*
|
|
391
|
+
* Answers `HTTP1_NO_ROOM` when it is well formed but does not fit. Either way
|
|
392
|
+
* `out` is untouched.
|
|
393
|
+
*
|
|
394
|
+
* @param out The buffer the head is written into; nothing outside the head's bytes changes.
|
|
395
|
+
* @param at The index in `out` the request line starts at; a negative one answers `HTTP1_NO_ROOM`.
|
|
396
|
+
* @param method The request method, a token such as `GET`, written as given.
|
|
397
|
+
* @param target The request target in the form the method may send, written as given.
|
|
398
|
+
* @param names The field names, matched case-insensitively; exactly one is `Host`, which is written first, and the rest follow in order.
|
|
399
|
+
* @param values The value of each field in `names`, at the same index.
|
|
400
|
+
* @param bodyLength The body's length in bytes, or `HTTP1_CHUNKED` (-1) or `HTTP1_NO_BODY` (-2).
|
|
401
|
+
* @returns The index in `out` just past the empty line, or `HTTP1_REFUSED` or `HTTP1_NO_ROOM`.
|
|
389
402
|
*/
|
|
390
403
|
export const http1WriteRequestHead = (
|
|
391
404
|
out: u8[],
|
|
@@ -448,8 +461,15 @@ const http1ClientPutHead = (
|
|
|
448
461
|
}
|
|
449
462
|
|
|
450
463
|
/**
|
|
451
|
-
* `http1WriteRequestHead`'s head in an array of its own,
|
|
452
|
-
*
|
|
464
|
+
* `http1WriteRequestHead`'s head in an array of its own, sized to fit, so
|
|
465
|
+
* there is no room to run out of.
|
|
466
|
+
*
|
|
467
|
+
* @param method The request method, a token such as `GET`.
|
|
468
|
+
* @param target The request target in the form the method may send.
|
|
469
|
+
* @param names The field names; exactly one is `Host`, which is written first, and the rest follow in order.
|
|
470
|
+
* @param values The value of each field in `names`, at the same index.
|
|
471
|
+
* @param bodyLength The body's length in bytes, or `HTTP1_CHUNKED` (-1) or `HTTP1_NO_BODY` (-2).
|
|
472
|
+
* @returns The head, ending in the empty line, or `null` for everything `http1WriteRequestHead` refuses and for a head over 1 GiB.
|
|
453
473
|
*/
|
|
454
474
|
export const http1RequestHead = (
|
|
455
475
|
method: string,
|
|
@@ -468,6 +488,13 @@ export const http1RequestHead = (
|
|
|
468
488
|
* `Connection` among the caller's fields, which would contradict the two this
|
|
469
489
|
* writes. A response to it is read after `expect(false, false)` and then
|
|
470
490
|
* `expectUpgrade()`, so that its 101 answers `HTTP1_UPGRADE`.
|
|
491
|
+
*
|
|
492
|
+
* @param method The request method, a token; a WebSocket handshake sends `GET`.
|
|
493
|
+
* @param target The request target in the form the method may send.
|
|
494
|
+
* @param names The caller's field names; exactly one is `Host`, which is written first, and the rest follow in order, before the two upgrade fields.
|
|
495
|
+
* @param values The value of each field in `names`, at the same index.
|
|
496
|
+
* @param upgrade The protocol asked for, one token such as `websocket`; an empty one answers `null`.
|
|
497
|
+
* @returns The head, ending in the empty line, or `null` when any of the above is refused or the head is over 1 GiB.
|
|
471
498
|
*/
|
|
472
499
|
export const http1UpgradeRequestHead = (
|
|
473
500
|
method: string,
|
|
@@ -545,64 +572,81 @@ export class Http1ResponseParser {
|
|
|
545
572
|
* `fieldName`, `fieldValue`, `reasonText` and `header` answer in either mode.
|
|
546
573
|
*/
|
|
547
574
|
names: string[]
|
|
575
|
+
/** The field values, each beside its name in `names`. */
|
|
548
576
|
values: string[]
|
|
549
577
|
/**
|
|
550
578
|
* The response's reason phrase and kept fields, copied: `head[reasonStart ..
|
|
551
579
|
* reasonEnd)` is the reason, and field `i` is `head[spans[4i] ..
|
|
552
580
|
* spans[4i + 1])`, its name in lowercase, then `head[spans[4i + 2] ..
|
|
553
581
|
* spans[4i + 3])`, its value. Both arrays are reused from response to response.
|
|
582
|
+
* @internal
|
|
554
583
|
*/
|
|
555
584
|
head: u8[]
|
|
585
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
556
586
|
spans: i32[]
|
|
557
587
|
/** The buffer the last `HTTP1_BODY`'s bytes are in, at `bodyOff`, `bodyLen` long. */
|
|
558
588
|
body: u8[]
|
|
559
589
|
/** What was wrong, once `next()` said `HTTP1_ERROR`; for a log. */
|
|
560
590
|
errorText: string = ""
|
|
561
|
-
/** The bytes fed and not yet consumed are `buf[start .. end)`. */
|
|
591
|
+
/** The bytes fed and not yet consumed are `buf[start .. end)`. @internal */
|
|
562
592
|
buf: u8[]
|
|
563
593
|
|
|
564
594
|
// --- limits, the caller's --------------------------------------------------
|
|
595
|
+
/** The most body bytes a response may carry, de-chunked; past it the parser refuses. */
|
|
565
596
|
maxBody: i64 = 0
|
|
566
597
|
/** The declared body length, or -1 when the response has none or is chunked or read until close. */
|
|
567
598
|
contentLength: i64 = -1
|
|
568
|
-
/** Bytes left in a length-delimited body or in the current chunk. */
|
|
599
|
+
/** Bytes left in a length-delimited body or in the current chunk. @internal */
|
|
569
600
|
left: i64 = 0
|
|
570
601
|
/** De-chunked body bytes so far, against `maxBody`. */
|
|
571
602
|
bodyTotal: i64 = 0
|
|
603
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
572
604
|
maxStatusLine: i32 = 0
|
|
605
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
573
606
|
maxHeaderBytes: i32 = 0
|
|
607
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
574
608
|
maxHeaders: i32 = 0
|
|
609
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
575
610
|
maxTrailerBytes: i32 = 0
|
|
576
611
|
|
|
577
612
|
/** The status code of the response last read. */
|
|
578
613
|
status: i32 = 0
|
|
579
614
|
/** The minor version: 0 for HTTP/1.0, 1 for HTTP/1.1 and anything above it. */
|
|
580
615
|
minor: i32 = 1
|
|
616
|
+
/** Where the last `HTTP1_BODY`'s bytes start in `body`. */
|
|
581
617
|
bodyOff: i32 = 0
|
|
618
|
+
/** How many bytes the last `HTTP1_BODY` holds. */
|
|
582
619
|
bodyLen: i32 = 0
|
|
583
620
|
/** Why `next()` said `HTTP1_ERROR`: one of the `HTTP1_E_` codes. */
|
|
584
621
|
error: i32 = 0
|
|
585
622
|
|
|
586
623
|
// --- internal --------------------------------------------------------------
|
|
624
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
587
625
|
start: i32 = 0
|
|
626
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
588
627
|
end: i32 = 0
|
|
589
|
-
/** Where the search for the next LF resumes, so a line fed a byte at a time is scanned once. */
|
|
628
|
+
/** Where the search for the next LF resumes, so a line fed a byte at a time is scanned once. @internal */
|
|
590
629
|
scan: i32 = 0
|
|
630
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
591
631
|
state: i32 = 0
|
|
592
|
-
/** Bytes of the header or trailer section so far, against its limit. */
|
|
632
|
+
/** Bytes of the header or trailer section so far, against its limit. @internal */
|
|
593
633
|
sectionBytes: i32 = 0
|
|
594
|
-
/** Field lines of the response so far, its trailers included, against `maxHeaders`. */
|
|
634
|
+
/** Field lines of the response so far, its trailers included, against `maxHeaders`. @internal */
|
|
595
635
|
fieldCount: i32 = 0
|
|
596
|
-
/** Interim responses before this request's final one, against `HTTP1_MAX_INFORMATIONAL`. */
|
|
636
|
+
/** Interim responses before this request's final one, against `HTTP1_MAX_INFORMATIONAL`. @internal */
|
|
597
637
|
informational: i32 = 0
|
|
598
|
-
/** The line `http1ClientTakeLine` found is `buf[lineStart .. lineEnd)`, its CRLF dropped. */
|
|
638
|
+
/** The line `http1ClientTakeLine` found is `buf[lineStart .. lineEnd)`, its CRLF dropped. @internal */
|
|
599
639
|
lineStart: i32 = 0
|
|
640
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
600
641
|
lineEnd: i32 = 0
|
|
601
642
|
|
|
643
|
+
/** Whether the response's body is chunked. */
|
|
602
644
|
chunked: boolean = false
|
|
645
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
603
646
|
persistent: boolean = false
|
|
604
|
-
/** What `expect` said of the request this response answers. */
|
|
647
|
+
/** What `expect` said of the request this response answers: whether it was a HEAD. */
|
|
605
648
|
wasHead: boolean = false
|
|
649
|
+
/** What `expect` said of the request this response answers: whether it was a CONNECT. */
|
|
606
650
|
wasConnect: boolean = false
|
|
607
651
|
/** Whether `expectUpgrade` said the request asked to switch protocols. */
|
|
608
652
|
wasUpgrade: boolean = false
|
|
@@ -610,15 +654,23 @@ export class Http1ResponseParser {
|
|
|
610
654
|
closed: boolean = false
|
|
611
655
|
/** Whether `names`, `values` and `reason` are filled; `fieldsAsSpans()` clears it. */
|
|
612
656
|
keepStrings: boolean = true
|
|
613
|
-
/** Bytes of `head` in use, and the fields recorded in `spans`. */
|
|
657
|
+
/** Bytes of `head` in use, and the fields recorded in `spans`. @internal */
|
|
614
658
|
headUsed: i32 = 0
|
|
659
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
615
660
|
spanCount: i32 = 0
|
|
661
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
616
662
|
reasonStart: i32 = 0
|
|
663
|
+
/** @internal Parser state the module's `http1Client` helpers read and write. */
|
|
617
664
|
reasonEnd: i32 = 0
|
|
618
665
|
|
|
619
666
|
/**
|
|
620
667
|
* Each `i32` limit is clamped into 0 to 2^30 and `maxBody` into 0 to 2^53,
|
|
621
668
|
* so that the sums the parser makes of them cannot overflow.
|
|
669
|
+
* @param maxStatusLine The longest status line accepted, in bytes.
|
|
670
|
+
* @param maxHeaderBytes The most bytes the header section may take.
|
|
671
|
+
* @param maxHeaders The most field lines a response may carry, trailers included.
|
|
672
|
+
* @param maxBody The most body bytes a response may carry, de-chunked.
|
|
673
|
+
* @param maxTrailerBytes The most bytes the trailer section may take.
|
|
622
674
|
*/
|
|
623
675
|
constructor(maxStatusLine: i32, maxHeaderBytes: i32, maxHeaders: i32, maxBody: i64, maxTrailerBytes: i32) {
|
|
624
676
|
this.maxStatusLine = http1ClientClamp(maxStatusLine)
|
|
@@ -682,6 +734,8 @@ export class Http1ResponseParser {
|
|
|
682
734
|
* parser waits for a response's first status line, and the parser forgets it
|
|
683
735
|
* after that response's `HTTP1_END`; anywhere else it does nothing, so a
|
|
684
736
|
* pipelining caller says it once per response, after the last one's end.
|
|
737
|
+
* @param methodWasHead Whether the request was a HEAD, so the response has no body.
|
|
738
|
+
* @param wasConnect Whether the request was a CONNECT, so a 2xx opens a tunnel.
|
|
685
739
|
*/
|
|
686
740
|
expect(methodWasHead: boolean, wasConnect: boolean): void {
|
|
687
741
|
if (this.state === HTTP1_CLIENT_S_STATUS_LINE && this.informational === 0) {
|
|
@@ -712,6 +766,9 @@ export class Http1ResponseParser {
|
|
|
712
766
|
* Appends `data[off .. off + len)` to the input. A window outside `data`
|
|
713
767
|
* panics. After `finish()`, or once the parser has closed or refused, the
|
|
714
768
|
* input is dropped; in a tunnel it is kept for `tunnelBytes()`.
|
|
769
|
+
* @param data The bytes read from the connection.
|
|
770
|
+
* @param off Where the new bytes start in `data`.
|
|
771
|
+
* @param len How many bytes to append.
|
|
715
772
|
*/
|
|
716
773
|
feed(data: u8[], off: i32, len: i32): void {
|
|
717
774
|
const size: i32 = toI32(data.length)
|
|
@@ -736,7 +793,10 @@ export class Http1ResponseParser {
|
|
|
736
793
|
this.closed = true
|
|
737
794
|
}
|
|
738
795
|
|
|
739
|
-
/**
|
|
796
|
+
/**
|
|
797
|
+
* The next event the input holds; see the module comment.
|
|
798
|
+
* @returns An `HTTP1_` event, `HTTP1_NEED_MORE` when the input runs out.
|
|
799
|
+
*/
|
|
740
800
|
next(): i32 {
|
|
741
801
|
const event: i32 = http1ClientNext(this)
|
|
742
802
|
if (event !== HTTP1_NEED_MORE || !this.closed) {
|
|
@@ -757,12 +817,17 @@ export class Http1ResponseParser {
|
|
|
757
817
|
* ended (RFC 9112 §9.3): a 1.1 response unless `Connection` lists `close`,
|
|
758
818
|
* a 1.0 response only when it lists `keep-alive`, and never one read until
|
|
759
819
|
* close, a tunnel or an error.
|
|
820
|
+
* @returns Whether the connection may be reused.
|
|
760
821
|
*/
|
|
761
822
|
keepAlive(): boolean {
|
|
762
823
|
return this.persistent
|
|
763
824
|
}
|
|
764
825
|
|
|
765
|
-
/**
|
|
826
|
+
/**
|
|
827
|
+
* The value of the first field named `name` (any case).
|
|
828
|
+
* @param name The field name to look for.
|
|
829
|
+
* @returns The field's value, OWS trimmed, or `null` when the response has no such field.
|
|
830
|
+
*/
|
|
766
831
|
header(name: string): string | null {
|
|
767
832
|
for (let i: i32 = 0; i < this.spanCount; i += 1) {
|
|
768
833
|
if (http1ClientHeadSameWord(this.head, this.spans[i * 4], this.spans[i * 4 + 1], name)) {
|
|
@@ -772,12 +837,19 @@ export class Http1ResponseParser {
|
|
|
772
837
|
return null
|
|
773
838
|
}
|
|
774
839
|
|
|
775
|
-
/**
|
|
840
|
+
/**
|
|
841
|
+
* How many fields the response last read has; trailers are not kept.
|
|
842
|
+
* @returns The number of fields, which `fieldName` and `fieldValue` index.
|
|
843
|
+
*/
|
|
776
844
|
fields(): i32 {
|
|
777
845
|
return this.spanCount
|
|
778
846
|
}
|
|
779
847
|
|
|
780
|
-
/**
|
|
848
|
+
/**
|
|
849
|
+
* Field `i`'s name, in lowercase, as a fresh string.
|
|
850
|
+
* @param i The field's index, from 0 to below `fields()`.
|
|
851
|
+
* @returns The name, or "" past the last field.
|
|
852
|
+
*/
|
|
781
853
|
fieldName(i: i32): string {
|
|
782
854
|
if (i < 0 || i >= this.spanCount) {
|
|
783
855
|
return ""
|
|
@@ -785,7 +857,11 @@ export class Http1ResponseParser {
|
|
|
785
857
|
return http1Text(this.head, this.spans[i * 4], this.spans[i * 4 + 1], false)
|
|
786
858
|
}
|
|
787
859
|
|
|
788
|
-
/**
|
|
860
|
+
/**
|
|
861
|
+
* Field `i`'s value, OWS trimmed, as a fresh string.
|
|
862
|
+
* @param i The field's index, from 0 to below `fields()`.
|
|
863
|
+
* @returns The value, or "" past the last field.
|
|
864
|
+
*/
|
|
789
865
|
fieldValue(i: i32): string {
|
|
790
866
|
if (i < 0 || i >= this.spanCount) {
|
|
791
867
|
return ""
|
|
@@ -793,7 +869,10 @@ export class Http1ResponseParser {
|
|
|
793
869
|
return http1Text(this.head, this.spans[i * 4 + 2], this.spans[i * 4 + 3], false)
|
|
794
870
|
}
|
|
795
871
|
|
|
796
|
-
/**
|
|
872
|
+
/**
|
|
873
|
+
* The reason phrase, as a fresh string.
|
|
874
|
+
* @returns The reason phrase of the response last read, "" when it had none.
|
|
875
|
+
*/
|
|
797
876
|
reasonText(): string {
|
|
798
877
|
if (this.reasonEnd <= this.reasonStart) {
|
|
799
878
|
return ""
|
|
@@ -801,12 +880,18 @@ export class Http1ResponseParser {
|
|
|
801
880
|
return http1Text(this.head, this.reasonStart, this.reasonEnd, false)
|
|
802
881
|
}
|
|
803
882
|
|
|
804
|
-
/**
|
|
883
|
+
/**
|
|
884
|
+
* How many bytes were fed and not consumed yet.
|
|
885
|
+
* @returns The count of unread input bytes.
|
|
886
|
+
*/
|
|
805
887
|
buffered(): i32 {
|
|
806
888
|
return this.end - this.start
|
|
807
889
|
}
|
|
808
890
|
|
|
809
|
-
/**
|
|
891
|
+
/**
|
|
892
|
+
* In a tunnel: every byte fed past the response head, as a fresh array.
|
|
893
|
+
* @returns The bytes, or an empty array outside a tunnel.
|
|
894
|
+
*/
|
|
810
895
|
tunnelBytes(): u8[] {
|
|
811
896
|
let n: i32 = this.end - this.start
|
|
812
897
|
if (n < 0 || this.state !== HTTP1_CLIENT_S_TUNNEL) {
|