@php-wasm/web-service-worker 3.1.5 → 3.1.9

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 (3) hide show
  1. package/index.cjs +1 -1
  2. package/index.js +126 -107
  3. package/package.json +7 -6
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("@php-wasm/scopes"),U=25e3;let P=0;function T(e,t,...r){const s=R();return e.postMessage({...t,requestId:s},...r),s}function R(){return++P}function m(e,t,r=U){return new Promise((s,n)=>{const o=i=>{i.data.type==="response"&&i.data.requestId===t&&(e.removeEventListener("message",o),clearTimeout(a),s(i.data.response))},a=setTimeout(()=>{n(new Error("Request timed out")),e.removeEventListener("message",o)},r);e.addEventListener("message",o)})}function x(e,t){return{type:"response",requestId:e,response:t}}async function q(e){let t=new URL(e.request.url);if(!w.isURLScoped(t))try{const c=new URL(e.request.referrer);t=w.setURLScope(t,w.getURLScope(c))}catch{}const r=e.request.headers.get("content-type"),s=e.request.method==="POST"?new Uint8Array(await e.request.clone().arrayBuffer()):void 0,n={};for(const c of e.request.headers.entries())n[c[0]]=c[1];let o;try{const c={method:"request",args:[{body:s,url:t.toString(),method:e.request.method,headers:{...n,Host:t.host,"User-agent":self.navigator.userAgent,"Content-type":r}}]},h=w.getURLScope(t);if(h===null)throw new Error(`The URL ${t.toString()} is not scoped. This should not happen.`);const f=await g(c,h);if(o=await m(self,f),delete o.headers["x-frame-options"],o.headers["content-security-policy"]){const l=o.headers["content-security-policy"].map(u=>E("frame-ancestors",u)).filter(u=>u.trim().length>0);l.length>0?o.headers["content-security-policy"]=l:delete o.headers["content-security-policy"]}}catch(c){throw console.error(c,{url:t.toString()}),c}if(o.httpStatusCode>=300&&o.httpStatusCode<=399&&o.headers.location)return Response.redirect(new URL(o.headers.location[0],t.toString()),o.httpStatusCode);const i=[101,103,204,205,304].includes(o.httpStatusCode)?null:o.bytes;return new Response(i,{headers:o.headers,status:o.httpStatusCode})}async function g(e,t){const r=R();for(const s of await self.clients.matchAll({includeUncontrolled:!0}))s.postMessage({...e,scope:t,requestId:r});return r}async function d(e,t){let r;return["GET","HEAD"].includes(e.method)||"body"in t?r=void 0:!e.bodyUsed&&e.body?r=e.body:r=await e.arrayBuffer(),new Request(t.url||e.url,{body:r,method:e.method,headers:e.headers,referrer:e.referrer,referrerPolicy:e.referrerPolicy,mode:e.mode==="navigate"?"same-origin":e.mode,credentials:e.credentials,cache:e.cache,redirect:e.redirect,integrity:e.integrity,...r instanceof ReadableStream&&{duplex:"half"},...t})}async function b(e){if(!e.body)return[e,e];const[t,r]=e.body.tee();return[await d(e,{body:t,duplex:"half"}),await d(e,{body:r,duplex:"half"})]}function H(e){const t={};return e.headers.forEach((r,s)=>{t[s]=r}),t}function E(e,t){const r=/^[\u{9}\u{A}\u{C}\u{D}\u{20}]+/u,s=/[\u{9}\u{A}\u{C}\u{D}\u{20}]+$/u,n=/[\u{9}\u{A}\u{C}\u{D}\u{20}]/u;return t.split(";").filter(o=>{const a=o.replace(r,"").replace(s,""),[i]=a.split(n,1);return i.toLowerCase()!==e.toLowerCase()}).join(";")}class S extends Error{constructor(t,r,s){super(`Could not fetch ${t} – your network appears to be blocking this request (HTTP ${r}). This often happens on school, university, or corporate networks. Try switching to a different network or using a VPN.`),this.name="FirewallInterferenceError",this.url=t,this.status=r,this.statusText=s}}const v="X-Playground-Cors-Proxy";async function A(e,t,r,s){var f;let n=typeof e=="string"?new Request(e,t):e;const o=s?new URL(s):null;let a=o?new URL(n.url,o):new URL(n.url);if(a.hostname==="localhost"||a.hostname==="127.0.0.1"||a.hostname==="[::1]"||a.hostname==="::1")return await p(n);if(a.protocol==="http:"){a.protocol="https:";const l=a.toString();n=await d(n,{url:l}),a=new URL(l)}if(!r)return await p(n);if(o&&a.protocol===o.protocol&&a.hostname===o.hostname&&a.port===o.port&&a.pathname.startsWith(o.pathname))return await p(n);const[c,h]=await b(n);try{return await p(c)}catch{const u=((f=new Headers(h.headers).get("x-cors-proxy-allowed-request-headers"))==null?void 0:f.split(","))||[],C=u.includes("authorization")||u.includes("cookie"),L=await d(h,{url:`${r}${n.url}`,...C&&{credentials:"include"}}),y=await p(L,t);if(!y.headers.has(v))throw new S(n.url,y.status,y.statusText);return y}}async function p(e,t){let r=t?new Request(e,t):e;if(new URL(r.url).protocol==="http:"&&r.body){const s=await new Response(r.body).arrayBuffer();r=await d(r,{body:s})}return fetch(r)}exports.FirewallInterferenceError=S;exports.awaitReply=m;exports.broadcastMessageExpectReply=g;exports.cloneRequest=d;exports.convertFetchEventToPHPRequest=q;exports.fetchWithCorsProxy=A;exports.getNextRequestId=R;exports.getRequestHeaders=H;exports.postMessageExpectReply=T;exports.removeContentSecurityPolicyDirective=E;exports.responseTo=x;exports.teeRequest=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@php-wasm/scopes"),q=require("@php-wasm/universal");var g=typeof document<"u"?document.currentScript:null;const I=25e3;let H=0;function v(e,t,...r){const n=S();return e.postMessage({...t,requestId:n},...r),n}function S(){return++H}function U(e,t,r=I){return new Promise((n,a)=>{const o=u=>{u.data.type==="response"&&u.data.requestId===t&&(e.removeEventListener("message",o),clearTimeout(s),n(u.data.response))},s=setTimeout(()=>{a(new Error("Request timed out")),e.removeEventListener("message",o)},r);e.addEventListener("message",o)})}function A(e,t){return{type:"response",requestId:e,response:t}}async function O(e){let t=new URL(e.request.url);if(!d.isURLScoped(t))try{const c=new URL(e.request.referrer);t=d.setURLScope(t,d.getURLScope(c))}catch{}const r=e.request.headers.get("content-type"),n=e.request.method==="POST"?new Uint8Array(await e.request.clone().arrayBuffer()):void 0,a={};for(const c of e.request.headers.entries())a[c[0]]=c[1];let o;try{const c={method:"request",args:[{body:n,url:t.toString(),method:e.request.method,headers:{...a,Host:t.host,"User-agent":self.navigator.userAgent,"Content-type":r}}]},i=d.getURLScope(t);if(i===null)throw new Error(`The URL ${t.toString()} is not scoped. This should not happen.`);const f=await b(c,i);if(o=await U(self,f),delete o.headers["x-frame-options"],o.headers["content-security-policy"]){const l=o.headers["content-security-policy"].map(p=>C("frame-ancestors",p)).filter(p=>p.trim().length>0);l.length>0?o.headers["content-security-policy"]=l:delete o.headers["content-security-policy"]}}catch(c){throw console.error(c,{url:t.toString()}),c}if(o.httpStatusCode>=300&&o.httpStatusCode<=399&&o.headers.location){const c=d.getURLScope(t);let i=new URL(o.headers.location[0],t.toString());return c&&!d.isURLScoped(i)&&(i=d.setURLScope(i,c)),Response.redirect(i.toString(),o.httpStatusCode)}const s=[101,103,204,205,304].includes(o.httpStatusCode);let u=null;return s||(o.bodyPort?u=q.portToStream(o.bodyPort):u=o.bytes),new Response(u,{headers:o.headers,status:o.httpStatusCode})}async function b(e,t){const r=S();for(const n of await self.clients.matchAll({includeUncontrolled:!0}))n.postMessage({...e,scope:t,requestId:r});return r}async function h(e,t){let r;return["GET","HEAD"].includes(e.method)?r=void 0:"body"in t?r=t.body:!e.bodyUsed&&e.body?r=e.body:r=await e.arrayBuffer(),new Request(t.url||e.url,{body:r,method:e.method,headers:e.headers,referrer:e.referrer,referrerPolicy:e.referrerPolicy,mode:e.mode==="navigate"?"same-origin":e.mode,credentials:e.credentials,cache:e.cache,redirect:e.redirect,integrity:e.integrity,...r instanceof ReadableStream&&{duplex:"half"},...t})}async function L(e){if(!e.body)return[e,e];const[t,r]=e.body.tee();return[await h(e,{body:t,duplex:"half"}),await h(e,{body:r,duplex:"half"})]}function D(e){const t={};return e.headers.forEach((r,n)=>{t[n]=r}),t}function C(e,t){const r=/^[\u{9}\u{A}\u{C}\u{D}\u{20}]+/u,n=/[\u{9}\u{A}\u{C}\u{D}\u{20}]+$/u,a=/[\u{9}\u{A}\u{C}\u{D}\u{20}]/u;return t.split(";").filter(o=>{const s=o.replace(r,"").replace(n,""),[u]=s.split(a,1);return u.toLowerCase()!==e.toLowerCase()}).join(";")}class T extends Error{constructor(t,r,n){super(`Could not fetch ${t} – your network appears to be blocking this request (HTTP ${r}). This often happens on school, university, or corporate networks. Try switching to a different network or using a VPN.`),this.name="FirewallInterferenceError",this.url=t,this.status=r,this.statusText=n}}const M="X-Playground-Cors-Proxy";async function j(e,t,r,n){var f;let a=typeof e=="string"?new Request(e,t):e;const o=n?new URL(n):null;let s=o?new URL(a.url,o):new URL(a.url);if(s.hostname==="localhost"||s.hostname==="127.0.0.1"||s.hostname==="[::1]"||s.hostname==="::1")return await fetch(a);if(s.protocol==="http:"){s.protocol="https:";const l=s.toString();a=await h(a,{url:l}),s=new URL(l)}if(!r)return await fetch(a);if(o&&s.protocol===o.protocol&&s.hostname===o.hostname&&s.port===o.port&&s.pathname.startsWith(o.pathname))return await fetch(a);const[c,i]=await L(a);try{return await fetch(c)}catch{const l=new Headers(i.headers),p=((f=l.get("x-cors-proxy-allowed-request-headers"))==null?void 0:f.split(","))||[],E=p.includes("authorization")||p.includes("cookie"),m=l.get("content-type");m&&m.toLowerCase().includes("multipart/form-data")&&(l.set("x-cors-proxy-content-type",m),l.set("content-type","application/octet-stream"));const y=new URL(typeof document>"u"?require("url").pathToFileURL(__filename).href:g&&g.tagName.toUpperCase()==="SCRIPT"&&g.src||new URL("index.cjs",document.baseURI).href);y.pathname="",y.search="",y.hash="";const P=new URL(r,y.toString());let w=i.body;w&&new URL(P).protocol==="http:"&&(w=await new Response(w).arrayBuffer());const x=await h(i,{url:`${r}${a.url}`,headers:l,body:w,...E&&{credentials:"include"}}),R=await fetch(x);if(!R.headers.has(M))throw new T(a.url,R.status,R.statusText);return R}}exports.FirewallInterferenceError=T;exports.awaitReply=U;exports.broadcastMessageExpectReply=b;exports.cloneRequest=h;exports.convertFetchEventToPHPRequest=O;exports.fetchWithCorsProxy=j;exports.getNextRequestId=S;exports.getRequestHeaders=D;exports.postMessageExpectReply=v;exports.removeContentSecurityPolicyDirective=C;exports.responseTo=A;exports.teeRequest=L;
package/index.js CHANGED
@@ -1,58 +1,59 @@
1
- import { isURLScoped as b, setURLScope as C, getURLScope as w } from "@php-wasm/scopes";
2
- const E = 25e3;
3
- let L = 0;
4
- function H(e, t, ...r) {
5
- const s = m();
1
+ import { isURLScoped as g, setURLScope as b, getURLScope as R } from "@php-wasm/scopes";
2
+ import { portToStream as E } from "@php-wasm/universal";
3
+ const T = 25e3;
4
+ let x = 0;
5
+ function j(e, t, ...r) {
6
+ const n = L();
6
7
  return e.postMessage(
7
8
  {
8
9
  ...t,
9
- requestId: s
10
+ requestId: n
10
11
  },
11
12
  ...r
12
- ), s;
13
+ ), n;
13
14
  }
14
- function m() {
15
- return ++L;
15
+ function L() {
16
+ return ++x;
16
17
  }
17
- function S(e, t, r = E) {
18
- return new Promise((s, n) => {
19
- const o = (c) => {
20
- c.data.type === "response" && c.data.requestId === t && (e.removeEventListener("message", o), clearTimeout(a), s(c.data.response));
21
- }, a = setTimeout(() => {
22
- n(new Error("Request timed out")), e.removeEventListener("message", o);
18
+ function P(e, t, r = T) {
19
+ return new Promise((n, a) => {
20
+ const o = (u) => {
21
+ u.data.type === "response" && u.data.requestId === t && (e.removeEventListener("message", o), clearTimeout(s), n(u.data.response));
22
+ }, s = setTimeout(() => {
23
+ a(new Error("Request timed out")), e.removeEventListener("message", o);
23
24
  }, r);
24
25
  e.addEventListener("message", o);
25
26
  });
26
27
  }
27
- function I(e, t) {
28
+ function k(e, t) {
28
29
  return {
29
30
  type: "response",
30
31
  requestId: e,
31
32
  response: t
32
33
  };
33
34
  }
34
- async function O(e) {
35
+ async function v(e) {
35
36
  let t = new URL(e.request.url);
36
- if (!b(t))
37
+ if (!g(t))
37
38
  try {
38
- const i = new URL(e.request.referrer);
39
- t = C(t, w(i));
39
+ const c = new URL(e.request.referrer);
40
+ t = b(t, R(c));
40
41
  } catch {
41
42
  }
42
- const r = e.request.headers.get("content-type"), s = e.request.method === "POST" ? new Uint8Array(await e.request.clone().arrayBuffer()) : void 0, n = {};
43
- for (const i of e.request.headers.entries())
44
- n[i[0]] = i[1];
43
+ const r = e.request.headers.get("content-type"), n = e.request.method === "POST" ? new Uint8Array(await e.request.clone().arrayBuffer()) : void 0, a = {};
44
+ for (const c of e.request.headers.entries())
45
+ a[c[0]] = c[1];
45
46
  let o;
46
47
  try {
47
- const i = {
48
+ const c = {
48
49
  method: "request",
49
50
  args: [
50
51
  {
51
- body: s,
52
+ body: n,
52
53
  url: t.toString(),
53
54
  method: e.request.method,
54
55
  headers: {
55
- ...n,
56
+ ...a,
56
57
  Host: t.host,
57
58
  // Safari and Firefox don't make the User-Agent header
58
59
  // available in the fetch event. Let's add it manually:
@@ -61,47 +62,54 @@ async function O(e) {
61
62
  }
62
63
  }
63
64
  ]
64
- }, d = w(t);
65
- if (d === null)
65
+ }, i = R(t);
66
+ if (i === null)
66
67
  throw new Error(
67
68
  `The URL ${t.toString()} is not scoped. This should not happen.`
68
69
  );
69
- const f = await U(i, d);
70
- if (o = await S(self, f), delete o.headers["x-frame-options"], o.headers["content-security-policy"]) {
70
+ const h = await A(c, i);
71
+ if (o = await P(self, h), delete o.headers["x-frame-options"], o.headers["content-security-policy"]) {
71
72
  const l = o.headers["content-security-policy"].map(
72
- (u) => x(
73
+ (d) => q(
73
74
  "frame-ancestors",
74
- u
75
+ d
75
76
  )
76
- ).filter((u) => u.trim().length > 0);
77
+ ).filter((d) => d.trim().length > 0);
77
78
  l.length > 0 ? o.headers["content-security-policy"] = l : delete o.headers["content-security-policy"];
78
79
  }
79
- } catch (i) {
80
- throw console.error(i, { url: t.toString() }), i;
80
+ } catch (c) {
81
+ throw console.error(c, { url: t.toString() }), c;
81
82
  }
82
- if (o.httpStatusCode >= 300 && o.httpStatusCode <= 399 && o.headers.location)
83
- return Response.redirect(
84
- new URL(o.headers.location[0], t.toString()),
83
+ if (o.httpStatusCode >= 300 && o.httpStatusCode <= 399 && o.headers.location) {
84
+ const c = R(t);
85
+ let i = new URL(
86
+ o.headers.location[0],
87
+ t.toString()
88
+ );
89
+ return c && !g(i) && (i = b(i, c)), Response.redirect(
90
+ i.toString(),
85
91
  o.httpStatusCode
86
92
  );
87
- const c = [101, 103, 204, 205, 304].includes(
93
+ }
94
+ const s = [101, 103, 204, 205, 304].includes(
88
95
  o.httpStatusCode
89
- ) ? null : o.bytes;
90
- return new Response(c, {
96
+ );
97
+ let u = null;
98
+ return s || (o.bodyPort ? u = E(o.bodyPort) : u = o.bytes), new Response(u, {
91
99
  headers: o.headers,
92
100
  status: o.httpStatusCode
93
101
  });
94
102
  }
95
- async function U(e, t) {
96
- const r = m();
97
- for (const s of await self.clients.matchAll({
103
+ async function A(e, t) {
104
+ const r = L();
105
+ for (const n of await self.clients.matchAll({
98
106
  // Sometimes the client that triggered the current fetch()
99
107
  // event is considered uncontrolled in Google Chrome. This
100
108
  // only happens on the first few fetches() after the initial
101
109
  // registration of the service worker.
102
110
  includeUncontrolled: !0
103
111
  }))
104
- s.postMessage({
112
+ n.postMessage({
105
113
  ...e,
106
114
  /**
107
115
  * Attach the scope with a URL starting with `/scope:` to this message.
@@ -115,9 +123,9 @@ async function U(e, t) {
115
123
  });
116
124
  return r;
117
125
  }
118
- async function p(e, t) {
126
+ async function w(e, t) {
119
127
  let r;
120
- return ["GET", "HEAD"].includes(e.method) || "body" in t ? r = void 0 : !e.bodyUsed && e.body ? r = e.body : r = await e.arrayBuffer(), new Request(t.url || e.url, {
128
+ return ["GET", "HEAD"].includes(e.method) ? r = void 0 : "body" in t ? r = t.body : !e.bodyUsed && e.body ? r = e.body : r = await e.arrayBuffer(), new Request(t.url || e.url, {
121
129
  body: r,
122
130
  method: e.method,
123
131
  headers: e.headers,
@@ -128,98 +136,109 @@ async function p(e, t) {
128
136
  cache: e.cache,
129
137
  redirect: e.redirect,
130
138
  integrity: e.integrity,
139
+ /**
140
+ * Infer the duplex value in a way that's consistent across browsers. Web browsers
141
+ * only support 'half' as of January 2026, but other values may be supported in the future.
142
+ * Unfortunately, also as of January 2026, we cannot read the duplex value directly from the
143
+ * request object:
144
+ *
145
+ * > Although duplex can be passed as an option when constructing a Request,
146
+ * > it is not currently exposed as a readable property on the resulting Request
147
+ * > object in all browsers.
148
+ *
149
+ * See MDN: https://developer.mozilla.org/en-US/docs/Web/API/Request/duplex
150
+ */
131
151
  ...r instanceof ReadableStream && { duplex: "half" },
132
152
  ...t
133
153
  });
134
154
  }
135
- async function T(e) {
155
+ async function H(e) {
136
156
  if (!e.body)
137
157
  return [e, e];
138
158
  const [t, r] = e.body.tee();
139
159
  return [
140
- await p(e, { body: t, duplex: "half" }),
141
- await p(e, { body: r, duplex: "half" })
160
+ await w(e, { body: t, duplex: "half" }),
161
+ await w(e, { body: r, duplex: "half" })
142
162
  ];
143
163
  }
144
- function D(e) {
164
+ function B(e) {
145
165
  const t = {};
146
- return e.headers.forEach((r, s) => {
147
- t[s] = r;
166
+ return e.headers.forEach((r, n) => {
167
+ t[n] = r;
148
168
  }), t;
149
169
  }
150
- function x(e, t) {
151
- const r = /^[\u{9}\u{A}\u{C}\u{D}\u{20}]+/u, s = /[\u{9}\u{A}\u{C}\u{D}\u{20}]+$/u, n = /[\u{9}\u{A}\u{C}\u{D}\u{20}]/u;
170
+ function q(e, t) {
171
+ const r = /^[\u{9}\u{A}\u{C}\u{D}\u{20}]+/u, n = /[\u{9}\u{A}\u{C}\u{D}\u{20}]+$/u, a = /[\u{9}\u{A}\u{C}\u{D}\u{20}]/u;
152
172
  return t.split(";").filter((o) => {
153
- const a = o.replace(r, "").replace(s, ""), [c] = a.split(
154
- n,
173
+ const s = o.replace(r, "").replace(n, ""), [u] = s.split(
174
+ a,
155
175
  // The directive name is the first token.
156
176
  1
157
177
  );
158
- return c.toLowerCase() !== e.toLowerCase();
178
+ return u.toLowerCase() !== e.toLowerCase();
159
179
  }).join(";");
160
180
  }
161
- class P extends Error {
162
- constructor(t, r, s) {
181
+ class I extends Error {
182
+ constructor(t, r, n) {
163
183
  super(
164
184
  `Could not fetch ${t} – your network appears to be blocking this request (HTTP ${r}). This often happens on school, university, or corporate networks. Try switching to a different network or using a VPN.`
165
- ), this.name = "FirewallInterferenceError", this.url = t, this.status = r, this.statusText = s;
185
+ ), this.name = "FirewallInterferenceError", this.url = t, this.status = r, this.statusText = n;
166
186
  }
167
187
  }
168
- const A = "X-Playground-Cors-Proxy";
169
- async function v(e, t, r, s) {
170
- var f;
171
- let n = typeof e == "string" ? new Request(e, t) : e;
172
- const o = s ? new URL(s) : null;
173
- let a = o ? new URL(n.url, o) : new URL(n.url);
174
- if (a.hostname === "localhost" || a.hostname === "127.0.0.1" || a.hostname === "[::1]" || a.hostname === "::1")
175
- return await h(n);
176
- if (a.protocol === "http:") {
177
- a.protocol = "https:";
178
- const l = a.toString();
179
- n = await p(n, { url: l }), a = new URL(l);
188
+ const O = "X-Playground-Cors-Proxy";
189
+ async function M(e, t, r, n) {
190
+ var h;
191
+ let a = typeof e == "string" ? new Request(e, t) : e;
192
+ const o = n ? new URL(n) : null;
193
+ let s = o ? new URL(a.url, o) : new URL(a.url);
194
+ if (s.hostname === "localhost" || s.hostname === "127.0.0.1" || s.hostname === "[::1]" || s.hostname === "::1")
195
+ return await fetch(a);
196
+ if (s.protocol === "http:") {
197
+ s.protocol = "https:";
198
+ const l = s.toString();
199
+ a = await w(a, { url: l }), s = new URL(l);
180
200
  }
181
201
  if (!r)
182
- return await h(n);
183
- if (o && a.protocol === o.protocol && a.hostname === o.hostname && a.port === o.port && a.pathname.startsWith(o.pathname))
184
- return await h(n);
185
- const [i, d] = await T(n);
202
+ return await fetch(a);
203
+ if (o && s.protocol === o.protocol && s.hostname === o.hostname && s.port === o.port && s.pathname.startsWith(o.pathname))
204
+ return await fetch(a);
205
+ const [c, i] = await H(a);
186
206
  try {
187
- return await h(i);
207
+ return await fetch(c);
188
208
  } catch {
189
- const u = ((f = new Headers(d.headers).get("x-cors-proxy-allowed-request-headers")) == null ? void 0 : f.split(",")) || [], R = u.includes("authorization") || u.includes("cookie"), g = await p(d, {
190
- url: `${r}${n.url}`,
191
- ...R && { credentials: "include" }
192
- }), y = await h(g, t);
193
- if (!y.headers.has(A))
194
- throw new P(
195
- n.url,
209
+ const l = new Headers(i.headers), d = ((h = l.get("x-cors-proxy-allowed-request-headers")) == null ? void 0 : h.split(",")) || [], U = d.includes("authorization") || d.includes("cookie"), m = l.get("content-type");
210
+ m && m.toLowerCase().includes("multipart/form-data") && (l.set("x-cors-proxy-content-type", m), l.set("content-type", "application/octet-stream"));
211
+ const p = new URL(import.meta.url);
212
+ p.pathname = "", p.search = "", p.hash = "";
213
+ const S = new URL(r, p.toString());
214
+ let f = i.body;
215
+ f && new URL(S).protocol === "http:" && (f = await new Response(f).arrayBuffer());
216
+ const C = await w(i, {
217
+ url: `${r}${a.url}`,
218
+ headers: l,
219
+ body: f,
220
+ ...U && { credentials: "include" }
221
+ }), y = await fetch(C);
222
+ if (!y.headers.has(O))
223
+ throw new I(
224
+ a.url,
196
225
  y.status,
197
226
  y.statusText
198
227
  );
199
228
  return y;
200
229
  }
201
230
  }
202
- async function h(e, t) {
203
- let r = t ? new Request(e, t) : e;
204
- if (new URL(r.url).protocol === "http:" && r.body) {
205
- const s = await new Response(r.body).arrayBuffer();
206
- r = await p(r, {
207
- body: s
208
- });
209
- }
210
- return fetch(r);
211
- }
212
231
  export {
213
- P as FirewallInterferenceError,
214
- S as awaitReply,
215
- U as broadcastMessageExpectReply,
216
- p as cloneRequest,
217
- O as convertFetchEventToPHPRequest,
218
- v as fetchWithCorsProxy,
219
- m as getNextRequestId,
220
- D as getRequestHeaders,
221
- H as postMessageExpectReply,
222
- x as removeContentSecurityPolicyDirective,
223
- I as responseTo,
224
- T as teeRequest
232
+ I as FirewallInterferenceError,
233
+ P as awaitReply,
234
+ A as broadcastMessageExpectReply,
235
+ w as cloneRequest,
236
+ v as convertFetchEventToPHPRequest,
237
+ M as fetchWithCorsProxy,
238
+ L as getNextRequestId,
239
+ B as getRequestHeaders,
240
+ j as postMessageExpectReply,
241
+ q as removeContentSecurityPolicyDirective,
242
+ k as responseTo,
243
+ H as teeRequest
225
244
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web-service-worker",
3
- "version": "3.1.5",
3
+ "version": "3.1.9",
4
4
  "description": "PHP.wasm – service worker utils",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,11 +31,16 @@
31
31
  "main": "./index.cjs",
32
32
  "module": "./index.js",
33
33
  "license": "GPL-2.0-or-later",
34
- "gitHead": "e10df5885055e97c87ce88fe5e9d8d4ac3e700da",
34
+ "gitHead": "97cf88501a336453baaac9a860a17329235a71fb",
35
35
  "engines": {
36
36
  "node": ">=20.10.0",
37
37
  "npm": ">=10.2.3"
38
38
  },
39
+ "dependencies": {
40
+ "ini": "4.1.2",
41
+ "@php-wasm/scopes": "3.1.9",
42
+ "@php-wasm/universal": "3.1.9"
43
+ },
39
44
  "packageManager": "npm@10.9.2",
40
45
  "overrides": {
41
46
  "rollup": "^4.34.6",
@@ -43,13 +48,9 @@
43
48
  "react-dom": "18.3.1",
44
49
  "typescript": "5.4.5",
45
50
  "@playwright/test": "1.55.1",
46
- "ws": "8.18.3",
47
51
  "tmp": "0.2.5",
48
52
  "form-data": "^4.0.4",
49
53
  "lodash": "^4.17.23",
50
54
  "glob": "^9.3.0"
51
- },
52
- "dependencies": {
53
- "@php-wasm/scopes": "3.1.5"
54
55
  }
55
56
  }