sandboxedjs 0.1.6 → 0.1.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/README.md +24 -19
- package/dist/index.cjs +39 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +39 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1545,6 +1545,22 @@ declare class Container {
|
|
|
1545
1545
|
headers?: Record<string, string>;
|
|
1546
1546
|
body?: string | Uint8Array;
|
|
1547
1547
|
}): Promise<HttpResponse>;
|
|
1548
|
+
/**
|
|
1549
|
+
* Deliver a request whose body is bytes, without letting them become text.
|
|
1550
|
+
*
|
|
1551
|
+
* Nodepod's public `request()` runs the body through `toString("utf8")` on
|
|
1552
|
+
* its way in, so anything above `0x7f` is replaced: a five-byte payload
|
|
1553
|
+
* containing `0x89` and `0xff` arrives as nine. That silently destroys every
|
|
1554
|
+
* upload — an image or a video reaches the server the wrong size and no
|
|
1555
|
+
* longer decodes, with no error raised anywhere.
|
|
1556
|
+
*
|
|
1557
|
+
* Its own dispatcher one layer down does preserve bytes, so a binary body
|
|
1558
|
+
* goes straight there. This reaches past the published surface deliberately,
|
|
1559
|
+
* so it is written to fail soft: any shape it does not recognise returns
|
|
1560
|
+
* `null` and the caller falls back to the ordinary path, which is exactly
|
|
1561
|
+
* the behaviour that existed before. Text bodies never come through here.
|
|
1562
|
+
*/
|
|
1563
|
+
private dispatchBinary;
|
|
1548
1564
|
/** Wait until something inside the container answers on `port`. */
|
|
1549
1565
|
waitForPort(port: number, opts?: {
|
|
1550
1566
|
timeoutMs?: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1545,6 +1545,22 @@ declare class Container {
|
|
|
1545
1545
|
headers?: Record<string, string>;
|
|
1546
1546
|
body?: string | Uint8Array;
|
|
1547
1547
|
}): Promise<HttpResponse>;
|
|
1548
|
+
/**
|
|
1549
|
+
* Deliver a request whose body is bytes, without letting them become text.
|
|
1550
|
+
*
|
|
1551
|
+
* Nodepod's public `request()` runs the body through `toString("utf8")` on
|
|
1552
|
+
* its way in, so anything above `0x7f` is replaced: a five-byte payload
|
|
1553
|
+
* containing `0x89` and `0xff` arrives as nine. That silently destroys every
|
|
1554
|
+
* upload — an image or a video reaches the server the wrong size and no
|
|
1555
|
+
* longer decodes, with no error raised anywhere.
|
|
1556
|
+
*
|
|
1557
|
+
* Its own dispatcher one layer down does preserve bytes, so a binary body
|
|
1558
|
+
* goes straight there. This reaches past the published surface deliberately,
|
|
1559
|
+
* so it is written to fail soft: any shape it does not recognise returns
|
|
1560
|
+
* `null` and the caller falls back to the ordinary path, which is exactly
|
|
1561
|
+
* the behaviour that existed before. Text bodies never come through here.
|
|
1562
|
+
*/
|
|
1563
|
+
private dispatchBinary;
|
|
1548
1564
|
/** Wait until something inside the container answers on `port`. */
|
|
1549
1565
|
waitForPort(port: number, opts?: {
|
|
1550
1566
|
timeoutMs?: number;
|
package/dist/index.js
CHANGED
|
@@ -23976,14 +23976,17 @@ var Container = class _Container {
|
|
|
23976
23976
|
/** Send an HTTP request to a server running inside the container. */
|
|
23977
23977
|
async request(port, init = {}) {
|
|
23978
23978
|
this.assertActive();
|
|
23979
|
-
const res = await this.pod.request(port, {
|
|
23979
|
+
const res = await this.dispatchBinary(port, init) ?? await this.pod.request(port, {
|
|
23980
23980
|
method: init.method ?? "GET",
|
|
23981
23981
|
path: init.path ?? "/",
|
|
23982
23982
|
headers: init.headers ?? {},
|
|
23983
23983
|
body: init.body ?? null
|
|
23984
23984
|
});
|
|
23985
23985
|
const bodyRaw = res.body;
|
|
23986
|
-
const bytes = bodyRaw instanceof Uint8Array ? bodyRaw :
|
|
23986
|
+
const bytes = bodyRaw instanceof Uint8Array ? bodyRaw : (
|
|
23987
|
+
// The binary dispatcher answers with an ArrayBuffer.
|
|
23988
|
+
bodyRaw instanceof ArrayBuffer ? new Uint8Array(bodyRaw) : typeof bodyRaw === "string" ? new TextEncoder().encode(bodyRaw) : new Uint8Array(0)
|
|
23989
|
+
);
|
|
23987
23990
|
const body = typeof bodyRaw === "string" ? bodyRaw : new TextDecoder().decode(bytes);
|
|
23988
23991
|
return {
|
|
23989
23992
|
status: res.statusCode ?? 200,
|
|
@@ -23996,6 +23999,40 @@ var Container = class _Container {
|
|
|
23996
23999
|
}
|
|
23997
24000
|
};
|
|
23998
24001
|
}
|
|
24002
|
+
/**
|
|
24003
|
+
* Deliver a request whose body is bytes, without letting them become text.
|
|
24004
|
+
*
|
|
24005
|
+
* Nodepod's public `request()` runs the body through `toString("utf8")` on
|
|
24006
|
+
* its way in, so anything above `0x7f` is replaced: a five-byte payload
|
|
24007
|
+
* containing `0x89` and `0xff` arrives as nine. That silently destroys every
|
|
24008
|
+
* upload — an image or a video reaches the server the wrong size and no
|
|
24009
|
+
* longer decodes, with no error raised anywhere.
|
|
24010
|
+
*
|
|
24011
|
+
* Its own dispatcher one layer down does preserve bytes, so a binary body
|
|
24012
|
+
* goes straight there. This reaches past the published surface deliberately,
|
|
24013
|
+
* so it is written to fail soft: any shape it does not recognise returns
|
|
24014
|
+
* `null` and the caller falls back to the ordinary path, which is exactly
|
|
24015
|
+
* the behaviour that existed before. Text bodies never come through here.
|
|
24016
|
+
*/
|
|
24017
|
+
async dispatchBinary(port, init) {
|
|
24018
|
+
if (!(init.body instanceof Uint8Array)) return null;
|
|
24019
|
+
const manager = this.pod._processManager;
|
|
24020
|
+
const dispatch = manager?.dispatchHttpRequest;
|
|
24021
|
+
if (typeof dispatch !== "function") return null;
|
|
24022
|
+
try {
|
|
24023
|
+
const response = await dispatch.call(
|
|
24024
|
+
manager,
|
|
24025
|
+
port,
|
|
24026
|
+
init.method ?? "GET",
|
|
24027
|
+
init.path ?? "/",
|
|
24028
|
+
init.headers ?? {},
|
|
24029
|
+
init.body
|
|
24030
|
+
);
|
|
24031
|
+
return response ?? null;
|
|
24032
|
+
} catch {
|
|
24033
|
+
return null;
|
|
24034
|
+
}
|
|
24035
|
+
}
|
|
23999
24036
|
/** Wait until something inside the container answers on `port`. */
|
|
24000
24037
|
waitForPort(port, opts = {}) {
|
|
24001
24038
|
return this.net.waitForPort(port, opts);
|