@aresdefencelabs/wasm-http-runtime 0.1.2 → 0.1.4
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/dist/abi.d.ts +1 -1
- package/dist/abi.js +44 -38
- package/emscripten/ares_abi_library.js +59 -0
- package/package.json +2 -2
package/dist/abi.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare function createAresAbiImports<Env>(state: RuntimeState<Env>): {
|
|
|
9
9
|
free_mem(ptr: number, size: number): void;
|
|
10
10
|
abi_log(messagePtr: number): void;
|
|
11
11
|
abi_http_get_user_agent_name(): number;
|
|
12
|
-
abi_http_fetch_blocking_async
|
|
12
|
+
abi_http_fetch_blocking_async(requestJsonCstrPtr: number): number;
|
|
13
13
|
abi_http_response_get_status(responseId: number): number;
|
|
14
14
|
abi_http_response_get_body_len(responseId: number): number;
|
|
15
15
|
abi_http_response_copy_body(responseId: number, outPtr: number, maxLen: number): number;
|
package/dist/abi.js
CHANGED
|
@@ -101,46 +101,52 @@ export function createAresAbiImports(state) {
|
|
|
101
101
|
const alloc = getAllocOrThrow(instance);
|
|
102
102
|
return writeCString(memory, alloc, userAgent);
|
|
103
103
|
},
|
|
104
|
-
abi_http_fetch_blocking_async
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
104
|
+
abi_http_fetch_blocking_async(requestJsonCstrPtr) {
|
|
105
|
+
const Asyncify = globalThis.Asyncify;
|
|
106
|
+
if (!Asyncify?.handleAsync) {
|
|
107
|
+
throw new Error("Asyncify.handleAsync is not available in this runtime");
|
|
108
|
+
}
|
|
109
|
+
return Asyncify.handleAsync(async () => {
|
|
110
|
+
const instance = getInstanceOrThrow(state);
|
|
111
|
+
const memory = getMemoryOrThrow(instance);
|
|
112
|
+
try {
|
|
113
|
+
const requestJson = readCString(memory, requestJsonCstrPtr);
|
|
114
|
+
const outbound = JSON.parse(requestJson);
|
|
115
|
+
if (state.options.debug) {
|
|
116
|
+
console.log("[AresWasm] abi_http_fetch_blocking outbound =", outbound);
|
|
117
|
+
}
|
|
118
|
+
const response = await fetch(outbound.url, {
|
|
119
|
+
method: outbound.method ?? "GET",
|
|
120
|
+
headers: outbound.headers,
|
|
121
|
+
body: outbound.body ?? undefined
|
|
122
|
+
});
|
|
123
|
+
console.log("[AresWasm] abi_http_fetch_blocking fetch completed, status =", response.status);
|
|
124
|
+
const bodyText = await response.text();
|
|
125
|
+
const bodyBytes = utf8ByteLength(bodyText);
|
|
126
|
+
if (bodyBytes > state.options.maxResponseBodyBytes) {
|
|
127
|
+
throw new Error(`HTTP response body too large: ${bodyBytes} bytes exceeds maxResponseBodyBytes=${state.options.maxResponseBodyBytes}`);
|
|
128
|
+
}
|
|
129
|
+
const headers = normalizeHeaders(response.headers);
|
|
130
|
+
const estimatedBytes = estimateResponseBytes({
|
|
131
|
+
bodyText,
|
|
132
|
+
headers
|
|
133
|
+
});
|
|
134
|
+
assertBridgeCapacity(state, estimatedBytes);
|
|
135
|
+
const responseId = state.nextHttpResponseId++;
|
|
136
|
+
state.httpResponses.set(responseId, {
|
|
137
|
+
status: response.status,
|
|
138
|
+
bodyText,
|
|
139
|
+
headers,
|
|
140
|
+
createdAtMs: Date.now(),
|
|
141
|
+
estimatedBytes
|
|
142
|
+
});
|
|
143
|
+
return responseId >>> 0;
|
|
112
144
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
body: outbound.body ?? undefined
|
|
117
|
-
});
|
|
118
|
-
console.log("[AresWasm] abi_http_fetch_blocking fetch completed, status =", response.status);
|
|
119
|
-
const bodyText = await response.text();
|
|
120
|
-
const bodyBytes = utf8ByteLength(bodyText);
|
|
121
|
-
if (bodyBytes > state.options.maxResponseBodyBytes) {
|
|
122
|
-
throw new Error(`HTTP response body too large: ${bodyBytes} bytes exceeds maxResponseBodyBytes=${state.options.maxResponseBodyBytes}`);
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error("[AresWasm] abi_http_fetch_blocking failed:", error);
|
|
147
|
+
return 0;
|
|
123
148
|
}
|
|
124
|
-
|
|
125
|
-
const estimatedBytes = estimateResponseBytes({
|
|
126
|
-
bodyText,
|
|
127
|
-
headers
|
|
128
|
-
});
|
|
129
|
-
assertBridgeCapacity(state, estimatedBytes);
|
|
130
|
-
const responseId = state.nextHttpResponseId++;
|
|
131
|
-
state.httpResponses.set(responseId, {
|
|
132
|
-
status: response.status,
|
|
133
|
-
bodyText,
|
|
134
|
-
headers,
|
|
135
|
-
createdAtMs: Date.now(),
|
|
136
|
-
estimatedBytes
|
|
137
|
-
});
|
|
138
|
-
return responseId >>> 0;
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
console.error("[AresWasm] abi_http_fetch_blocking failed:", error);
|
|
142
|
-
return 0;
|
|
143
|
-
}
|
|
149
|
+
});
|
|
144
150
|
},
|
|
145
151
|
abi_http_response_get_status(responseId) {
|
|
146
152
|
return getResponseByIdOrEmpty(state, responseId).status >>> 0;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
addToLibrary({
|
|
2
|
+
abi_log__deps: ['$UTF8ToString'],
|
|
3
|
+
abi_log: function (messagePtr) {
|
|
4
|
+
if (typeof Module.__aresAbiLog !== 'function') {
|
|
5
|
+
throw new Error('Module.__aresAbiLog is not set');
|
|
6
|
+
}
|
|
7
|
+
Module.__aresAbiLog(messagePtr);
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
abi_http_get_user_agent_name: function () {
|
|
11
|
+
if (typeof Module.__aresAbiHttpGetUserAgentName !== 'function') {
|
|
12
|
+
throw new Error('Module.__aresAbiHttpGetUserAgentName is not set');
|
|
13
|
+
}
|
|
14
|
+
return Module.__aresAbiHttpGetUserAgentName() >>> 0;
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
abi_http_response_get_status: function (responseId) {
|
|
18
|
+
if (typeof Module.__aresAbiHttpResponseGetStatus !== 'function') {
|
|
19
|
+
throw new Error('Module.__aresAbiHttpResponseGetStatus is not set');
|
|
20
|
+
}
|
|
21
|
+
return Module.__aresAbiHttpResponseGetStatus(responseId) >>> 0;
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
abi_http_response_get_body_len: function (responseId) {
|
|
25
|
+
if (typeof Module.__aresAbiHttpResponseGetBodyLen !== 'function') {
|
|
26
|
+
throw new Error('Module.__aresAbiHttpResponseGetBodyLen is not set');
|
|
27
|
+
}
|
|
28
|
+
return Module.__aresAbiHttpResponseGetBodyLen(responseId) >>> 0;
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
abi_http_response_copy_body: function (responseId, outPtr, maxLen) {
|
|
32
|
+
if (typeof Module.__aresAbiHttpResponseCopyBody !== 'function') {
|
|
33
|
+
throw new Error('Module.__aresAbiHttpResponseCopyBody is not set');
|
|
34
|
+
}
|
|
35
|
+
return Module.__aresAbiHttpResponseCopyBody(responseId, outPtr, maxLen) >>> 0;
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
abi_http_response_copy_header: function (responseId, keyPtr, outPtr, maxLen) {
|
|
39
|
+
if (typeof Module.__aresAbiHttpResponseCopyHeader !== 'function') {
|
|
40
|
+
throw new Error('Module.__aresAbiHttpResponseCopyHeader is not set');
|
|
41
|
+
}
|
|
42
|
+
return Module.__aresAbiHttpResponseCopyHeader(responseId, keyPtr, outPtr, maxLen) >>> 0;
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
abi_http_response_free: function (responseId) {
|
|
46
|
+
if (typeof Module.__aresAbiHttpResponseFree !== 'function') {
|
|
47
|
+
throw new Error('Module.__aresAbiHttpResponseFree is not set');
|
|
48
|
+
}
|
|
49
|
+
Module.__aresAbiHttpResponseFree(responseId);
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
abi_http_fetch_blocking_async__async: 'auto',
|
|
53
|
+
abi_http_fetch_blocking_async: async function (requestJsonCstrPtr) {
|
|
54
|
+
if (typeof Module.__aresAbiHttpFetchBlockingAsync !== 'function') {
|
|
55
|
+
throw new Error('Module.__aresAbiHttpFetchBlockingAsync is not set');
|
|
56
|
+
}
|
|
57
|
+
return (await Module.__aresAbiHttpFetchBlockingAsync(requestJsonCstrPtr)) >>> 0;
|
|
58
|
+
},
|
|
59
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aresdefencelabs/wasm-http-runtime",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Runtime adapter that connects C++ WebAssembly workers to the Cloudflare Workers runtime via an ABI bridge.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
},
|
|
37
37
|
"main": "./dist/index.js",
|
|
38
38
|
"types": "./dist/index.d.ts",
|
|
39
|
-
"files": ["dist"]
|
|
39
|
+
"files": ["dist", "emscripten"]
|
|
40
40
|
}
|