Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] first draft of wasi:http@0.3.0 #101

Closed
wants to merge 5 commits into from
Closed
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
52 changes: 13 additions & 39 deletions wit/handler.wit
Original file line number Diff line number Diff line change
@@ -1,43 +1,17 @@
/// This interface defines a handler of incoming HTTP Requests. It should
/// be exported by components which can respond to HTTP Requests.
interface incoming-handler {
use types.{incoming-request, response-outparam};
/// This interface defines a handler of HTTP Requests. It may be imported by
/// components which wish to send HTTP Requests and also exported by components
/// which can respond to HTTP Requests. In addition, it may be used to pass
/// a request from one component to another without any use of a network.
interface handler {
use types.{request, response, error-code};

/// This function is invoked with an incoming HTTP Request, and a resource
/// `response-outparam` which provides the capability to reply with an HTTP
/// Response. The response is sent by calling the `response-outparam.set`
/// method, which allows execution to continue after the response has been
/// sent. This enables both streaming to the response body, and performing other
/// work.
/// When exported, this function may be called with either an incoming
/// request read from the network or a request synthesized or forwarded by
/// another component.
///
/// The implementor of this function must write a response to the
/// `response-outparam` before returning, or else the caller will respond
/// with an error on its behalf.
/// When imported, this function may be used to either send an outgoing
/// request over the network or pass it to another component.
handle: func(
request: incoming-request,
response-out: response-outparam
);
}

/// This interface defines a handler of outgoing HTTP Requests. It should be
/// imported by components which wish to make HTTP Requests.
interface outgoing-handler {
use types.{
outgoing-request, request-options, future-incoming-response, error-code
};

/// This function is invoked with an outgoing HTTP Request, and it returns
/// a resource `future-incoming-response` which represents an HTTP Response
/// which may arrive in the future.
///
/// The `options` argument accepts optional parameters for the HTTP
/// protocol's transport layer.
///
/// This function may return an error if the `outgoing-request` is invalid
/// or not allowed to be made. Otherwise, protocol errors are reported
/// through the `future-incoming-response`.
handle: func(
request: outgoing-request,
options: option<request-options>
) -> result<future-incoming-response, error-code>;
request: request,
) -> result<response, error-code>;
}
12 changes: 9 additions & 3 deletions wit/proxy.wit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi:http@0.2.0;
package wasi:http@0.3.0-draft-2024-02-29;

/// The `wasi:http/imports` world imports all the APIs for HTTP proxies.
/// It is intended to be `include`d in other worlds.
Expand All @@ -20,7 +20,10 @@ world imports {

/// This is the default handler to use when user code simply wants to make an
/// HTTP request (e.g., via `fetch()`).
import outgoing-handler;
///
/// This may also be used to pass synthesized or forwarded requests to another
/// component.
import handler;
}

/// The `wasi:http/proxy` world captures a widely-implementable intersection of
Expand All @@ -34,5 +37,8 @@ world proxy {
/// `handle` function of this exported interface. A host may arbitrarily reuse
/// or not reuse component instance when delivering incoming HTTP requests and
/// thus a component must be able to handle 0..N calls to `handle`.
export incoming-handler;
///
/// This may also be used to receive synthesized or forwarded requests from
/// another component.
export handler;
}
Loading
Loading