@aresdefencelabs/wasm-http-runtime 0.0.6 → 0.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/dist/abi.js +35 -26
- package/package.json +1 -1
package/dist/abi.js
CHANGED
|
@@ -104,33 +104,42 @@ 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
|
+
const bodyText = await response.text();
|
|
119
|
+
const bodyBytes = utf8ByteLength(bodyText);
|
|
120
|
+
if (bodyBytes > state.options.maxResponseBodyBytes) {
|
|
121
|
+
throw new Error(`HTTP response body too large: ${bodyBytes} bytes exceeds maxResponseBodyBytes=${state.options.maxResponseBodyBytes}`);
|
|
122
|
+
}
|
|
123
|
+
const headers = normalizeHeaders(response.headers);
|
|
124
|
+
const estimatedBytes = estimateResponseBytes({
|
|
125
|
+
bodyText,
|
|
126
|
+
headers
|
|
127
|
+
});
|
|
128
|
+
assertBridgeCapacity(state, estimatedBytes);
|
|
129
|
+
const responseId = state.nextHttpResponseId++;
|
|
130
|
+
state.httpResponses.set(responseId, {
|
|
131
|
+
status: response.status,
|
|
132
|
+
bodyText,
|
|
133
|
+
headers,
|
|
134
|
+
createdAtMs: Date.now(),
|
|
135
|
+
estimatedBytes
|
|
136
|
+
});
|
|
137
|
+
return responseId >>> 0;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error("[AresWasm] abi_http_fetch_blocking failed:", error);
|
|
141
|
+
return 0;
|
|
118
142
|
}
|
|
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
143
|
},
|
|
135
144
|
abi_http_response_get_status(responseId) {
|
|
136
145
|
return getResponseByIdOrEmpty(state, responseId).status >>> 0;
|
package/package.json
CHANGED