@aresdefencelabs/wasm-http-runtime 0.0.6 → 0.0.8
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.js +36 -26
- package/package.json +1 -1
package/dist/abi.js
CHANGED
|
@@ -104,33 +104,43 @@ export function createAresAbiImports(state) {
|
|
|
104
104
|
async abi_http_fetch_blocking(requestJsonCstrPtr) {
|
|
105
105
|
const instance = getInstanceOrThrow(state);
|
|
106
106
|
const memory = getMemoryOrThrow(instance);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
107
|
+
try {
|
|
108
|
+
const requestJson = readCString(memory, requestJsonCstrPtr);
|
|
109
|
+
const outbound = JSON.parse(requestJson);
|
|
110
|
+
if (state.options.debug) {
|
|
111
|
+
console.log("[AresWasm] abi_http_fetch_blocking outbound =", outbound);
|
|
112
|
+
}
|
|
113
|
+
const response = await fetch(outbound.url, {
|
|
114
|
+
method: outbound.method ?? "GET",
|
|
115
|
+
headers: outbound.headers,
|
|
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}`);
|
|
123
|
+
}
|
|
124
|
+
const headers = normalizeHeaders(response.headers);
|
|
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;
|
|
118
143
|
}
|
|
119
|
-
const headers = normalizeHeaders(response.headers);
|
|
120
|
-
const estimatedBytes = estimateResponseBytes({
|
|
121
|
-
bodyText,
|
|
122
|
-
headers
|
|
123
|
-
});
|
|
124
|
-
assertBridgeCapacity(state, estimatedBytes);
|
|
125
|
-
const responseId = state.nextHttpResponseId++;
|
|
126
|
-
state.httpResponses.set(responseId, {
|
|
127
|
-
status: response.status,
|
|
128
|
-
bodyText,
|
|
129
|
-
headers,
|
|
130
|
-
createdAtMs: Date.now(),
|
|
131
|
-
estimatedBytes
|
|
132
|
-
});
|
|
133
|
-
return responseId >>> 0;
|
|
134
144
|
},
|
|
135
145
|
abi_http_response_get_status(responseId) {
|
|
136
146
|
return getResponseByIdOrEmpty(state, responseId).status >>> 0;
|
package/package.json
CHANGED