-
Notifications
You must be signed in to change notification settings - Fork 35
[0.3] Rework handlers and worlds #199
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
Merged
+82
−61
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package wasi:[email protected]; | ||
|
||
/// The `wasi:http/service` world captures a broad category of HTTP services | ||
/// including web applications, API servers, and proxies. It may be `include`d | ||
/// in more specific worlds such as `wasi:http/middleware`. | ||
world service { | ||
/// HTTP services have access to time and randomness. | ||
include wasi:clocks/[email protected]; | ||
import wasi:random/[email protected]; | ||
|
||
/// Services have standard output and error streams which are expected to | ||
/// terminate in a developer-facing console provided by the host. | ||
import wasi:cli/[email protected]; | ||
import wasi:cli/[email protected]; | ||
|
||
/// TODO: this is a temporary workaround until component tooling is able to | ||
/// gracefully handle the absence of stdin. Hosts must return an eof stream | ||
/// for this import, which is what wasi-libc + tooling will do automatically | ||
/// when this import is properly removed. | ||
import wasi:cli/[email protected]; | ||
|
||
/// This is the default `client` to use when user code simply wants to make an | ||
/// HTTP request (e.g., via `fetch()`). | ||
import client; | ||
|
||
/// The host delivers incoming HTTP requests to a component by calling the | ||
/// `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`. | ||
/// | ||
/// This may also be used to receive synthesized or forwarded requests from | ||
/// another component. | ||
export handler; | ||
} | ||
|
||
/// The `wasi:http/middleware` world captures HTTP services that forward HTTP | ||
/// Requests to another handler. | ||
/// | ||
/// Components may implement this world to allow them to participate in handler | ||
/// "chains" where a Request flows through handlers on its way to some terminal | ||
/// `service` and corresponding Responses flow in the opposite direction. | ||
world middleware { | ||
include service; | ||
import handler; | ||
} | ||
|
||
/// This interface defines a handler of HTTP Requests. | ||
/// | ||
/// In a `wasi:http/service` this interface is exported to respond to an | ||
/// incoming HTTP Request with a Response. | ||
/// | ||
/// In `wasi:http/middleware` this interface is both exported and imported as | ||
/// the "downstream" and "upstream" directions of the middleware chain. | ||
interface handler { | ||
use types.{request, response, error-code}; | ||
|
||
/// This function may be called with either an incoming request read from the | ||
/// network or a request synthesized or forwarded by another component. | ||
handle: async func( | ||
request: request, | ||
) -> result<response, error-code>; | ||
} | ||
|
||
/// This interface defines an HTTP client for sending "outgoing" requests. | ||
/// | ||
/// Most components are expected to import this interface to provide the | ||
/// capability to send HTTP requests to arbitrary destinations on a network. | ||
/// | ||
/// The type signature of `client.send` is the same as `handler.handle`. This | ||
/// duplication is currently necessary because some Component Model tooling | ||
/// (including WIT itself) is unable to represent a component importing two | ||
/// instances of the same interface. | ||
lann marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
interface client { | ||
use types.{request, response, error-code}; | ||
|
||
// This function may be used to either send an outgoing request over the | ||
// network or to forward it to another component. | ||
send: async func( | ||
request: request, | ||
) -> result<response, error-code>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.