Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/foreground-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,17 @@ async function instantiateModule(
// haven't overridden the default CallContext implementation, we provide an HttpContext
// on-demand.
//
// Unfortuantely this duplicates a little bit of logic-- in particular, we have to bind
// Unfortunately this duplicates a little bit of logic-- in particular, we have to bind
// CallContext to each of the HttpContext contributions (See "REBIND" below.)
//
// Notably, if we're calling this from a background thread, skip all of the patching:
// we want to dispatch to the main thread.
if (
module === EXTISM_ENV &&
name === 'http_request' &&
promising &&
imports[module][name] === context[ENV].http_request
imports[module][name] === context[ENV].http_request &&
!opts.executingInWorker
) {
const httpContext = new HttpContext(opts.fetch, opts.allowedHosts, opts.memory, opts.allowHttpResponseHeaders);

Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export interface InternalConfig extends Required<NativeManifestOptions> {
sharedArrayBufferSize: number;
allowHttpResponseHeaders: boolean;
nodeWorkerArgs: NodeWorkerArgs;
executingInWorker: boolean;
}

export interface InternalWasi {
Expand Down
1 change: 1 addition & 0 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export async function createPlugin(
}

const ic: InternalConfig = {
executingInWorker: false,
allowedHosts: opts.allowedHosts as [],
allowedPaths: opts.allowedPaths,
functions: opts.functions,
Expand Down
2 changes: 1 addition & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class Reactor {

// TODO: replace our internal fetch and logger
this.plugin = await _createForegroundPlugin(
{ ...opts, functions, fetch, logger } as InternalConfig,
{ ...opts, functions, fetch, logger, executingInWorker: true } as InternalConfig,
ev.names,
modules,
this.context,
Expand Down