@php-wasm/universal 2.0.4 → 2.0.7
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.cjs +3 -3
- package/index.cjs.map +1 -1
- package/index.js +38 -21
- package/index.js.map +1 -1
- package/lib/php-response.d.ts +5 -0
- package/package.json +7 -7
package/index.js
CHANGED
|
@@ -558,12 +558,7 @@ class StreamedPHPResponse {
|
|
|
558
558
|
* Resolves once HTTP status code is available.
|
|
559
559
|
*/
|
|
560
560
|
get httpStatusCode() {
|
|
561
|
-
return
|
|
562
|
-
this.getParsedHeaders().then((e) => e.httpStatusCode),
|
|
563
|
-
this.exitCode.then(
|
|
564
|
-
(e) => e !== 0 ? 500 : void 0
|
|
565
|
-
)
|
|
566
|
-
]).then((e) => e !== void 0 ? e : this.getParsedHeaders().then(
|
|
561
|
+
return this.getParsedHeaders().then((e) => e.httpStatusCode).then((e) => e !== void 0 ? e : this.getParsedHeaders().then(
|
|
567
562
|
(r) => r.httpStatusCode,
|
|
568
563
|
() => 200
|
|
569
564
|
)).catch(() => 500);
|
|
@@ -644,6 +639,13 @@ class PHPResponse {
|
|
|
644
639
|
await e.exitCode
|
|
645
640
|
);
|
|
646
641
|
}
|
|
642
|
+
/**
|
|
643
|
+
* True if the response is successful (HTTP status code 200-399),
|
|
644
|
+
* false otherwise.
|
|
645
|
+
*/
|
|
646
|
+
ok() {
|
|
647
|
+
return this.httpStatusCode >= 200 && this.httpStatusCode < 400;
|
|
648
|
+
}
|
|
647
649
|
toRawData() {
|
|
648
650
|
return {
|
|
649
651
|
headers: this.headers,
|
|
@@ -1297,8 +1299,8 @@ class PHP {
|
|
|
1297
1299
|
`The script path "${t.scriptPath}" does not exist.`
|
|
1298
1300
|
);
|
|
1299
1301
|
m(this, h, $).call(this, t.relativeUri || ""), m(this, h, J).call(this, t.method || "GET");
|
|
1300
|
-
const
|
|
1301
|
-
if (m(this, h, B).call(this,
|
|
1302
|
+
const i = normalizeHeaders(t.headers || {}), o = i.host || "example.com:443", a = m(this, h, G).call(this, o, t.protocol || "http");
|
|
1303
|
+
if (m(this, h, B).call(this, o), m(this, h, V).call(this, a), m(this, h, Y).call(this, i), t.body && (r = m(this, h, K).call(this, t.body)), typeof t.code == "string")
|
|
1302
1304
|
this.writeFile("/internal/eval.php", t.code), m(this, h, L).call(this, "/internal/eval.php");
|
|
1303
1305
|
else if (typeof t.scriptPath == "string")
|
|
1304
1306
|
m(this, h, L).call(this, t.scriptPath || "");
|
|
@@ -1306,12 +1308,12 @@ class PHP {
|
|
|
1306
1308
|
throw new TypeError(
|
|
1307
1309
|
"The request object must have either a `code` or a `scriptPath` property."
|
|
1308
1310
|
);
|
|
1309
|
-
const
|
|
1310
|
-
for (const
|
|
1311
|
-
m(this, h, X).call(this,
|
|
1312
|
-
const
|
|
1313
|
-
for (const
|
|
1314
|
-
m(this, h, O).call(this,
|
|
1311
|
+
const c = m(this, h, z).call(this, t.$_SERVER, i, a);
|
|
1312
|
+
for (const p in c)
|
|
1313
|
+
m(this, h, X).call(this, p, c[p]);
|
|
1314
|
+
const l = t.env || {};
|
|
1315
|
+
for (const p in l)
|
|
1316
|
+
m(this, h, O).call(this, p, l[p]);
|
|
1315
1317
|
return await this[__private__dont__use].ccall(
|
|
1316
1318
|
"wasm_sapi_handle_request",
|
|
1317
1319
|
NUMBER,
|
|
@@ -1319,14 +1321,23 @@ class PHP {
|
|
|
1319
1321
|
[],
|
|
1320
1322
|
{ async: !0 }
|
|
1321
1323
|
);
|
|
1322
|
-
})
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1324
|
+
}), n = () => {
|
|
1325
|
+
if (r)
|
|
1326
|
+
try {
|
|
1327
|
+
this[__private__dont__use].free(r);
|
|
1328
|
+
} catch (i) {
|
|
1329
|
+
logger.error(i);
|
|
1330
|
+
}
|
|
1326
1331
|
e(), this.dispatchEvent({
|
|
1327
1332
|
type: "request.end"
|
|
1328
1333
|
});
|
|
1329
|
-
}
|
|
1334
|
+
};
|
|
1335
|
+
return s.then(
|
|
1336
|
+
(i) => (i.finished.finally(n), i),
|
|
1337
|
+
(i) => {
|
|
1338
|
+
throw n(), i;
|
|
1339
|
+
}
|
|
1340
|
+
);
|
|
1330
1341
|
}
|
|
1331
1342
|
/**
|
|
1332
1343
|
* Defines a constant in the PHP runtime.
|
|
@@ -2438,8 +2449,14 @@ class PHPRequestHandler {
|
|
|
2438
2449
|
...e,
|
|
2439
2450
|
// Pass along URL with the #fragment filtered out
|
|
2440
2451
|
url: s.toString()
|
|
2441
|
-
};
|
|
2442
|
-
return
|
|
2452
|
+
}, c = await m(this, H, Z).call(this, a, o);
|
|
2453
|
+
return c.ok() && c.exitCode !== 0 ? new PHPResponse(
|
|
2454
|
+
500,
|
|
2455
|
+
c.headers,
|
|
2456
|
+
c.bytes,
|
|
2457
|
+
c.errors,
|
|
2458
|
+
c.exitCode
|
|
2459
|
+
) : c;
|
|
2443
2460
|
} else
|
|
2444
2461
|
return m(this, H, Q).call(this, i, o);
|
|
2445
2462
|
else
|