@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.
Files changed (2) hide show
  1. package/dist/abi.js +35 -26
  2. 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
- const requestJson = readCString(memory, requestJsonCstrPtr);
108
- const outbound = JSON.parse(requestJson);
109
- const response = await fetch(outbound.url, {
110
- method: outbound.method ?? "GET",
111
- headers: outbound.headers,
112
- body: outbound.body ?? undefined
113
- });
114
- const bodyText = await response.text();
115
- const bodyBytes = utf8ByteLength(bodyText);
116
- if (bodyBytes > state.options.maxResponseBodyBytes) {
117
- throw new Error(`HTTP response body too large: ${bodyBytes} bytes exceeds maxResponseBodyBytes=${state.options.maxResponseBodyBytes}`);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aresdefencelabs/wasm-http-runtime",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
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,