@amritk/nish-aarch64-linux 0.36.0 → 0.38.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.
Files changed (103) hide show
  1. package/INSTALL.md +92 -71
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +75 -14
  4. package/package.json +1 -1
  5. package/runtime/async.d.mts +2 -0
  6. package/runtime/async.mjs +7 -0
  7. package/runtime/core/arrays.d.ts +4 -0
  8. package/runtime/core/arrays.mjs +33 -0
  9. package/runtime/nish.d.ts +1045 -512
  10. package/runtime/nish.h +53 -6
  11. package/runtime/page.d.ts +53 -0
  12. package/runtime/page.mjs +146 -0
  13. package/runtime/runtime-async.c +740 -0
  14. package/runtime/runtime-cross.c +2 -1
  15. package/runtime/runtime-region.c +85 -7
  16. package/runtime/runtime-text.c +1068 -0
  17. package/runtime/runtime-wasm.c +65 -9
  18. package/runtime/runtime.c +50 -961
  19. package/runtime/vite.mjs +48 -11
  20. package/scripts/build.sh +231 -31
  21. package/std/LICENSE-fdlibm +8 -0
  22. package/std/README.md +109 -82
  23. package/std/array.ts +266 -0
  24. package/std/bytes.ts +23 -19
  25. package/std/compress/checksum.ts +1 -1
  26. package/std/crypto/aes.ts +48 -43
  27. package/std/crypto/base64url.ts +7 -5
  28. package/std/crypto/bcrypt-batch.ts +13 -13
  29. package/std/crypto/bcrypt.ts +33 -27
  30. package/std/crypto/chacha20poly1305.ts +16 -14
  31. package/std/crypto/ed25519.ts +19 -16
  32. package/std/crypto/hmac.ts +7 -6
  33. package/std/crypto/jwt.ts +23 -20
  34. package/std/crypto/p256.ts +63 -56
  35. package/std/crypto/p384.ts +23 -20
  36. package/std/crypto/pki.ts +18 -15
  37. package/std/crypto/rsa.ts +23 -19
  38. package/std/crypto/x25519.ts +11 -10
  39. package/std/crypto/x509.ts +69 -62
  40. package/std/host/ring.ts +124 -0
  41. package/std/host/text.ts +86 -0
  42. package/std/json-equal.ts +12 -11
  43. package/std/json-number.ts +12 -12
  44. package/std/json-tokenizer.ts +26 -22
  45. package/std/json-typed.ts +92 -78
  46. package/std/json-value.ts +38 -33
  47. package/std/json.ts +32 -28
  48. package/std/math.ts +743 -41
  49. package/std/net/dns-resolver.ts +46 -6
  50. package/std/net/dns.ts +50 -13
  51. package/std/net/fetch.ts +1744 -295
  52. package/std/net/handler.ts +30 -0
  53. package/std/net/hpack.ts +29 -26
  54. package/std/net/http-compress.ts +42 -28
  55. package/std/net/http-fields.ts +19 -4
  56. package/std/net/http1-client-codec.ts +29 -25
  57. package/std/net/http1-codec.ts +62 -91
  58. package/std/net/http1-server.ts +79 -57
  59. package/std/net/http2-frame.ts +17 -16
  60. package/std/net/http2-tls.ts +17 -15
  61. package/std/net/http2.ts +67 -54
  62. package/std/net/http3-frame.ts +11 -10
  63. package/std/net/http3-server.ts +36 -35
  64. package/std/net/http3.ts +70 -58
  65. package/std/net/postgres-async.ts +1005 -0
  66. package/std/net/postgres.ts +185 -164
  67. package/std/net/prefork.ts +38 -34
  68. package/std/net/qpack.ts +15 -14
  69. package/std/net/quic-conn-ack.ts +1 -0
  70. package/std/net/quic-conn-cid.ts +11 -0
  71. package/std/net/quic-conn-params.ts +41 -14
  72. package/std/net/quic-datagram.ts +7 -0
  73. package/std/net/quic-frame.ts +48 -12
  74. package/std/net/quic-listener.ts +61 -44
  75. package/std/net/quic-packet.ts +71 -52
  76. package/std/net/quic-recovery.ts +59 -21
  77. package/std/net/quic-stream.ts +83 -55
  78. package/std/net/quic.ts +204 -152
  79. package/std/net/serve.ts +763 -0
  80. package/std/net/tls/client.ts +1 -0
  81. package/std/net/tls/codec.ts +81 -12
  82. package/std/net/tls/record-client.ts +30 -18
  83. package/std/net/tls/record-server.ts +74 -46
  84. package/std/net/tls/record.ts +33 -24
  85. package/std/net/tls/ticket.ts +2 -0
  86. package/std/net/tls/verify.ts +8 -7
  87. package/std/net/tls-tcp.ts +58 -50
  88. package/std/net/tls.ts +55 -43
  89. package/std/net/url.ts +12 -9
  90. package/std/net/websocket.ts +23 -19
  91. package/std/net/webtransport.ts +24 -18
  92. package/std/random.ts +8 -6
  93. package/std/regex.ts +70 -59
  94. package/std/sync/ring.ts +24 -21
  95. package/std/sync/shm.ts +9 -7
  96. package/std/term-io.ts +17 -14
  97. package/std/term-probe.ts +11 -10
  98. package/std/term-rate.ts +71 -61
  99. package/std/term.ts +73 -59
  100. package/std/text.ts +242 -15
  101. package/std/threads.ts +19 -15
  102. package/std/yaml-json.ts +17 -15
  103. package/std/yaml-write.ts +21 -14
@@ -227,9 +227,13 @@ export class HttpRequest {
227
227
  * @internal Set by `HttpHandler` in this module after routing; the param accessors check `k` against it.
228
228
  */
229
229
  paramCount: i32 = 0
230
+ /** Where the method starts in `head`; the method is `head[methodStart .. methodEnd)`, for a log line or a `Router.match`. */
230
231
  methodStart: i32 = 0
232
+ /** Where the method ends in `head`, one past its last byte. */
231
233
  methodEnd: i32 = 0
234
+ /** Where the request target (path and query) starts in `head`; the target is `head[targetStart .. targetEnd)`. */
232
235
  targetStart: i32 = 0
236
+ /** Where the request target ends in `head`, one past its last byte. */
233
237
  targetEnd: i32 = 0
234
238
  /**
235
239
  * Where the path ends: the target's first `?`, or its end.
@@ -241,9 +245,14 @@ export class HttpRequest {
241
245
  * @internal Set by `HttpHandler` in this module when it copies the head, and read by `header`.
242
246
  */
243
247
  headerCount: i32 = 0
248
+ /** How many bytes of `body` are the request's body, 0 for none; read the body as `body[0 .. bodyLength)`. */
244
249
  bodyLength: i32 = 0
245
250
  /** The connection's slot, and its generation when this request was read. */
246
251
  slot: i32 = 0
252
+ /**
253
+ * The slot's generation when this request was read.
254
+ * @internal Read by `HttpHandler` in this module, which drops a reply to a slot that has since closed and been reused.
255
+ */
247
256
  gen: i32 = 0
248
257
  /** Its index in the handler's pool. */
249
258
  index: i32 = 0
@@ -385,6 +394,7 @@ export class HttpRequest {
385
394
 
386
395
  /** The span `queryIndex` found, raw. */
387
396
  queryValueStart: i32 = 0
397
+ /** Where the raw value `queryIndex` found ends in `head`, one past its last byte; it starts at `queryValueStart`. */
388
398
  queryValueEnd: i32 = 0
389
399
 
390
400
  /**
@@ -463,6 +473,10 @@ export class HttpRequest {
463
473
  * requests. One per thread; nothing in it is shared.
464
474
  */
465
475
  export class HttpHandler {
476
+ /**
477
+ * The HTTP/1.1 carrier the handler drives.
478
+ * @internal Read only by this class, which accepts, reads, flushes and closes connections through it.
479
+ */
466
480
  server: Http1Server
467
481
  private router: Router
468
482
  /** Every request the pool has made, and the indices of the free ones. */
@@ -480,6 +494,10 @@ export class HttpHandler {
480
494
  private watchedFired: boolean[]
481
495
  /** `json` and `problem` write here. */
482
496
  scratch: u8[]
497
+ /**
498
+ * The JSON writer over `scratch`.
499
+ * @internal Read only by this class; programs get it from `json`.
500
+ */
483
501
  writer: JsonWriter
484
502
  /** `refuse`'s scratch for `Router.match`. */
485
503
  private probe: i32[]
@@ -1043,6 +1061,18 @@ export class HttpHandler {
1043
1061
  return r
1044
1062
  }
1045
1063
 
1064
+ /**
1065
+ * Whether the client of `r` has hung up: its connection is closed or
1066
+ * reused, or the peer ended its stream while `r` is held. A half-close
1067
+ * counts, as nginx counts it, so a hung task is cancelled rather than
1068
+ * kept for a reader who may be gone.
1069
+ * @param r a request `take` handed over
1070
+ * @returns true once `r`'s connection is closed or reused, or its peer's stream has ended
1071
+ */
1072
+ hungUp(r: HttpRequest): boolean {
1073
+ return !this.live(r) || this.server.connection(r.slot).ended()
1074
+ }
1075
+
1046
1076
  /** Whether `r`'s connection is the one it was read on, still open. */
1047
1077
  private live(r: HttpRequest): boolean {
1048
1078
  return this.server.holds(r.slot) && this.slotGen[r.slot] === r.gen
package/std/net/hpack.ts CHANGED
@@ -35,12 +35,13 @@
35
35
  * end of the tables, Huffman padding longer than seven bits or not all ones,
36
36
  * the EOS symbol inside a string, a table size update above the SETTINGS limit
37
37
  * or after the block's first field, and a block that does not begin with the
38
- * update a lowered limit requires (§4.2). Each of those is HTTP/2's
39
- * COMPRESSION_ERROR, which closes the connection, so the code is sticky: every
40
- * later `decode` answers it again without reading anything. So is
41
- * `HPACK_ERR_COPY_BUDGET`, a block that would make the table copy more than
42
- * `HPACK_COPY_FACTOR` times the larger of its size and the block's length,
43
- * which HTTP/2 answers with ENHANCE_YOUR_CALM.
38
+ * update a lowered limit requires (§4.2).
39
+ *
40
+ * Each of those is HTTP/2's COMPRESSION_ERROR, which closes the connection, so
41
+ * the code is sticky: every later `decode` answers it again without reading
42
+ * anything. So is `HPACK_ERR_COPY_BUDGET`, a block that would make the table
43
+ * copy more than `HPACK_COPY_FACTOR` times the larger of its size and the
44
+ * block's length, which HTTP/2 answers with ENHANCE_YOUR_CALM.
44
45
  *
45
46
  * A header list larger than the caller's limit is not one of them. The block
46
47
  * is still decoded to its end, so that the table stays in step with the
@@ -777,14 +778,15 @@ export const hpackDecodeString = (h: HpackHuffman, c: HpackCursor, out: u8[]): i
777
778
  * oldest entry first. An index says where each entry sits, two numbers to an
778
779
  * entry — where it starts in `bytes` and how long its name is; its value runs
779
780
  * to where the next one starts — oldest first from entry `first` on, so that
780
- * adding one is two `push`es and evicting one moves `first`. The evicted
781
- * prefix of the index, and of `bytes`, is shifted out in place once it is half
782
- * of either, which keeps both amortised constant time without a ring's index
783
- * arithmetic. Shifting and popping keep an array's storage, and `bytes` never
784
- * holds more than three times `maxSize`, so a table the peer fills and empties
785
- * for as long as it likes stops allocating once its arrays have grown that far
786
- * (`docs/security/http2.md`, H2-1). Dynamic index 1, the newest entry, is the
787
- * last.
781
+ * adding one is two `push`es and evicting one moves `first`.
782
+ *
783
+ * The evicted prefix of the index, and of `bytes`, is shifted out in place once
784
+ * it is half of either, which keeps both amortised constant time without a
785
+ * ring's index arithmetic. Shifting and popping keep an array's storage, and
786
+ * `bytes` never holds more than three times `maxSize`, so a table the peer
787
+ * fills and empties for as long as it likes stops allocating once its arrays
788
+ * have grown that far (`docs/security/http2.md`, H2-1). Dynamic index 1, the
789
+ * newest entry, is the last.
788
790
  */
789
791
  export class HpackTable {
790
792
  /**
@@ -1109,21 +1111,22 @@ export class HpackWork {
1109
1111
  * One HTTP/2 connection's receiving side: its dynamic table, the SETTINGS
1110
1112
  * limit the table may grow to, and the header-list limit.
1111
1113
  *
1112
- * `decode` answers the block's fields in `names`, `values` and
1113
- * `neverIndexed`, which it empties and refills on every call. Each name and
1114
- * value is an array the decoder owns, taken from its working storage's pools
1115
- * by its length and given back, emptied, at the next block, so **a field is
1116
- * valid until the next `decode`**: a caller that keeps one past it copies it,
1117
- * since the next block may refill the same array with another field. That is
1118
- * what keeps the storage a peer can make a connection hold bounded by the
1119
- * header-list limit, however many blocks it sends and whatever becomes of
1114
+ * `decode` answers the block's fields in `names`, `values` and `neverIndexed`,
1115
+ * which it empties and refills on every call. Each name and value is an array
1116
+ * the decoder owns, taken from its working storage's pools by its length and
1117
+ * given back, emptied, at the next block, so **a field is valid until the next
1118
+ * `decode`**: a caller that keeps one past it copies it, since the next block
1119
+ * may refill the same array with another field.
1120
+ *
1121
+ * That is what keeps the storage a peer can make a connection hold bounded by
1122
+ * the header-list limit, however many blocks it sends and whatever becomes of
1120
1123
  * their streams (`docs/security/http2.md`, H2-1): a class `j` array holds a
1121
1124
  * field of at least 2^(j-1) octets, so no class ever holds more than about
1122
- * twice the limit, and only the classes up to log2 of the limit, plus one,
1123
- * hold any. `settingsLimit` is the SETTINGS_HEADER_TABLE_SIZE this endpoint
1125
+ * twice the limit, and only the classes up to log2 of the limit, plus one, hold
1126
+ * any. `settingsLimit` is the SETTINGS_HEADER_TABLE_SIZE this endpoint
1124
1127
  * advertised and the peer acknowledged; the table starts at it.
1125
- * `maxHeaderListSize` counts each field as its name, its value and 32 bytes,
1126
- * as SETTINGS_MAX_HEADER_LIST_SIZE does (RFC 9113 §6.5.2).
1128
+ * `maxHeaderListSize` counts each field as its name, its value and 32 bytes, as
1129
+ * SETTINGS_MAX_HEADER_LIST_SIZE does (RFC 9113 §6.5.2).
1127
1130
  */
1128
1131
  export class HpackDecoder {
1129
1132
  /** The dynamic table, as the blocks decoded so far have left it. */
@@ -23,18 +23,20 @@
23
23
  * its `minLength`, longer than its `maxLength`, or that gzip would not make
24
24
  * smaller, answering -1 so the program sends the bytes as they are.
25
25
  *
26
- * **Compression that pays for itself.** A body is sent compressed only when
27
- * it saves at least `minSaving` bytes and `minSavingPercent` percent of the
28
- * body; otherwise the compressed bytes are dropped and the body goes as it
29
- * is. With `segmentMode` set, `respondEncoded` also sends it compressed only
30
- * when the whole response, head included, takes fewer TCP segments of `mss`
31
- * bytes (the connection's `mss` if set, else the compressor's, 1448 by
32
- * default): a 1300-byte body that gzips to 700 still fits in one segment
33
- * either way. After each call `decision` says why (`HTTP_COMPRESS_SENT`,
34
- * `_NOT_ACCEPTED`, `_TOO_SMALL`, `_TOO_LARGE`, `_TOO_LITTLE_SAVED`,
35
- * `_NO_FEWER_SEGMENTS`), for a program to count. A response whose identity
36
- * form already fits one segment is `_NO_FEWER_SEGMENTS` without running gzip
37
- * at all, as no compression could take fewer.
26
+ * **Compression that pays for itself.** A body is sent compressed only when it
27
+ * saves at least `minSaving` bytes and `minSavingPercent` percent of the body;
28
+ * otherwise the compressed bytes are dropped and the body goes as it is. With
29
+ * `segmentMode` set, `respondEncoded` also sends it compressed only when the
30
+ * whole response, head included, takes fewer TCP segments of `mss` bytes (the
31
+ * connection's `mss` if set, else the compressor's `mss` if set, else the MSS
32
+ * the server read from the socket, else `HTTP_DEFAULT_MSS`, 1448): a
33
+ * 1300-byte body that gzips to 700 still fits in one segment either way.
34
+ *
35
+ * After each call `decision` says why (`HTTP_COMPRESS_SENT`, `_NOT_ACCEPTED`,
36
+ * `_TOO_SMALL`, `_TOO_LARGE`, `_TOO_LITTLE_SAVED`, `_NO_FEWER_SEGMENTS`), for a
37
+ * program to count. A response whose identity form already fits one segment is
38
+ * `_NO_FEWER_SEGMENTS` without running gzip at all, as no compression could
39
+ * take fewer.
38
40
  *
39
41
  * **Two encoders.** Bodies up to `fixedLimit` (16 KB) go through
40
42
  * `GzipFixedCompressor`: one fixed-Huffman block, a 16 KB window, no state
@@ -51,15 +53,17 @@
51
53
  *
52
54
  * **Negotiation** (`httpAcceptEncoding`) follows §12.5.3: each listed coding
53
55
  * with its q-value, `x-gzip` as `gzip`, `*` for every coding not listed, and
54
- * `identity` acceptable unless it is given q=0, directly or through `*`. Of
55
- * the codings the program offers, the most preferred with q above 0 wins, the
56
- * program's order (gzip, then deflate) breaking ties; it beats `identity` at
57
- * an equal q, and beats an `identity` the field does not mention at any q. With no field at all the answer is
58
- * `HTTP_CODING_IDENTITY` (the RFC allows any coding then, but a client that
59
- * says nothing is safest sent nothing it may not read); an empty field asks
60
- * for identity too. `HTTP_CODING_NONE` means nothing offered is acceptable
61
- * and identity is refused: a server may answer 406 or send identity anyway.
62
- * A malformed element is skipped. The parser allocates nothing.
56
+ * `identity` acceptable unless it is given q=0, directly or through `*`.
57
+ *
58
+ * Of the codings the program offers, the most preferred with q above 0 wins,
59
+ * the program's order (gzip, then deflate) breaking ties; it beats `identity`
60
+ * at an equal q, and beats an `identity` the field does not mention at any q.
61
+ * With no field at all the answer is `HTTP_CODING_IDENTITY` (the RFC allows any
62
+ * coding then, but a client that says nothing is safest sent nothing it may not
63
+ * read); an empty field asks for identity too. `HTTP_CODING_NONE` means nothing
64
+ * offered is acceptable and identity is refused: a server may answer 406 or
65
+ * send identity anyway. A malformed element is skipped. The parser allocates
66
+ * nothing.
63
67
  *
64
68
  * **Compressing allocates nothing** and caches nothing between responses:
65
69
  * `HttpCompressor` holds a `GzipCompressor`, a `GzipFixedCompressor`, an
@@ -406,6 +410,7 @@ export class HttpCompressor {
406
410
  readonly output: u8[]
407
411
  /** The fields `addFields` built: the program's, then `Content-Encoding` and `Vary`. */
408
412
  readonly names: u8[][]
413
+ /** The value of each field in `names`, at the same index; pass both to `respond`. */
409
414
  readonly values: u8[][]
410
415
  private readonly contentEncodingName: u8[]
411
416
  private readonly gzipValue: u8[]
@@ -420,6 +425,7 @@ export class HttpCompressor {
420
425
  * default (any saving at all); a value below those counts as them.
421
426
  */
422
427
  minSaving: i32
428
+ /** The percent of the body a compressed body must save, as well as `minSaving` bytes: 0 by default, 100 or more sends nothing compressed. */
423
429
  minSavingPercent: i32
424
430
  /**
425
431
  * Whether `addFields` adds `Vary: Accept-Encoding` (RFC 9110 §12.5.5), which
@@ -430,10 +436,17 @@ export class HttpCompressor {
430
436
  /**
431
437
  * Whether `respondEncoded` also sends the compressed response only when,
432
438
  * head included, it takes fewer TCP segments of `mss` bytes than the body
433
- * as it is; off by default. `mss` is `HTTP_DEFAULT_MSS` unless the program
434
- * sets it, or a connection's own `mss` overrides it.
439
+ * as it is; off by default. Segments are the connection's own `mss` if the
440
+ * program set it, else this compressor's `mss` if set, else the socket's MSS
441
+ * the server read on accept, else `HTTP_DEFAULT_MSS`.
435
442
  */
436
443
  segmentMode: boolean
444
+ /**
445
+ * The TCP segment size `segmentMode` counts in, in bytes, when the program
446
+ * sets it: 0 (the default) or less means unset, so a connection's socket MSS
447
+ * is used, or `HTTP_DEFAULT_MSS` where there is none. A value set here wins
448
+ * over the socket's; a connection's own `mss` wins over it.
449
+ */
437
450
  mss: i32
438
451
  /** `HTTP_ENCODER_AUTO` (the default), `HTTP_ENCODER_FIXED` or `HTTP_ENCODER_LEVEL`. */
439
452
  encoder: i32
@@ -479,7 +492,7 @@ export class HttpCompressor {
479
492
  this.minSaving = 1
480
493
  this.minSavingPercent = 0
481
494
  this.segmentMode = false
482
- this.mss = HTTP_DEFAULT_MSS
495
+ this.mss = 0
483
496
  this.encoder = HTTP_ENCODER_AUTO
484
497
  this.fixedLimit = 16384
485
498
  this.decision = HTTP_COMPRESS_NOT_ACCEPTED
@@ -604,10 +617,11 @@ export class HttpCompressor {
604
617
  /**
605
618
  * `segmentMode`'s rule, for a response of `identityBytes` bytes sent as it
606
619
  * is or `encodedBytes` compressed, heads included, at `mss` bytes a segment
607
- * (`this.mss` when 0 or less): whether the compressed one takes fewer
608
- * segments. When it does not, `decision` becomes
609
- * `HTTP_COMPRESS_NO_FEWER_SEGMENTS`. `respondEncoded` calls it; a program
610
- * driving HTTP/2 or HTTP/3 by hand may with its own head sizes.
620
+ * (`this.mss` when 0 or less, and `HTTP_DEFAULT_MSS` when both are, as
621
+ * `segmentSize` reads it): whether the compressed one takes fewer segments.
622
+ * When it does not, `decision` becomes `HTTP_COMPRESS_NO_FEWER_SEGMENTS`.
623
+ * `respondEncoded` calls it; a program driving HTTP/2 or HTTP/3 by hand may
624
+ * with its own head sizes.
611
625
  *
612
626
  * @param identityBytes the whole response's length sent uncompressed, head
613
627
  * included, in bytes
@@ -48,7 +48,11 @@
48
48
  * compared without case (`HTTP_FIELDS_AUTHORITY_MISMATCH`);
49
49
  * - a `content-length` that is not one run of at most eighteen digits, or two
50
50
  * that disagree (`HTTP_FIELDS_BAD_CONTENT_LENGTH`). Matching it against
51
- * the body is the version's job, since only it sees the body.
51
+ * the body is the version's job, since only it sees the body;
52
+ * - in a section a program sends, a second `date` field: `Date` is a
53
+ * singleton (RFC 9110 §5.3, §6.6.1) whose value holds a comma, so two
54
+ * cannot be combined into one and a reader cannot tell which to believe
55
+ * (`HTTP_FIELDS_DATE_REPEATED`).
52
56
  *
53
57
  * **The date.** `httpDateWrite` writes a second since 1970 as an IMF-fixdate
54
58
  * (RFC 9110 §5.6.7), `Fri, 16 Oct 2026 08:11:54 GMT`, the form every version's
@@ -102,6 +106,9 @@ export const HTTP_FIELDS_AUTHORITY_MISMATCH: i32 = -10
102
106
  /** A `content-length` that is not a run of digits, or two that disagree. */
103
107
  export const HTTP_FIELDS_BAD_CONTENT_LENGTH: i32 = -11
104
108
 
109
+ /** A `date` field that a section about to be sent holds more than once (RFC 9110 §5.3). */
110
+ export const HTTP_FIELDS_DATE_REPEATED: i32 = -12
111
+
105
112
  /** `contentLength` when the section has no `content-length`. */
106
113
  export const HTTP_FIELDS_NO_LENGTH: i64 = -1
107
114
 
@@ -380,9 +387,10 @@ const httpFieldsHasUserinfo = (authority: u8[]): boolean => {
380
387
  /**
381
388
  * Checks a field section a program is about to send, pseudo-headers left
382
389
  * out: every name valid and in lowercase, every value valid, nothing
383
- * connection-specific, and as many values as names. Answers `HTTP_FIELDS_OK`
384
- * or the first refusal. A version's writer refuses what this refuses, so
385
- * that a program's string can never reach the wire as a field it was not.
390
+ * connection-specific, at most one `date` (a singleton, RFC 9110 §5.3), and
391
+ * as many values as names. Answers `HTTP_FIELDS_OK` or the first refusal. A
392
+ * version's writer refuses what this refuses, so that a program's string can
393
+ * never reach the wire as a field it was not.
386
394
  *
387
395
  * @param names the regular field names about to be sent, in order
388
396
  * @param values the value for each name, at the same index
@@ -395,6 +403,7 @@ export const httpFieldsCheckOutgoing = (names: u8[][], values: u8[][]): i32 => {
395
403
  if (n !== toI32(values.length)) {
396
404
  return HTTP_FIELDS_BAD_VALUE
397
405
  }
406
+ let dated: boolean = false
398
407
  for (let k: i32 = 0; k < n && k < toI32(names.length) && k < toI32(values.length); k++) {
399
408
  const name: u8[] = names[k]
400
409
  const value: u8[] = values[k]
@@ -407,6 +416,12 @@ export const httpFieldsCheckOutgoing = (names: u8[][], values: u8[][]): i32 => {
407
416
  if (httpFieldConnectionSpecific(name, value)) {
408
417
  return HTTP_FIELDS_CONNECTION_SPECIFIC
409
418
  }
419
+ if (httpFieldIs(name, "date")) {
420
+ if (dated) {
421
+ return HTTP_FIELDS_DATE_REPEATED
422
+ }
423
+ dated = true
424
+ }
410
425
  }
411
426
  return HTTP_FIELDS_OK
412
427
  }
@@ -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
- * header section are in), `HTTP1_BODY` (some body bytes, de-chunked),
39
- * `HTTP1_END` (the response is complete; with `keepAlive()` the next one
40
- * follows), `HTTP1_UPGRADE` (a CONNECT was answered with 2xx, or a request
41
- * that `expectUpgrade` named was answered with 101, and the connection is a
42
- * tunnel now: `tunnelBytes()` answers what was fed past the head),
43
- * `HTTP1_CLOSED` (the connection is done: the server closed it between
44
- * responses, or the last response was not kept alive) and
45
- * `HTTP1_ERROR`. The last three repeat on every later call. Only complete
46
- * lines are acted on, body bytes are counted, never guessed, and every
47
- * refusal is decided by the same byte wherever the input was cut, so the
48
- * sequence of events, the concatenated body and the error code do not depend
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` together
63
- * with `Content-Length`, a transfer coding other than one `chunked` or one in
64
- * an HTTP/1.0 response, a `Content-Length` that is not a decimal or whose
65
- * repeats disagree, a malformed chunk, a status line, header section, field
66
- * count, body or trailer section over the caller's limit, a chunk-size line
67
- * over `HTTP1_MAX_CHUNK_LINE` and more than `HTTP1_MAX_INFORMATIONAL` interim
68
- * responses. Each of these is a response-smuggling or a resource shape, and
69
- * each is refused rather than repaired: a client that repairs one differently
70
- * from a proxy disagrees with it about where the next response starts. An
71
- * error is final.
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,10 @@ 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. Answers
388
- * `HTTP1_NO_ROOM` when it is well formed but does not fit. Either way `out` is untouched.
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.
389
393
  *
390
394
  * @param out The buffer the head is written into; nothing outside the head's bytes changes.
391
395
  * @param at The index in `out` the request line starts at; a negative one answers `HTTP1_NO_ROOM`.