@php-wasm/web 3.1.4 → 3.1.5

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/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { LatestSupportedPHPVersion as j, FSHelpers as w, loadPHPRuntime as me, __private__dont__use as k } from "@php-wasm/universal";
2
- import { consumeAPI as mt, exposeAPI as gt } from "@php-wasm/universal";
3
- import { concatArrayBuffers as R, concatUint8Arrays as u, Semaphore as ge, joinPaths as ie, basename as Ie } from "@php-wasm/util";
1
+ import { LatestSupportedPHPVersion as G, FSHelpers as w, loadPHPRuntime as me, __private__dont__use as F } from "@php-wasm/universal";
2
+ import { consumeAPI as gt, exposeAPI as It } from "@php-wasm/universal";
3
+ import { concatArrayBuffers as R, concatUint8Arrays as u, Semaphore as ge, joinPaths as ae, basename as Ie } from "@php-wasm/util";
4
4
  import { logger as U } from "@php-wasm/logger";
5
5
  import { fetchWithCorsProxy as Ke } from "@php-wasm/web-service-worker";
6
- import { FirewallInterferenceError as Kt, fetchWithCorsProxy as Dt } from "@php-wasm/web-service-worker";
6
+ import { FirewallInterferenceError as Dt, fetchWithCorsProxy as Wt } from "@php-wasm/web-service-worker";
7
7
  import { createMemoizedFetch as De } from "@wp-playground/common";
8
8
  import { journalFSEvents as We, normalizeFilesystemOperations as be } from "@php-wasm/fs-journal";
9
- async function Pe(i = j) {
9
+ async function Pe(i = G) {
10
10
  switch (i) {
11
11
  case "8.5":
12
12
  return (await import("@php-wasm/web-8-5")).getPHPLoaderModule();
@@ -38,7 +38,7 @@ function L(i) {
38
38
  i & 255
39
39
  ]);
40
40
  }
41
- function V(i) {
41
+ function z(i) {
42
42
  const e = new ArrayBuffer(8);
43
43
  return new DataView(e).setBigUint64(0, BigInt(i), !1), new Uint8Array(e);
44
44
  }
@@ -66,7 +66,7 @@ class m {
66
66
  return this.offset >= this.buffer.byteLength;
67
67
  }
68
68
  }
69
- class M {
69
+ class x {
70
70
  constructor(e) {
71
71
  this.offset = 0, this.buffer = new ArrayBuffer(e), this.uint8Array = new Uint8Array(this.buffer), this.view = new DataView(this.buffer);
72
72
  }
@@ -141,7 +141,7 @@ const D = {
141
141
  }, Re = f(D), _e = {
142
142
  host_name: 0
143
143
  }, Be = f(_e);
144
- class ae {
144
+ class oe {
145
145
  static decodeFromClient(e) {
146
146
  const t = new DataView(e.buffer);
147
147
  let n = 0;
@@ -149,22 +149,22 @@ class ae {
149
149
  n += 2;
150
150
  const s = [];
151
151
  for (; n < r + 2; ) {
152
- const _ = e[n];
152
+ const a = e[n];
153
153
  n += 1;
154
- const a = t.getUint16(n);
154
+ const _ = t.getUint16(n);
155
155
  n += 2;
156
- const S = e.slice(n, n + a);
157
- switch (n += a, _) {
156
+ const S = e.slice(n, n + _);
157
+ switch (n += _, a) {
158
158
  case _e.host_name:
159
159
  s.push({
160
- name_type: Be[_],
160
+ name_type: Be[a],
161
161
  name: {
162
162
  host_name: new TextDecoder().decode(S)
163
163
  }
164
164
  });
165
165
  break;
166
166
  default:
167
- throw new Error(`Unsupported name type ${_}`);
167
+ throw new Error(`Unsupported name type ${a}`);
168
168
  }
169
169
  }
170
170
  return { server_name_list: s };
@@ -185,16 +185,16 @@ class ae {
185
185
  throw new Error(
186
186
  "Encoding non-empty lists for ClientHello is not supported yet. Only empty lists meant for ServerHello are supported today."
187
187
  );
188
- const t = new M(4);
188
+ const t = new x(4);
189
189
  return t.writeUint16(D.server_name), t.writeUint16(0), t.uint8Array;
190
190
  }
191
191
  }
192
- const oe = {
192
+ const ce = {
193
193
  uncompressed: 0,
194
194
  ansiX962_compressed_prime: 1,
195
195
  ansiX962_compressed_char2: 2
196
- }, z = f(oe);
197
- class ce {
196
+ }, Y = f(ce);
197
+ class Se {
198
198
  /**
199
199
  * +--------------------------------------------------+
200
200
  * | Payload Length [2B] |
@@ -213,8 +213,8 @@ class ce {
213
213
  static decodeFromClient(e) {
214
214
  const t = new m(e.buffer), n = t.readUint8(), r = [];
215
215
  for (let s = 0; s < n; s++) {
216
- const _ = t.readUint8();
217
- _ in z && r.push(z[_]);
216
+ const a = t.readUint8();
217
+ a in Y && r.push(Y[a]);
218
218
  }
219
219
  return r;
220
220
  }
@@ -233,11 +233,11 @@ class ce {
233
233
  * +--------------------------------------------------+
234
234
  */
235
235
  static encodeForClient(e) {
236
- const t = new M(6);
237
- return t.writeUint16(D.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(oe[e]), t.uint8Array;
236
+ const t = new x(6);
237
+ return t.writeUint16(D.ec_point_formats), t.writeUint16(2), t.writeUint8(1), t.writeUint8(ce[e]), t.uint8Array;
238
238
  }
239
239
  }
240
- const Se = {
240
+ const Ce = {
241
241
  decodeFromClient(i) {
242
242
  const e = i[0] ?? 0;
243
243
  return {
@@ -258,7 +258,7 @@ const Se = {
258
258
  ...e
259
259
  ]);
260
260
  }
261
- }, Ce = {
261
+ }, le = {
262
262
  TLS1_CK_PSK_WITH_RC4_128_SHA: 138,
263
263
  TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA: 139,
264
264
  TLS1_CK_PSK_WITH_AES_128_CBC_SHA: 140,
@@ -461,13 +461,13 @@ const Se = {
461
461
  TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305: 52396,
462
462
  TLS1_CK_DHE_PSK_WITH_CHACHA20_POLY1305: 52397,
463
463
  TLS1_CK_RSA_PSK_WITH_CHACHA20_POLY1305: 52398
464
- }, Y = f(Ce), Ae = {
464
+ }, Z = f(le), he = {
465
465
  secp256r1: 23,
466
466
  secp384r1: 24,
467
467
  secp521r1: 25,
468
468
  x25519: 29,
469
469
  x448: 30
470
- }, Z = f(Ae);
470
+ }, J = f(he);
471
471
  class Ue {
472
472
  /**
473
473
  * +--------------------------------------------------+
@@ -490,7 +490,7 @@ class Ue {
490
490
  const n = [];
491
491
  for (; !t.isFinished(); ) {
492
492
  const r = t.readUint16();
493
- r in Z && n.push(Z[r]);
493
+ r in J && n.push(J[r]);
494
494
  }
495
495
  return n;
496
496
  }
@@ -505,16 +505,16 @@ class Ue {
505
505
  * +--------------------------------------------------+
506
506
  */
507
507
  static encodeForClient(e) {
508
- const t = new M(6);
509
- return t.writeUint16(D.supported_groups), t.writeUint16(2), t.writeUint16(Ae[e]), t.uint8Array;
508
+ const t = new x(6);
509
+ return t.writeUint16(D.supported_groups), t.writeUint16(2), t.writeUint16(he[e]), t.uint8Array;
510
510
  }
511
511
  }
512
- const G = {
512
+ const $ = {
513
513
  anonymous: 0,
514
514
  rsa: 1,
515
515
  dsa: 2,
516
516
  ecdsa: 3
517
- }, J = f(G), $ = {
517
+ }, X = f($), V = {
518
518
  none: 0,
519
519
  md5: 1,
520
520
  sha1: 2,
@@ -522,8 +522,8 @@ const G = {
522
522
  sha256: 4,
523
523
  sha384: 5,
524
524
  sha512: 6
525
- }, X = f($);
526
- class Me {
525
+ }, Q = f(V);
526
+ class xe {
527
527
  /**
528
528
  * Binary layout:
529
529
  *
@@ -545,14 +545,14 @@ class Me {
545
545
  const n = [];
546
546
  for (; !t.isFinished(); ) {
547
547
  const r = t.readUint8(), s = t.readUint8();
548
- if (J[s]) {
549
- if (!X[r]) {
548
+ if (X[s]) {
549
+ if (!Q[r]) {
550
550
  U.warn(`Unknown hash algorithm: ${r}`);
551
551
  continue;
552
552
  }
553
553
  n.push({
554
- algorithm: J[s],
555
- hash: X[r]
554
+ algorithm: X[s],
555
+ hash: Q[r]
556
556
  });
557
557
  }
558
558
  }
@@ -570,33 +570,33 @@ class Me {
570
570
  * +--------------------------------------------------+
571
571
  */
572
572
  static encodeforClient(e, t) {
573
- const n = new M(6);
574
- return n.writeUint16(D.signature_algorithms), n.writeUint16(2), n.writeUint8($[e]), n.writeUint8(G[t]), n.uint8Array;
573
+ const n = new x(6);
574
+ return n.writeUint16(D.signature_algorithms), n.writeUint16(2), n.writeUint8(V[e]), n.writeUint8($[t]), n.uint8Array;
575
575
  }
576
576
  }
577
- const Q = {
578
- server_name: ae,
579
- signature_algorithms: Me,
577
+ const ee = {
578
+ server_name: oe,
579
+ signature_algorithms: xe,
580
580
  supported_groups: Ue,
581
- ec_point_formats: ce,
582
- renegotiation_info: Se
581
+ ec_point_formats: Se,
582
+ renegotiation_info: Ce
583
583
  };
584
- function ve(i) {
584
+ function Me(i) {
585
585
  const e = new m(i.buffer), t = [];
586
586
  for (; !e.isFinished(); ) {
587
- const n = e.offset, r = e.readUint16(), s = Re[r], _ = e.readUint16(), a = e.readUint8Array(_);
588
- if (!(s in Q))
587
+ const n = e.offset, r = e.readUint16(), s = Re[r], a = e.readUint16(), _ = e.readUint8Array(a);
588
+ if (!(s in ee))
589
589
  continue;
590
- const S = Q[s];
590
+ const S = ee[s];
591
591
  t.push({
592
592
  type: s,
593
- data: S.decodeFromClient(a),
594
- raw: i.slice(n, n + 4 + _)
593
+ data: S.decodeFromClient(_),
594
+ raw: i.slice(n, n + 4 + a)
595
595
  });
596
596
  }
597
597
  return t;
598
598
  }
599
- async function q(i, e, t, n) {
599
+ async function O(i, e, t, n) {
600
600
  const r = R([e, t]), s = await crypto.subtle.importKey(
601
601
  "raw",
602
602
  i,
@@ -604,28 +604,28 @@ async function q(i, e, t, n) {
604
604
  !1,
605
605
  ["sign"]
606
606
  );
607
- let _ = r;
608
- const a = [];
609
- for (; R(a).byteLength < n; ) {
610
- _ = await ee(s, _);
611
- const c = R([_, r]), A = await ee(s, c);
612
- a.push(A);
613
- }
614
- return R(a).slice(0, n);
607
+ let a = r;
608
+ const _ = [];
609
+ for (; R(_).byteLength < n; ) {
610
+ a = await te(s, a);
611
+ const c = R([a, r]), C = await te(s, c);
612
+ _.push(C);
613
+ }
614
+ return R(_).slice(0, n);
615
615
  }
616
- async function ee(i, e) {
616
+ async function te(i, e) {
617
617
  return await crypto.subtle.sign(
618
618
  { name: "HMAC", hash: "SHA-256" },
619
619
  i,
620
620
  e
621
621
  );
622
622
  }
623
- const xe = {
623
+ const ve = {
624
624
  Null: 0
625
- }, he = {
625
+ }, Ae = {
626
626
  Warning: 1,
627
627
  Fatal: 2
628
- }, le = f(he), ue = {
628
+ }, ue = f(Ae), He = {
629
629
  CloseNotify: 0,
630
630
  UnexpectedMessage: 10,
631
631
  BadRecordMac: 20,
@@ -651,12 +651,12 @@ const xe = {
651
651
  UserCanceled: 90,
652
652
  NoRenegotiation: 100,
653
653
  UnsupportedExtension: 110
654
- }, He = f(ue), C = {
654
+ }, de = f(He), l = {
655
655
  ChangeCipherSpec: 20,
656
656
  Alert: 21,
657
657
  Handshake: 22,
658
658
  ApplicationData: 23
659
- }, d = {
659
+ }, E = {
660
660
  HelloRequest: 0,
661
661
  ClientHello: 1,
662
662
  ServerHello: 2,
@@ -677,7 +677,7 @@ const xe = {
677
677
  }, ke = {
678
678
  secp256r1: 23
679
679
  };
680
- class F extends Error {
680
+ class q extends Error {
681
681
  }
682
682
  const B = new Uint8Array([3, 3]), Fe = crypto.subtle.generateKey(
683
683
  {
@@ -714,7 +714,7 @@ class qe {
714
714
  new WritableStream({
715
715
  async write(t) {
716
716
  await e.writeTLSRecord(
717
- C.ApplicationData,
717
+ l.ApplicationData,
718
718
  t
719
719
  );
720
720
  },
@@ -764,7 +764,7 @@ class qe {
764
764
  */
765
765
  async TLSHandshake(e, t) {
766
766
  const n = await this.readNextHandshakeMessage(
767
- d.ClientHello
767
+ E.ClientHello
768
768
  );
769
769
  if (!n.body.cipher_suites.length)
770
770
  throw new Error(
@@ -772,31 +772,31 @@ class qe {
772
772
  );
773
773
  const r = crypto.getRandomValues(new Uint8Array(32));
774
774
  await this.writeTLSRecord(
775
- C.Handshake,
775
+ l.Handshake,
776
776
  I.serverHello(
777
777
  n.body,
778
778
  r,
779
- xe.Null
779
+ ve.Null
780
780
  )
781
781
  ), await this.writeTLSRecord(
782
- C.Handshake,
782
+ l.Handshake,
783
783
  I.certificate(t)
784
784
  );
785
- const s = await Fe, _ = n.body.random, a = await I.ECDHEServerKeyExchange(
786
- _,
785
+ const s = await Fe, a = n.body.random, _ = await I.ECDHEServerKeyExchange(
786
+ a,
787
787
  r,
788
788
  s,
789
789
  e
790
790
  );
791
- await this.writeTLSRecord(C.Handshake, a), await this.writeTLSRecord(
792
- C.Handshake,
791
+ await this.writeTLSRecord(l.Handshake, _), await this.writeTLSRecord(
792
+ l.Handshake,
793
793
  I.serverHelloDone()
794
794
  );
795
795
  const S = await this.readNextHandshakeMessage(
796
- d.ClientKeyExchange
796
+ E.ClientKeyExchange
797
797
  );
798
- await this.readNextMessage(C.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
799
- clientRandom: _,
798
+ await this.readNextMessage(l.ChangeCipherSpec), this.sessionKeys = await this.deriveSessionKeys({
799
+ clientRandom: a,
800
800
  serverRandom: r,
801
801
  serverPrivateKey: s.privateKey,
802
802
  clientPublicKey: await crypto.subtle.importKey(
@@ -806,11 +806,11 @@ class qe {
806
806
  !1,
807
807
  []
808
808
  )
809
- }), await this.readNextHandshakeMessage(d.Finished), await this.writeTLSRecord(
810
- C.ChangeCipherSpec,
809
+ }), await this.readNextHandshakeMessage(E.Finished), await this.writeTLSRecord(
810
+ l.ChangeCipherSpec,
811
811
  I.changeCipherSpec()
812
812
  ), await this.writeTLSRecord(
813
- C.Handshake,
813
+ l.Handshake,
814
814
  await I.createFinishedMessage(
815
815
  this.handshakeMessages,
816
816
  this.sessionKeys.masterSecret
@@ -835,22 +835,22 @@ class qe {
835
835
  n,
836
836
  256
837
837
  // Length of the derived secret (256 bits for P-256)
838
- ), _ = new Uint8Array(
839
- await q(
838
+ ), a = new Uint8Array(
839
+ await O(
840
840
  s,
841
841
  new TextEncoder().encode("master secret"),
842
842
  u([e, t]),
843
843
  48
844
844
  )
845
- ), a = await q(
846
- _,
845
+ ), _ = await O(
846
+ a,
847
847
  new TextEncoder().encode("key expansion"),
848
848
  u([t, e]),
849
849
  // Client key, server key, client IV, server IV
850
850
  40
851
- ), S = new m(a), c = S.readUint8Array(16), A = S.readUint8Array(16), h = S.readUint8Array(4), l = S.readUint8Array(4);
851
+ ), S = new m(_), c = S.readUint8Array(16), C = S.readUint8Array(16), h = S.readUint8Array(4), A = S.readUint8Array(4);
852
852
  return {
853
- masterSecret: _,
853
+ masterSecret: a,
854
854
  clientWriteKey: await crypto.subtle.importKey(
855
855
  "raw",
856
856
  c,
@@ -860,17 +860,17 @@ class qe {
860
860
  ),
861
861
  serverWriteKey: await crypto.subtle.importKey(
862
862
  "raw",
863
- A,
863
+ C,
864
864
  { name: "AES-GCM" },
865
865
  !1,
866
866
  ["encrypt", "decrypt"]
867
867
  ),
868
868
  clientIV: h,
869
- serverIV: l
869
+ serverIV: A
870
870
  };
871
871
  }
872
872
  async readNextHandshakeMessage(e) {
873
- const t = await this.readNextMessage(C.Handshake);
873
+ const t = await this.readNextMessage(l.Handshake);
874
874
  if (t.msg_type !== e)
875
875
  throw new Error(`Expected ${e} message`);
876
876
  return t;
@@ -884,33 +884,33 @@ class qe {
884
884
  t.type,
885
885
  n
886
886
  );
887
- return t.type === C.Handshake && this.handshakeMessages.push(t.fragment), r;
887
+ return t.type === l.Handshake && this.handshakeMessages.push(t.fragment), r;
888
888
  }
889
889
  async readNextTLSRecord(e) {
890
890
  for (; ; ) {
891
- for (let a = 0; a < this.receivedTLSRecords.length; a++) {
892
- const S = this.receivedTLSRecords[a];
891
+ for (let _ = 0; _ < this.receivedTLSRecords.length; _++) {
892
+ const S = this.receivedTLSRecords[_];
893
893
  if (S.type === e)
894
- return this.receivedTLSRecords.splice(a, 1), S;
894
+ return this.receivedTLSRecords.splice(_, 1), S;
895
895
  }
896
- const t = await this.pollBytes(5), n = t[3] << 8 | t[4], r = t[0], s = await this.pollBytes(n), _ = {
896
+ const t = await this.pollBytes(5), n = t[3] << 8 | t[4], r = t[0], s = await this.pollBytes(n), a = {
897
897
  type: r,
898
898
  version: {
899
899
  major: t[1],
900
900
  minor: t[2]
901
901
  },
902
902
  length: n,
903
- fragment: this.sessionKeys && r !== C.ChangeCipherSpec ? await this.decryptData(r, s) : s
903
+ fragment: this.sessionKeys && r !== l.ChangeCipherSpec ? await this.decryptData(r, s) : s
904
904
  };
905
- if (_.type === C.Alert) {
906
- const a = _.fragment[0], S = _.fragment[1], c = le[a], A = He[S];
907
- throw a === he.Warning && S === ue.CloseNotify ? new F(
905
+ if (a.type === l.Alert) {
906
+ const _ = a.fragment[0], S = a.fragment[1], c = ue[_], C = de[S];
907
+ throw _ === Ae.Warning && S === He.CloseNotify ? new q(
908
908
  "TLS connection closed by peer (CloseNotify)"
909
909
  ) : new Error(
910
- `TLS alert received: ${c} ${A}`
910
+ `TLS alert received: ${c} ${C}`
911
911
  );
912
912
  }
913
- this.receivedTLSRecords.push(_);
913
+ this.receivedTLSRecords.push(a);
914
914
  }
915
915
  }
916
916
  /**
@@ -921,7 +921,7 @@ class qe {
921
921
  for (; this.receivedBytesBuffer.length < e; ) {
922
922
  const { value: n, done: r } = await this.clientUpstreamReader.read();
923
923
  if (r)
924
- throw await this.close(), new F("TLS connection closed");
924
+ throw await this.close(), new q("TLS connection closed");
925
925
  if (this.receivedBytesBuffer = u([
926
926
  this.receivedBytesBuffer,
927
927
  n
@@ -940,12 +940,12 @@ class qe {
940
940
  try {
941
941
  for (; ; ) {
942
942
  const e = await this.readNextMessage(
943
- C.ApplicationData
943
+ l.ApplicationData
944
944
  );
945
945
  this.serverUpstreamWriter.write(e.body);
946
946
  }
947
947
  } catch (e) {
948
- if (e instanceof F)
948
+ if (e instanceof q)
949
949
  return;
950
950
  throw e;
951
951
  }
@@ -955,12 +955,12 @@ class qe {
955
955
  * the AES-GCM algorithm.
956
956
  */
957
957
  async decryptData(e, t) {
958
- const n = this.sessionKeys.clientIV, r = t.slice(0, 8), s = new Uint8Array([...n, ...r]), _ = await crypto.subtle.decrypt(
958
+ const n = this.sessionKeys.clientIV, r = t.slice(0, 8), s = new Uint8Array([...n, ...r]), a = await crypto.subtle.decrypt(
959
959
  {
960
960
  name: "AES-GCM",
961
961
  iv: s,
962
962
  additionalData: new Uint8Array([
963
- ...V(this.receivedRecordSequenceNumber),
963
+ ...z(this.receivedRecordSequenceNumber),
964
964
  e,
965
965
  ...B,
966
966
  // Payload length without IV and tag
@@ -972,7 +972,7 @@ class qe {
972
972
  // Payload without the explicit IV
973
973
  t.slice(8)
974
974
  );
975
- return ++this.receivedRecordSequenceNumber, new Uint8Array(_);
975
+ return ++this.receivedRecordSequenceNumber, new Uint8Array(a);
976
976
  }
977
977
  async accumulateUntilMessageIsComplete(e) {
978
978
  this.partialTLSMessages[e.type] = u([
@@ -981,7 +981,7 @@ class qe {
981
981
  ]);
982
982
  const t = this.partialTLSMessages[e.type];
983
983
  switch (e.type) {
984
- case C.Handshake: {
984
+ case l.Handshake: {
985
985
  if (t.length < 4)
986
986
  return !1;
987
987
  const n = t[1] << 8 | t[2];
@@ -989,13 +989,13 @@ class qe {
989
989
  return !1;
990
990
  break;
991
991
  }
992
- case C.Alert: {
992
+ case l.Alert: {
993
993
  if (t.length < 2)
994
994
  return !1;
995
995
  break;
996
996
  }
997
- case C.ChangeCipherSpec:
998
- case C.ApplicationData:
997
+ case l.ChangeCipherSpec:
998
+ case l.ApplicationData:
999
999
  break;
1000
1000
  default:
1001
1001
  throw new Error(`TLS: Unsupported record type ${e.type}`);
@@ -1010,28 +1010,28 @@ class qe {
1010
1010
  * only kicks in after the handshake is complete.
1011
1011
  */
1012
1012
  async writeTLSRecord(e, t) {
1013
- e === C.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== C.ChangeCipherSpec && (t = await this.encryptData(e, t));
1013
+ e === l.Handshake && this.handshakeMessages.push(t), this.sessionKeys && e !== l.ChangeCipherSpec && (t = await this.encryptData(e, t));
1014
1014
  const n = B, r = t.length, s = new Uint8Array(5);
1015
1015
  s[0] = e, s[1] = n[0], s[2] = n[1], s[3] = r >> 8 & 255, s[4] = r & 255;
1016
- const _ = u([s, t]);
1017
- this.clientDownstreamWriter.write(_);
1016
+ const a = u([s, t]);
1017
+ this.clientDownstreamWriter.write(a);
1018
1018
  }
1019
1019
  /**
1020
1020
  * Encrypts data in a TLS 1.2-compliant manner using
1021
1021
  * the AES-GCM algorithm.
1022
1022
  */
1023
1023
  async encryptData(e, t) {
1024
- const n = this.sessionKeys.serverIV, r = crypto.getRandomValues(new Uint8Array(8)), s = new Uint8Array([...n, ...r]), _ = new Uint8Array([
1025
- ...V(this.sentRecordSequenceNumber),
1024
+ const n = this.sessionKeys.serverIV, r = crypto.getRandomValues(new Uint8Array(8)), s = new Uint8Array([...n, ...r]), a = new Uint8Array([
1025
+ ...z(this.sentRecordSequenceNumber),
1026
1026
  e,
1027
1027
  ...B,
1028
1028
  // Payload length without IV and tag
1029
1029
  ...K(t.length)
1030
- ]), a = await crypto.subtle.encrypt(
1030
+ ]), _ = await crypto.subtle.encrypt(
1031
1031
  {
1032
1032
  name: "AES-GCM",
1033
1033
  iv: s,
1034
- additionalData: _,
1034
+ additionalData: a,
1035
1035
  tagLength: 128
1036
1036
  },
1037
1037
  this.sessionKeys.serverWriteKey,
@@ -1039,20 +1039,20 @@ class qe {
1039
1039
  );
1040
1040
  return ++this.sentRecordSequenceNumber, u([
1041
1041
  r,
1042
- new Uint8Array(a)
1042
+ new Uint8Array(_)
1043
1043
  ]);
1044
1044
  }
1045
1045
  }
1046
1046
  class T {
1047
1047
  static TLSMessage(e, t) {
1048
1048
  switch (e) {
1049
- case C.Handshake:
1049
+ case l.Handshake:
1050
1050
  return T.clientHandshake(t);
1051
- case C.Alert:
1051
+ case l.Alert:
1052
1052
  return T.alert(t);
1053
- case C.ChangeCipherSpec:
1053
+ case l.ChangeCipherSpec:
1054
1054
  return T.changeCipherSpec();
1055
- case C.ApplicationData:
1055
+ case l.ApplicationData:
1056
1056
  return T.applicationData(t);
1057
1057
  default:
1058
1058
  throw new Error(`TLS: Unsupported TLS record type ${e}`);
@@ -1087,50 +1087,50 @@ class T {
1087
1087
  const n = [];
1088
1088
  for (; !t.isFinished(); ) {
1089
1089
  const r = t.readUint16();
1090
- r in Y && n.push(Y[r]);
1090
+ r in Z && n.push(Z[r]);
1091
1091
  }
1092
1092
  return n;
1093
1093
  }
1094
1094
  static applicationData(e) {
1095
1095
  return {
1096
- type: C.ApplicationData,
1096
+ type: l.ApplicationData,
1097
1097
  body: e
1098
1098
  };
1099
1099
  }
1100
1100
  static changeCipherSpec() {
1101
1101
  return {
1102
- type: C.ChangeCipherSpec,
1102
+ type: l.ChangeCipherSpec,
1103
1103
  body: new Uint8Array()
1104
1104
  };
1105
1105
  }
1106
1106
  static alert(e) {
1107
1107
  return {
1108
- type: C.Alert,
1109
- level: le[e[0]],
1110
- description: He[e[1]]
1108
+ type: l.Alert,
1109
+ level: ue[e[0]],
1110
+ description: de[e[1]]
1111
1111
  };
1112
1112
  }
1113
1113
  static clientHandshake(e) {
1114
1114
  const t = e[0], n = e[1] << 16 | e[2] << 8 | e[3], r = e.slice(4);
1115
1115
  let s;
1116
1116
  switch (t) {
1117
- case d.HelloRequest:
1117
+ case E.HelloRequest:
1118
1118
  s = T.clientHelloRequestPayload();
1119
1119
  break;
1120
- case d.ClientHello:
1120
+ case E.ClientHello:
1121
1121
  s = T.clientHelloPayload(r);
1122
1122
  break;
1123
- case d.ClientKeyExchange:
1123
+ case E.ClientKeyExchange:
1124
1124
  s = T.clientKeyExchangePayload(r);
1125
1125
  break;
1126
- case d.Finished:
1126
+ case E.Finished:
1127
1127
  s = T.clientFinishedPayload(r);
1128
1128
  break;
1129
1129
  default:
1130
1130
  throw new Error(`Invalid handshake type ${t}`);
1131
1131
  }
1132
1132
  return {
1133
- type: C.Handshake,
1133
+ type: l.Handshake,
1134
1134
  msg_type: t,
1135
1135
  length: n,
1136
1136
  body: s
@@ -1194,13 +1194,13 @@ class T {
1194
1194
  n.cipher_suites = T.parseCipherSuites(
1195
1195
  t.readUint8Array(s).buffer
1196
1196
  );
1197
- const _ = t.readUint8();
1197
+ const a = t.readUint8();
1198
1198
  n.compression_methods = t.readUint8Array(
1199
- _
1199
+ a
1200
1200
  );
1201
- const a = t.readUint16();
1202
- return n.extensions = ve(
1203
- t.readUint8Array(a)
1201
+ const _ = t.readUint16();
1202
+ return n.extensions = Me(
1203
+ t.readUint8Array(_)
1204
1204
  ), n;
1205
1205
  }
1206
1206
  /**
@@ -1242,7 +1242,7 @@ class I {
1242
1242
  ...n
1243
1243
  ]);
1244
1244
  return new Uint8Array([
1245
- d.Certificate,
1245
+ E.Certificate,
1246
1246
  ...L(r.length),
1247
1247
  ...r
1248
1248
  ]);
@@ -1283,7 +1283,7 @@ class I {
1283
1283
  static async ECDHEServerKeyExchange(e, t, n, r) {
1284
1284
  const s = new Uint8Array(
1285
1285
  await crypto.subtle.exportKey("raw", n.publicKey)
1286
- ), _ = new Uint8Array([
1286
+ ), a = new Uint8Array([
1287
1287
  // Curve type (1 byte)
1288
1288
  Ne.NamedCurve,
1289
1289
  // Curve name (2 bytes)
@@ -1292,26 +1292,26 @@ class I {
1292
1292
  s.byteLength,
1293
1293
  // Public key (65 bytes, uncompressed format)
1294
1294
  ...s
1295
- ]), a = await crypto.subtle.sign(
1295
+ ]), _ = await crypto.subtle.sign(
1296
1296
  {
1297
1297
  name: "RSASSA-PKCS1-v1_5",
1298
1298
  hash: "SHA-256"
1299
1299
  },
1300
1300
  r,
1301
- new Uint8Array([...e, ...t, ..._])
1302
- ), S = new Uint8Array(a), c = new Uint8Array([
1303
- $.sha256,
1304
- G.rsa
1305
- ]), A = new Uint8Array([
1306
- ..._,
1301
+ new Uint8Array([...e, ...t, ...a])
1302
+ ), S = new Uint8Array(_), c = new Uint8Array([
1303
+ V.sha256,
1304
+ $.rsa
1305
+ ]), C = new Uint8Array([
1306
+ ...a,
1307
1307
  ...c,
1308
1308
  ...K(S.length),
1309
1309
  ...S
1310
1310
  ]);
1311
1311
  return new Uint8Array([
1312
- d.ServerKeyExchange,
1313
- ...L(A.length),
1314
- ...A
1312
+ E.ServerKeyExchange,
1313
+ ...L(C.length),
1314
+ ...C
1315
1315
  ]);
1316
1316
  }
1317
1317
  /**
@@ -1353,37 +1353,37 @@ class I {
1353
1353
  * +------------------------------------+
1354
1354
  */
1355
1355
  static serverHello(e, t, n) {
1356
- const r = e.extensions.map((a) => {
1357
- switch (a.type) {
1356
+ const r = e.extensions.map((_) => {
1357
+ switch (_.type) {
1358
1358
  case "server_name":
1359
- return ae.encodeForClient();
1359
+ return oe.encodeForClient();
1360
1360
  case "ec_point_formats":
1361
- return ce.encodeForClient(
1361
+ return Se.encodeForClient(
1362
1362
  "uncompressed"
1363
1363
  );
1364
1364
  case "renegotiation_info":
1365
- return Se.encodeForClient();
1365
+ return Ce.encodeForClient();
1366
1366
  }
1367
- }).filter((a) => a !== void 0), s = u(r), _ = new Uint8Array([
1367
+ }).filter((_) => _ !== void 0), s = u(r), a = new Uint8Array([
1368
1368
  // Version field – 0x03, 0x03 means TLS 1.2
1369
1369
  ...B,
1370
1370
  ...t,
1371
1371
  e.session_id.length,
1372
1372
  ...e.session_id,
1373
- ...K(Ce.TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
1373
+ ...K(le.TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256),
1374
1374
  n,
1375
1375
  // Extensions length (2 bytes)
1376
1376
  ...K(s.length),
1377
1377
  ...s
1378
1378
  ]);
1379
1379
  return new Uint8Array([
1380
- d.ServerHello,
1381
- ...L(_.length),
1382
- ..._
1380
+ E.ServerHello,
1381
+ ...L(a.length),
1382
+ ...a
1383
1383
  ]);
1384
1384
  }
1385
1385
  static serverHelloDone() {
1386
- return new Uint8Array([d.ServerHelloDone, ...L(0)]);
1386
+ return new Uint8Array([E.ServerHelloDone, ...L(0)]);
1387
1387
  }
1388
1388
  /**
1389
1389
  * Server finished message.
@@ -1408,7 +1408,7 @@ class I {
1408
1408
  "SHA-256",
1409
1409
  u(e)
1410
1410
  ), r = new Uint8Array(
1411
- await q(
1411
+ await O(
1412
1412
  t,
1413
1413
  new TextEncoder().encode("server finished"),
1414
1414
  n,
@@ -1417,7 +1417,7 @@ class I {
1417
1417
  )
1418
1418
  );
1419
1419
  return new Uint8Array([
1420
- d.Finished,
1420
+ E.Finished,
1421
1421
  ...L(r.length),
1422
1422
  ...r
1423
1423
  ]);
@@ -1429,18 +1429,18 @@ class I {
1429
1429
  function je(i, e) {
1430
1430
  return Ge.generateCertificate(i, e);
1431
1431
  }
1432
- function Ht(i) {
1432
+ function dt(i) {
1433
1433
  return `-----BEGIN CERTIFICATE-----
1434
- ${Ee(
1435
- de(i.buffer)
1434
+ ${Te(
1435
+ Ee(i.buffer)
1436
1436
  )}
1437
1437
  -----END CERTIFICATE-----`;
1438
1438
  }
1439
- async function dt(i) {
1439
+ async function Et(i) {
1440
1440
  const e = await crypto.subtle.exportKey("pkcs8", i);
1441
1441
  return `-----BEGIN PRIVATE KEY-----
1442
- ${Ee(
1443
- de(e)
1442
+ ${Te(
1443
+ Ee(e)
1444
1444
  )}
1445
1445
  -----END PRIVATE KEY-----`;
1446
1446
  }
@@ -1543,13 +1543,13 @@ class Ge {
1543
1543
  o.ASN1(
1544
1544
  H.UTCTime,
1545
1545
  new TextEncoder().encode(
1546
- ne((e == null ? void 0 : e.notBefore) ?? /* @__PURE__ */ new Date())
1546
+ re((e == null ? void 0 : e.notBefore) ?? /* @__PURE__ */ new Date())
1547
1547
  )
1548
1548
  ),
1549
1549
  o.ASN1(
1550
1550
  H.UTCTime,
1551
1551
  new TextEncoder().encode(
1552
- ne(
1552
+ re(
1553
1553
  (e == null ? void 0 : e.notAfter) ?? Ve(/* @__PURE__ */ new Date(), 10)
1554
1554
  )
1555
1555
  )
@@ -1599,12 +1599,12 @@ class Ge {
1599
1599
  ]);
1600
1600
  }
1601
1601
  static subjectAltName(e) {
1602
- var s, _;
1603
- const t = ((s = e.dnsNames) == null ? void 0 : s.map((a) => {
1604
- const S = o.ia5String(a);
1602
+ var s, a;
1603
+ const t = ((s = e.dnsNames) == null ? void 0 : s.map((_) => {
1604
+ const S = o.ia5String(_);
1605
1605
  return o.contextSpecific(2, S);
1606
- })) || [], n = ((_ = e.ipAddresses) == null ? void 0 : _.map((a) => {
1607
- const S = o.ia5String(a);
1606
+ })) || [], n = ((a = e.ipAddresses) == null ? void 0 : a.map((_) => {
1607
+ const S = o.ia5String(_);
1608
1608
  return o.contextSpecific(7, S);
1609
1609
  })) || [], r = o.octetString(
1610
1610
  o.sequence([...t, ...n])
@@ -1732,7 +1732,7 @@ function p(i) {
1732
1732
  return e;
1733
1733
  throw new Error(`OID not found for name: ${i}`);
1734
1734
  }
1735
- const te = 32, H = {
1735
+ const ne = 32, H = {
1736
1736
  Boolean: 1,
1737
1737
  Integer: 2,
1738
1738
  BitString: 3,
@@ -1740,8 +1740,8 @@ const te = 32, H = {
1740
1740
  Null: 5,
1741
1741
  OID: 6,
1742
1742
  Utf8String: 12,
1743
- Sequence: 16 | te,
1744
- Set: 17 | te,
1743
+ Sequence: 16 | ne,
1744
+ Set: 17 | ne,
1745
1745
  PrintableString: 19,
1746
1746
  IA5String: 22,
1747
1747
  UTCTime: 23
@@ -1758,8 +1758,8 @@ class o {
1758
1758
  n.unshift(t & 255), t >>= 8;
1759
1759
  const r = n.length, s = new Uint8Array(1 + r);
1760
1760
  s[0] = 128 | r;
1761
- for (let _ = 0; _ < r; _++)
1762
- s[_ + 1] = n[_];
1761
+ for (let a = 0; a < r; a++)
1762
+ s[a + 1] = n[a];
1763
1763
  return s;
1764
1764
  }
1765
1765
  }
@@ -1787,14 +1787,14 @@ class o {
1787
1787
  static objectIdentifier(e) {
1788
1788
  const t = e.split(".").map(Number), r = [t[0] * 40 + t[1]];
1789
1789
  for (let s = 2; s < t.length; s++) {
1790
- let _ = t[s];
1791
- const a = [];
1790
+ let a = t[s];
1791
+ const _ = [];
1792
1792
  do
1793
- a.unshift(_ & 127), _ >>= 7;
1794
- while (_ > 0);
1795
- for (let S = 0; S < a.length - 1; S++)
1796
- a[S] |= 128;
1797
- r.push(...a);
1793
+ _.unshift(a & 127), a >>= 7;
1794
+ while (a > 0);
1795
+ for (let S = 0; S < _.length - 1; S++)
1796
+ _[S] |= 128;
1797
+ r.push(..._);
1798
1798
  }
1799
1799
  return o.ASN1(H.OID, new Uint8Array(r));
1800
1800
  }
@@ -1827,19 +1827,19 @@ class o {
1827
1827
  );
1828
1828
  }
1829
1829
  }
1830
- function de(i) {
1830
+ function Ee(i) {
1831
1831
  return btoa(String.fromCodePoint(...new Uint8Array(i)));
1832
1832
  }
1833
- function Ee(i) {
1833
+ function Te(i) {
1834
1834
  var e;
1835
1835
  return ((e = i.match(/.{1,64}/g)) == null ? void 0 : e.join(`
1836
1836
  `)) || i;
1837
1837
  }
1838
- function ne(i) {
1839
- const e = i.getUTCFullYear().toString().substr(2), t = b(i.getUTCMonth() + 1), n = b(i.getUTCDate()), r = b(i.getUTCHours()), s = b(i.getUTCMinutes()), _ = b(i.getUTCSeconds());
1840
- return `${e}${t}${n}${r}${s}${_}Z`;
1838
+ function re(i) {
1839
+ const e = i.getUTCFullYear().toString().substr(2), t = P(i.getUTCMonth() + 1), n = P(i.getUTCDate()), r = P(i.getUTCHours()), s = P(i.getUTCMinutes()), a = P(i.getUTCSeconds());
1840
+ return `${e}${t}${n}${r}${s}${a}Z`;
1841
1841
  }
1842
- function b(i) {
1842
+ function P(i) {
1843
1843
  return i.toString().padStart(2, "0");
1844
1844
  }
1845
1845
  function Ve(i, e) {
@@ -1855,37 +1855,37 @@ class ze extends TransformStream {
1855
1855
  if (t === "SCAN_CHUNK_SIZE") {
1856
1856
  if (e.length < 3)
1857
1857
  return;
1858
- let _ = 0;
1859
- for (; _ < e.length; ) {
1860
- const c = e[_];
1858
+ let a = 0;
1859
+ for (; a < e.length; ) {
1860
+ const c = e[a];
1861
1861
  if (!(c >= 48 && c <= 57 || // 0-9
1862
1862
  c >= 97 && c <= 102 || // a-f
1863
1863
  c >= 65 && c <= 70)) break;
1864
- _++;
1864
+ a++;
1865
1865
  }
1866
- if (_ === 0)
1866
+ if (a === 0)
1867
1867
  throw new Error("Invalid chunk size format");
1868
- if (e.length < _ + 2)
1868
+ if (e.length < a + 2)
1869
1869
  return;
1870
- if (e[_] !== 13 || // \r
1871
- e[_ + 1] !== 10)
1870
+ if (e[a] !== 13 || // \r
1871
+ e[a + 1] !== 10)
1872
1872
  throw new Error(
1873
1873
  "Invalid chunk size format. Expected CRLF after chunk size"
1874
1874
  );
1875
- const a = new TextDecoder().decode(
1876
- e.slice(0, _)
1877
- ), S = parseInt(a, 16);
1878
- if (e = e.slice(_ + 2), S === 0) {
1875
+ const _ = new TextDecoder().decode(
1876
+ e.slice(0, a)
1877
+ ), S = parseInt(_, 16);
1878
+ if (e = e.slice(a + 2), S === 0) {
1879
1879
  t = "SCAN_FINAL_CHUNK", s.terminate();
1880
1880
  return;
1881
1881
  }
1882
1882
  n = S, t = "SCAN_CHUNK_DATA";
1883
1883
  } else if (t === "SCAN_CHUNK_DATA") {
1884
- const _ = Math.min(
1884
+ const a = Math.min(
1885
1885
  n,
1886
1886
  e.length
1887
- ), a = e.slice(0, _);
1888
- e = e.slice(_), n -= _, s.enqueue(a), n === 0 && (t = "SCAN_CHUNK_TRAILER");
1887
+ ), _ = e.slice(0, a);
1888
+ e = e.slice(a), n -= a, s.enqueue(_), n === 0 && (t = "SCAN_CHUNK_TRAILER");
1889
1889
  } else if (t === "SCAN_CHUNK_TRAILER") {
1890
1890
  if (e.length < 2)
1891
1891
  return;
@@ -1924,11 +1924,11 @@ class Ze {
1924
1924
  outputType: s = "messages"
1925
1925
  } = {}) {
1926
1926
  this.CONNECTING = 0, this.OPEN = 1, this.CLOSING = 2, this.CLOSED = 3, this.readyState = this.CONNECTING, this.binaryType = "blob", this.bufferedAmount = 0, this.extensions = "", this.protocol = "ws", this.host = "", this.port = 0, this.listeners = /* @__PURE__ */ new Map(), this.clientUpstream = new TransformStream(), this.clientUpstreamWriter = this.clientUpstream.writable.getWriter(), this.clientDownstream = new TransformStream(), this.fetchInitiated = !1, this.bufferedBytesFromClient = new Uint8Array(0), this.url = e, this.options = t;
1927
- const _ = new URL(e);
1928
- this.host = _.searchParams.get("host"), this.port = parseInt(_.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = r, this.CAroot = n, s === "messages" && this.clientDownstream.readable.pipeTo(
1927
+ const a = new URL(e);
1928
+ this.host = a.searchParams.get("host"), this.port = parseInt(a.searchParams.get("port"), 10), this.binaryType = "arraybuffer", this.corsProxyUrl = r, this.CAroot = n, s === "messages" && this.clientDownstream.readable.pipeTo(
1929
1929
  new WritableStream({
1930
- write: (a) => {
1931
- this.emit("message", { data: a });
1930
+ write: (_) => {
1931
+ this.emit("message", { data: _ });
1932
1932
  },
1933
1933
  abort: () => {
1934
1934
  this.emit("error", new Error("ECONNREFUSED")), this.close();
@@ -2024,11 +2024,19 @@ class Ze {
2024
2024
  e.certificate,
2025
2025
  this.CAroot.certificate
2026
2026
  ]);
2027
- const n = await y.parseHttpRequest(
2027
+ const { request: n, expectsContinue: r } = await y.parseHttpRequest(
2028
2028
  t.serverEnd.upstream.readable,
2029
2029
  this.host,
2030
2030
  "https"
2031
2031
  );
2032
+ if (r) {
2033
+ const s = t.serverEnd.downstream.writable.getWriter();
2034
+ await s.write(
2035
+ new TextEncoder().encode(`HTTP/1.1 100 Continue\r
2036
+ \r
2037
+ `)
2038
+ ), s.releaseLock();
2039
+ }
2032
2040
  try {
2033
2041
  await y.fetchRawResponseBytes(
2034
2042
  n,
@@ -2038,11 +2046,19 @@ class Ze {
2038
2046
  }
2039
2047
  }
2040
2048
  async fetchOverHTTP() {
2041
- const e = await y.parseHttpRequest(
2049
+ const { request: e, expectsContinue: t } = await y.parseHttpRequest(
2042
2050
  this.clientUpstream.readable,
2043
2051
  this.host,
2044
2052
  "http"
2045
2053
  );
2054
+ if (t) {
2055
+ const n = this.clientDownstream.writable.getWriter();
2056
+ await n.write(
2057
+ new TextEncoder().encode(`HTTP/1.1 100 Continue\r
2058
+ \r
2059
+ `)
2060
+ ), n.releaseLock();
2061
+ }
2046
2062
  try {
2047
2063
  await y.fetchRawResponseBytes(
2048
2064
  e,
@@ -2068,7 +2084,7 @@ const Je = [
2068
2084
  function Xe(i, e) {
2069
2085
  if (e.length < 8)
2070
2086
  return !1;
2071
- if (i === 443 && e[0] === C.Handshake && // TLS versions between 1.0 and 1.2
2087
+ if (i === 443 && e[0] === l.Handshake && // TLS versions between 1.0 and 1.2
2072
2088
  e[1] === 3 && e[2] >= 1 && e[2] <= 3)
2073
2089
  return "tls";
2074
2090
  const n = new TextDecoder("latin1", {
@@ -2085,7 +2101,7 @@ class y {
2085
2101
  static fetchRawResponseBytes(e, t) {
2086
2102
  return new ReadableStream({
2087
2103
  async start(n) {
2088
- var a;
2104
+ var _;
2089
2105
  let r;
2090
2106
  try {
2091
2107
  r = await Ke(
@@ -2105,20 +2121,20 @@ Content-Length: 0\r
2105
2121
  return;
2106
2122
  }
2107
2123
  n.enqueue(y.headersAsBytes(r));
2108
- const s = (a = r.body) == null ? void 0 : a.getReader();
2124
+ const s = (_ = r.body) == null ? void 0 : _.getReader();
2109
2125
  if (!s) {
2110
2126
  n.close();
2111
2127
  return;
2112
2128
  }
2113
- const _ = new TextEncoder();
2129
+ const a = new TextEncoder();
2114
2130
  for (; ; ) {
2115
2131
  const { done: S, value: c } = await s.read();
2116
2132
  if (c && (n.enqueue(
2117
- _.encode(`${c.length.toString(16)}\r
2133
+ a.encode(`${c.length.toString(16)}\r
2118
2134
  `)
2119
- ), n.enqueue(c), n.enqueue(_.encode(`\r
2135
+ ), n.enqueue(c), n.enqueue(a.encode(`\r
2120
2136
  `))), S) {
2121
- n.enqueue(_.encode(`0\r
2137
+ n.enqueue(a.encode(`0\r
2122
2138
  \r
2123
2139
  `)), n.close();
2124
2140
  return;
@@ -2129,12 +2145,12 @@ Content-Length: 0\r
2129
2145
  }
2130
2146
  static headersAsBytes(e) {
2131
2147
  const t = `HTTP/1.1 ${e.status} ${e.statusText}`, n = {};
2132
- e.headers.forEach((_, a) => {
2133
- n[a.toLowerCase()] = _;
2134
- }), delete n["content-length"], n["transfer-encoding"] = "chunked";
2148
+ e.headers.forEach((a, _) => {
2149
+ n[_.toLowerCase()] = a;
2150
+ }), delete n["content-length"], delete n["content-encoding"], n["transfer-encoding"] = "chunked";
2135
2151
  const r = [];
2136
- for (const [_, a] of Object.entries(n))
2137
- r.push(`${_}: ${a}`);
2152
+ for (const [a, _] of Object.entries(n))
2153
+ r.push(`${a}: ${_}`);
2138
2154
  const s = [t, ...r].join(`\r
2139
2155
  `) + `\r
2140
2156
  \r
@@ -2146,90 +2162,98 @@ Content-Length: 0\r
2146
2162
  * with known headers and a readable body stream.
2147
2163
  */
2148
2164
  static async parseHttpRequest(e, t, n) {
2149
- let r = new Uint8Array(0), s = !1, _ = -1;
2150
- const a = e.getReader();
2151
- for (; _ === -1; ) {
2152
- const { done: x, value: P } = await a.read();
2153
- if (x) {
2165
+ let r = new Uint8Array(0), s = !1, a = -1;
2166
+ const _ = e.getReader();
2167
+ for (; a === -1; ) {
2168
+ const { done: v, value: W } = await _.read();
2169
+ if (v) {
2154
2170
  s = !0;
2155
2171
  break;
2156
2172
  }
2157
- r = u([r, P]), _ = Qe(
2173
+ r = u([r, W]), a = Qe(
2158
2174
  r,
2159
2175
  new Uint8Array([13, 10, 13, 10])
2160
2176
  );
2161
2177
  }
2162
- a.releaseLock();
2163
- const S = r.slice(0, _), c = y.parseRequestHeaders(S), A = c.headers.get("Transfer-Encoding") !== null ? "chunked" : "content-length", h = c.headers.get("Content-Length") !== null ? parseInt(c.headers.get("Content-Length"), 10) : void 0, l = r.slice(
2164
- _ + 4
2178
+ _.releaseLock();
2179
+ const S = r.slice(0, a), c = y.parseRequestHeaders(S), C = c.headers.get("Transfer-Encoding") !== null ? "chunked" : "content-length", h = c.headers.get("Content-Length") !== null ? parseInt(c.headers.get("Content-Length"), 10) : void 0, A = r.slice(
2180
+ a + 4
2165
2181
  /* Skip \r\n\r\n */
2166
2182
  );
2167
- let E;
2183
+ let d;
2168
2184
  if (c.method !== "GET") {
2169
- const x = e.getReader();
2170
- let P = l.length, N = l.slice(-6);
2171
- const pe = new TextEncoder().encode(`0\r
2185
+ const v = e.getReader();
2186
+ let W = A.length, N = A.slice(-6);
2187
+ const we = new TextEncoder().encode(`0\r
2172
2188
  \r
2173
2189
  `);
2174
- E = new ReadableStream({
2175
- async start(W) {
2176
- l.length > 0 && W.enqueue(l), s && W.close();
2190
+ d = new ReadableStream({
2191
+ async start(b) {
2192
+ A.length > 0 && b.enqueue(A);
2193
+ const k = C === "content-length" && h !== void 0 && W >= h;
2194
+ (s || k) && b.close();
2177
2195
  },
2178
- async pull(W) {
2179
- const { done: we, value: g } = await x.read();
2180
- if (P += (g == null ? void 0 : g.length) || 0, g && (W.enqueue(g), N = u([
2196
+ async pull(b) {
2197
+ const { done: k, value: g } = await v.read();
2198
+ if (W += (g == null ? void 0 : g.length) || 0, g && (b.enqueue(g), N = u([
2181
2199
  N,
2182
2200
  g || new Uint8Array()
2183
- ]).slice(-5)), we || A === "content-length" && h !== void 0 && P >= h || A === "chunked" && N.every(
2184
- (Le, ye) => Le === pe[ye]
2201
+ ]).slice(-5)), k || C === "content-length" && h !== void 0 && W >= h || C === "chunked" && N.every(
2202
+ (Le, ye) => Le === we[ye]
2185
2203
  )) {
2186
- W.close();
2204
+ b.close();
2187
2205
  return;
2188
2206
  }
2189
2207
  }
2190
- }), A === "chunked" && (E = E.pipeThrough(
2208
+ }), C === "chunked" && (d = d.pipeThrough(
2191
2209
  new ze()
2192
2210
  ));
2193
2211
  }
2194
- const v = c.headers.get("Host") ?? t, fe = new URL(c.path, n + "://" + v);
2195
- return new Request(fe.toString(), {
2196
- method: c.method,
2197
- headers: c.headers,
2198
- body: E,
2199
- // In Node.js, duplex: 'half' is required when
2200
- // the body stream is provided.
2201
- // @ts-expect-error
2202
- duplex: "half"
2203
- });
2212
+ const M = c.headers.get("Host") ?? t, pe = new URL(c.path, n + "://" + M);
2213
+ return {
2214
+ request: new Request(pe.toString(), {
2215
+ method: c.method,
2216
+ headers: c.headers,
2217
+ body: d,
2218
+ // @ts-expect-error duplex is required for streaming request bodies
2219
+ duplex: d ? "half" : void 0
2220
+ }),
2221
+ expectsContinue: c.expectsContinue
2222
+ };
2204
2223
  }
2205
2224
  static parseRequestHeaders(e) {
2225
+ var S;
2206
2226
  const t = new TextDecoder().decode(e), n = t.split(`
2207
- `)[0], [r, s] = n.split(" "), _ = new Headers();
2208
- for (const a of t.split(`\r
2227
+ `)[0], [r, s] = n.split(" "), a = new Headers();
2228
+ for (const c of t.split(`\r
2209
2229
  `).slice(1)) {
2210
- if (a === "")
2230
+ if (c === "")
2211
2231
  break;
2212
- const [S, c] = a.split(": ");
2213
- _.set(S, c);
2232
+ const C = c.indexOf(":");
2233
+ if (C === -1)
2234
+ continue;
2235
+ const h = c.slice(0, C).trim(), A = c.slice(C + 1).trimStart();
2236
+ h !== "" && a.set(h, A);
2214
2237
  }
2215
- return { method: r, path: s, headers: _ };
2238
+ const _ = ((S = a.get("Expect")) == null ? void 0 : S.toLowerCase()) === "100-continue";
2239
+ return a.delete("Expect"), { method: r, path: s, headers: a, expectsContinue: _ };
2216
2240
  }
2217
2241
  }
2218
2242
  function Qe(i, e) {
2219
2243
  const t = i.length, n = e.length, r = t - n;
2220
2244
  for (let s = 0; s <= r; s++) {
2221
- let _ = !0;
2222
- for (let a = 0; a < n; a++)
2223
- if (i[s + a] !== e[a]) {
2224
- _ = !1;
2245
+ let a = !0;
2246
+ for (let _ = 0; _ < n; _++)
2247
+ if (i[s + _] !== e[_]) {
2248
+ a = !1;
2225
2249
  break;
2226
2250
  }
2227
- if (_)
2251
+ if (a)
2228
2252
  return s;
2229
2253
  }
2230
2254
  return -1;
2231
2255
  }
2232
- async function et(i = j) {
2256
+ async function et(i = G) {
2233
2257
  switch (i) {
2234
2258
  case "8.5":
2235
2259
  return (await import("@php-wasm/web-8-5")).getIntlExtensionPath();
@@ -2248,10 +2272,10 @@ async function et(i = j) {
2248
2272
  }
2249
2273
  throw new Error(`Unsupported PHP version ${i}`);
2250
2274
  }
2251
- async function tt(i = j, e) {
2252
- const t = De(fetch), n = "intl.so", r = "icu.dat", s = await et(i), _ = (await import("./shared/icu.dat")).default, [a, S] = await Promise.all([
2275
+ async function tt(i = G, e) {
2276
+ const t = De(fetch), n = "intl.so", r = "icu.dat", s = await et(i), a = (await import("./shared/icu.dat")).default, [_, S] = await Promise.all([
2253
2277
  t(s).then((c) => c.arrayBuffer()),
2254
- t(_).then((c) => c.arrayBuffer())
2278
+ t(a).then((c) => c.arrayBuffer())
2255
2279
  ]);
2256
2280
  return {
2257
2281
  ...e,
@@ -2269,7 +2293,7 @@ async function tt(i = j, e) {
2269
2293
  `/internal/shared/extensions/${n}`
2270
2294
  ) || c.FS.writeFile(
2271
2295
  `/internal/shared/extensions/${n}`,
2272
- new Uint8Array(a)
2296
+ new Uint8Array(_)
2273
2297
  ), w.fileExists(
2274
2298
  c.FS,
2275
2299
  "/internal/shared/extensions/intl.ini"
@@ -2304,9 +2328,9 @@ const nt = () => ({
2304
2328
  }
2305
2329
  }
2306
2330
  });
2307
- async function Tt(i, e = {}) {
2331
+ async function ft(i, e = {}) {
2308
2332
  var s;
2309
- "setImmediate" in globalThis || (globalThis.setImmediate = (_) => setTimeout(_, 0));
2333
+ "setImmediate" in globalThis || (globalThis.setImmediate = (a) => setTimeout(a, 0));
2310
2334
  let t = {
2311
2335
  ...nt(),
2312
2336
  ...e.emscriptenOptions || {}
@@ -2321,7 +2345,7 @@ async function Tt(i, e = {}) {
2321
2345
  ]);
2322
2346
  return (s = e.onPhpLoaderModuleLoaded) == null || s.call(e, n), await me(n, r);
2323
2347
  }
2324
- function ft(i, e) {
2348
+ function pt(i, e) {
2325
2349
  window.addEventListener("message", (t) => {
2326
2350
  t.source === i.contentWindow && (e && t.origin !== e || typeof t.data != "object" || t.data.type !== "relay" || window.parent.postMessage(t.data, "*"));
2327
2351
  }), window.addEventListener("message", (t) => {
@@ -2329,14 +2353,14 @@ function ft(i, e) {
2329
2353
  t.source === window.parent && (typeof t.data != "object" || t.data.type !== "relay" || (n = i == null ? void 0 : i.contentWindow) == null || n.postMessage(t.data));
2330
2354
  });
2331
2355
  }
2332
- async function pt(i) {
2356
+ async function wt(i) {
2333
2357
  const e = new Worker(i, { type: "module" });
2334
2358
  return new Promise((t, n) => {
2335
2359
  e.onerror = (s) => {
2336
- const _ = new Error(
2360
+ const a = new Error(
2337
2361
  `WebWorker failed to load at ${i}. ${s.message ? `Original error: ${s.message}` : ""}`
2338
2362
  );
2339
- _.filename = s.filename, n(_);
2363
+ a.filename = s.filename, n(a);
2340
2364
  };
2341
2365
  function r(s) {
2342
2366
  s.data === "worker-script-started" && (t(e), e.removeEventListener("message", r));
@@ -2344,7 +2368,7 @@ async function pt(i) {
2344
2368
  e.addEventListener("message", r);
2345
2369
  });
2346
2370
  }
2347
- function wt(i, e = { initialSync: {} }) {
2371
+ function Lt(i, e = { initialSync: {} }) {
2348
2372
  return e = {
2349
2373
  ...e,
2350
2374
  initialSync: {
@@ -2352,7 +2376,7 @@ function wt(i, e = { initialSync: {} }) {
2352
2376
  direction: e.initialSync.direction ?? "opfs-to-memfs"
2353
2377
  }
2354
2378
  }, async function(t, n, r) {
2355
- return e.initialSync.direction === "opfs-to-memfs" ? (w.fileExists(n, r) && w.rmdir(n, r), w.mkdir(n, r), await rt(n, i, r)) : await Te(
2379
+ return e.initialSync.direction === "opfs-to-memfs" ? (w.fileExists(n, r) && w.rmdir(n, r), w.mkdir(n, r), await rt(n, i, r)) : await fe(
2356
2380
  n,
2357
2381
  i,
2358
2382
  r,
@@ -2368,27 +2392,27 @@ async function rt(i, e, t) {
2368
2392
  [e, t]
2369
2393
  ];
2370
2394
  for (; s.length > 0; ) {
2371
- const [_, a] = s.pop();
2372
- for await (const S of _.values()) {
2395
+ const [a, _] = s.pop();
2396
+ for await (const S of a.values()) {
2373
2397
  const c = n.run(async () => {
2374
- const A = ie(
2375
- a,
2398
+ const C = ae(
2399
+ _,
2376
2400
  S.name
2377
2401
  );
2378
2402
  if (S.kind === "directory") {
2379
2403
  try {
2380
- i.mkdir(A);
2404
+ i.mkdir(C);
2381
2405
  } catch (h) {
2382
2406
  if ((h == null ? void 0 : h.errno) !== 20)
2383
2407
  throw U.error(h), h;
2384
2408
  }
2385
- s.push([S, A]);
2409
+ s.push([S, C]);
2386
2410
  } else if (S.kind === "file") {
2387
- const h = await S.getFile(), l = new Uint8Array(await h.arrayBuffer());
2411
+ const h = await S.getFile(), A = new Uint8Array(await h.arrayBuffer());
2388
2412
  i.createDataFile(
2389
- a,
2413
+ _,
2390
2414
  S.name,
2391
- l,
2415
+ A,
2392
2416
  !0,
2393
2417
  !0,
2394
2418
  !0
@@ -2402,44 +2426,44 @@ async function rt(i, e, t) {
2402
2426
  await Promise.any(r);
2403
2427
  }
2404
2428
  }
2405
- async function Te(i, e, t, n) {
2429
+ async function fe(i, e, t, n) {
2406
2430
  i.mkdirTree(t);
2407
2431
  const r = [];
2408
- async function s(A, h) {
2432
+ async function s(C, h) {
2409
2433
  await Promise.all(
2410
- i.readdir(A).filter(
2411
- (l) => l !== "." && l !== ".."
2412
- ).map(async (l) => {
2413
- const E = ie(A, l);
2414
- if (!st(i, E)) {
2415
- r.push([h, E, l]);
2434
+ i.readdir(C).filter(
2435
+ (A) => A !== "." && A !== ".."
2436
+ ).map(async (A) => {
2437
+ const d = ae(C, A);
2438
+ if (!st(i, d)) {
2439
+ r.push([h, d, A]);
2416
2440
  return;
2417
2441
  }
2418
- const v = await h.getDirectoryHandle(l, {
2442
+ const M = await h.getDirectoryHandle(A, {
2419
2443
  create: !0
2420
2444
  });
2421
- return await s(E, v);
2445
+ return await s(d, M);
2422
2446
  })
2423
2447
  );
2424
2448
  }
2425
2449
  await s(t, e);
2426
- let _ = 0;
2427
- const a = n && ot(n, 100), S = 100, c = /* @__PURE__ */ new Set();
2450
+ let a = 0;
2451
+ const _ = n && ot(n, 100), S = 100, c = /* @__PURE__ */ new Set();
2428
2452
  try {
2429
- for (const [A, h, l] of r) {
2430
- const E = O(
2453
+ for (const [C, h, A] of r) {
2454
+ const d = j(
2455
+ C,
2431
2456
  A,
2432
- l,
2433
2457
  i,
2434
2458
  h
2435
2459
  ).then(() => {
2436
- _++, c.delete(E), a == null || a({
2437
- files: _,
2460
+ a++, c.delete(d), _ == null || _({
2461
+ files: a,
2438
2462
  total: r.length
2439
2463
  });
2440
2464
  });
2441
- c.add(E), c.size >= S && (await Promise.race(c), a == null || a({
2442
- files: _,
2465
+ c.add(d), c.size >= S && (await Promise.race(c), _ == null || _({
2466
+ files: a,
2443
2467
  total: r.length
2444
2468
  }));
2445
2469
  }
@@ -2450,7 +2474,7 @@ async function Te(i, e, t, n) {
2450
2474
  function st(i, e) {
2451
2475
  return i.isDir(i.lookupPath(e, { follow: !0 }).node.mode);
2452
2476
  }
2453
- async function O(i, e, t, n) {
2477
+ async function j(i, e, t, n) {
2454
2478
  let r;
2455
2479
  try {
2456
2480
  r = t.readFile(n, {
@@ -2459,7 +2483,7 @@ async function O(i, e, t, n) {
2459
2483
  } catch {
2460
2484
  return;
2461
2485
  }
2462
- const s = await i.getFileHandle(e, { create: !0 }), _ = s.createWritable !== void 0 ? (
2486
+ const s = await i.getFileHandle(e, { create: !0 }), a = s.createWritable !== void 0 ? (
2463
2487
  // Google Chrome, Firefox, probably more browsers
2464
2488
  await s.createWritable()
2465
2489
  ) : (
@@ -2467,43 +2491,43 @@ async function O(i, e, t, n) {
2467
2491
  await s.createSyncAccessHandle()
2468
2492
  );
2469
2493
  try {
2470
- await _.truncate(0), await _.write(r);
2494
+ await a.truncate(0), await a.write(r);
2471
2495
  } finally {
2472
- await _.close();
2496
+ await a.close();
2473
2497
  }
2474
2498
  }
2475
2499
  function it(i, e, t) {
2476
- const n = [], r = We(i, t, (a) => {
2477
- n.push(a);
2478
- }), s = new _t(i, e, t);
2479
- async function _() {
2500
+ const n = [], r = We(i, t, (_) => {
2501
+ n.push(_);
2502
+ }), s = new at(i, e, t);
2503
+ async function a() {
2480
2504
  if (n.length === 0)
2481
2505
  return;
2482
- const a = await i.semaphore.acquire(), S = [...n];
2506
+ const _ = await i.semaphore.acquire(), S = [...n];
2483
2507
  n.splice(0, S.length);
2484
2508
  const c = be(S);
2485
2509
  try {
2486
- for (const A of c)
2487
- await s.processEntry(A);
2510
+ for (const C of c)
2511
+ await s.processEntry(C);
2488
2512
  } finally {
2489
- a();
2513
+ _();
2490
2514
  }
2491
2515
  }
2492
- return i.addEventListener("request.end", _), i.addEventListener("filesystem.write", _), function() {
2493
- r(), i.removeEventListener("request.end", _), i.removeEventListener("filesystem.write", _);
2516
+ return i.addEventListener("request.end", a), i.addEventListener("filesystem.write", a), function() {
2517
+ r(), i.removeEventListener("request.end", a), i.removeEventListener("filesystem.write", a);
2494
2518
  };
2495
2519
  }
2496
- class _t {
2520
+ class at {
2497
2521
  constructor(e, t, n) {
2498
- this.php = e, this.opfs = t, this.memfsRoot = re(n);
2522
+ this.php = e, this.opfs = t, this.memfsRoot = se(n);
2499
2523
  }
2500
2524
  toOpfsPath(e) {
2501
- return re(e.substring(this.memfsRoot.length));
2525
+ return se(e.substring(this.memfsRoot.length));
2502
2526
  }
2503
2527
  async processEntry(e) {
2504
2528
  if (!e.path.startsWith(this.memfsRoot) || e.path === this.memfsRoot)
2505
2529
  return;
2506
- const t = this.toOpfsPath(e.path), n = await se(this.opfs, t), r = at(t);
2530
+ const t = this.toOpfsPath(e.path), n = await ie(this.opfs, t), r = _t(t);
2507
2531
  if (r)
2508
2532
  try {
2509
2533
  if (e.operation === "DELETE")
@@ -2520,27 +2544,27 @@ class _t {
2520
2544
  create: !0
2521
2545
  });
2522
2546
  else if (e.operation === "WRITE")
2523
- await O(
2547
+ await j(
2524
2548
  n,
2525
2549
  r,
2526
- this.php[k].FS,
2550
+ this.php[F].FS,
2527
2551
  e.path
2528
2552
  );
2529
2553
  else if (e.operation === "RENAME" && e.toPath.startsWith(this.memfsRoot)) {
2530
- const s = this.toOpfsPath(e.toPath), _ = await se(
2554
+ const s = this.toOpfsPath(e.toPath), a = await ie(
2531
2555
  this.opfs,
2532
2556
  s
2533
2557
  );
2534
2558
  if (e.nodeType === "directory") {
2535
- const a = await _.getDirectoryHandle(
2559
+ const _ = await a.getDirectoryHandle(
2536
2560
  r,
2537
2561
  {
2538
2562
  create: !0
2539
2563
  }
2540
2564
  );
2541
- await Te(
2542
- this.php[k].FS,
2543
- a,
2565
+ await fe(
2566
+ this.php[F].FS,
2567
+ _,
2544
2568
  e.toPath
2545
2569
  ), await n.removeEntry(r, {
2546
2570
  recursive: !0
@@ -2550,10 +2574,10 @@ class _t {
2550
2574
  await n.removeEntry(r);
2551
2575
  } catch {
2552
2576
  }
2553
- await O(
2554
- _,
2577
+ await j(
2578
+ a,
2555
2579
  Ie(s),
2556
- this.php[k].FS,
2580
+ this.php[F].FS,
2557
2581
  e.toPath
2558
2582
  );
2559
2583
  }
@@ -2563,31 +2587,31 @@ class _t {
2563
2587
  }
2564
2588
  }
2565
2589
  }
2566
- function re(i) {
2590
+ function se(i) {
2567
2591
  return i.replace(/\/$/, "").replace(/\/\/+/g, "/");
2568
2592
  }
2569
- function at(i) {
2593
+ function _t(i) {
2570
2594
  return i.substring(i.lastIndexOf("/") + 1);
2571
2595
  }
2572
- async function se(i, e) {
2596
+ async function ie(i, e) {
2573
2597
  const t = e.replace(/^\/+|\/+$/g, "").replace(/\/+/, "/");
2574
2598
  if (!t)
2575
2599
  return i;
2576
2600
  const n = t.split("/");
2577
2601
  let r = i;
2578
2602
  for (let s = 0; s < n.length - 1; s++) {
2579
- const _ = n[s];
2580
- r = await r.getDirectoryHandle(_, { create: !0 });
2603
+ const a = n[s];
2604
+ r = await r.getDirectoryHandle(a, { create: !0 });
2581
2605
  }
2582
2606
  return r;
2583
2607
  }
2584
2608
  function ot(i, e) {
2585
2609
  let t = 0, n, r;
2586
- return function(..._) {
2587
- r = _;
2588
- const a = Date.now() - t;
2610
+ return function(...a) {
2611
+ r = a;
2612
+ const _ = Date.now() - t;
2589
2613
  if (n === void 0) {
2590
- const S = Math.max(0, e - a);
2614
+ const S = Math.max(0, e - _);
2591
2615
  n = setTimeout(() => {
2592
2616
  n = void 0, t = Date.now(), i(...r);
2593
2617
  }, S);
@@ -2595,17 +2619,17 @@ function ot(i, e) {
2595
2619
  };
2596
2620
  }
2597
2621
  export {
2598
- Kt as FirewallInterferenceError,
2599
- Ht as certificateToPEM,
2600
- mt as consumeAPI,
2601
- wt as createDirectoryHandleMountHandler,
2602
- gt as exposeAPI,
2603
- Dt as fetchWithCorsProxy,
2622
+ Dt as FirewallInterferenceError,
2623
+ dt as certificateToPEM,
2624
+ gt as consumeAPI,
2625
+ Lt as createDirectoryHandleMountHandler,
2626
+ It as exposeAPI,
2627
+ Wt as fetchWithCorsProxy,
2604
2628
  je as generateCertificate,
2605
2629
  Pe as getPHPLoaderModule,
2606
- Tt as loadWebRuntime,
2607
- dt as privateKeyToPEM,
2608
- ft as setupPostMessageRelay,
2609
- pt as spawnPHPWorkerThread
2630
+ ft as loadWebRuntime,
2631
+ Et as privateKeyToPEM,
2632
+ pt as setupPostMessageRelay,
2633
+ wt as spawnPHPWorkerThread
2610
2634
  };
2611
2635
  //# sourceMappingURL=index.js.map