Skip to content
Open
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
1 change: 1 addition & 0 deletions docs/Proposals.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You can learn more about contributing new proposals (and other ways to contribut
| Proposal | Champion | Versions |
| -------------------------------------------------- | --------------------------------------------------------------------- | -------- |
| [Clocks: Timezone][wasi-clocks] | Dan Gohman, Colin Murphy | |
| [HTTP: Filter][wasi-http] | Pat Hickey, Lann Martin, John VanEnk | |
| [HTTP: Informational Outbound Response][wasi-http] | Pat Hickey, Lann Martin, John VanEnk | |
| [I2C][wasi-i2c] | Friedrich Vandenberghe, Merlijn Sebrechts, Maximilian Seidler | |
| [Key-value Store][wasi-kv-store] | Jiaxiao Zhou, Dan Chiarlone | |
Expand Down
10 changes: 10 additions & 0 deletions proposals/http/wit/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -470,4 +470,14 @@ interface types {
/// acquired from it previously will remain valid.
consume-body: static func(this: response, res: future<result<_, error-code>>) -> tuple<stream<u8>, future<result<option<trailers>, error-code>>>;
}

/// The action to take after inspecting the incoming request.
@unstable(feature = http-filter)
variant filter-action {
/// Forward the (possibly modified) request to origin.
forward(request),

/// Short-circuit with a response (skip origin).
respond(response),
}
}
48 changes: 48 additions & 0 deletions proposals/http/wit/worlds.wit
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,54 @@ world middleware {
import handler;
}

/// Memory-efficient middleware intended for resource-constrained environments.
///
/// Separating the request and response phases can let hosts reclaim a filter's
/// memory while the next stage processes a request, allowing more concurrent
/// requests within the same memory budget.
@unstable(feature = http-filter)
world filter {
/// HTTP services have access to time and randomness.
include wasi:clocks/imports@0.3.2;
include wasi:random/imports@0.3.2;

/// Services have standard output and error streams which are expected to
/// terminate in a developer-facing console provided by the host.
import wasi:cli/stdout@0.3.2;
import wasi:cli/stderr@0.3.2;
import wasi:cli/stdin@0.3.2;

/// This is the default `client` to use when user code simply wants to make an
/// HTTP request (e.g., via `fetch()`).
import client;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edge Actions currently does not support guest-initiated outbound HTTP. Is client intended to be optional once Component Model optional imports land? For the initial version, can we explicitly document that hosts may deny all client.send calls with HTTP-request-denied if they don't support outbound requests?


export filter-handler;
}

/// Filtering handler interface for HTTP middleware.
///
/// Components export this to process requests and responses in a linear
/// (non-blocking, two-phase) fashion.
///
/// For a given HTTP request, hosts may invoke `handle-request` and
/// `handle-response` on different component instances. Filters must not rely
/// on instance-local state being preserved between the two phases.
@unstable(feature = http-filter)
interface filter-handler {
@unstable(feature = http-filter)
use types.{request, response, error-code, filter-action};

/// Called during the request phase. Receives the client request and
/// decides whether to proceed to origin or respond immediately.
@unstable(feature = http-filter)
handle-request: async func(req: request) -> result<filter-action, error-code>;

/// Called during the response phase. Receives the origin response and
/// returns a (possibly modified) response to send to the client.
@unstable(feature = http-filter)
handle-response: async func(resp: response) -> result<response, error-code>;
}

/// This interface defines a handler of HTTP Requests.
///
/// In a `wasi:http/service` this interface is exported to respond to an
Expand Down
Loading