http_request is not enabled
Closed this issue · 2 comments
7aGiven commented
Enviroment
platform: Ubuntu 22.04.3 / Windows 10
CPU: x64
Runtime: Nodejs 20
Issue
If run with js-sdk and use extism_http_request API, showhttp_request is not enabled
message,
If run with extism cli, run success.
js code
const createPlugin = require("@extism/extism")
async function main() {
const plugin = await createPlugin("./a.wasm",{
useWasi: true,
withAllowedHosts: ['www.google.com'],
allowedHosts: ['www.google.com']
})
const ret = await plugin.call("hello")
console.log(ret)
}
main()
c code
#define EXTISM_IMPLEMENTATION
#include "extism-pdk.h"
int32_t EXTISM_EXPORTED_FUNCTION(hello) {
char req_str[] = "{\"method\":\"GET\",\"url\":\"http://www.google.com\"}";
ExtismHandle req = extism_alloc_buf_from_sz(req_str);
ExtismHandle res = extism_http_request(req, 0);
extism_output_set_from_handle(res, 0, extism_length(res));
return 0;
}
build and run
/opt/wasi-sdk/bin/clang -o a.wasm --target=wasm32-unknown-unknown -nostdlib -Wl,--no-entry a.c
node c.js
run result
chrisdickinson commented
Ah – since HTTP requests are asynchronous, http_request
is only enabled when runInWorker
is enabled. You might try passing that during your initial setup:
const createPlugin = require("@extism/extism")
async function main() {
const plugin = await createPlugin("./a.wasm",{
useWasi: true,
withAllowedHosts: ['www.google.com'],
allowedHosts: ['www.google.com'],
runInWorker: true
})
const ret = await plugin.call("hello")
console.log(ret)
}
main()
7aGiven commented
Thank you very much. And you fix js-sdk referencewithAllowedHost
.