diff --git a/wit/handler.wit b/wit/handler.wit index cc79ece..3140d8c 100644 --- a/wit/handler.wit +++ b/wit/handler.wit @@ -7,7 +7,7 @@ // that takes a `request` parameter and returns a `response` result. // interface incoming-handler { - use types.{incoming-request, response-outparam} + use types.{incoming-request, response-outparam}; // The `handle` function takes an outparam instead of returning its response // so that the component may stream its response while streaming any other @@ -20,7 +20,7 @@ interface incoming-handler { handle: func( request: incoming-request, response-out: response-outparam - ) + ); } // The `wasi:http/outgoing-handler` interface is meant to be imported by @@ -31,7 +31,7 @@ interface incoming-handler { // that takes a `request` parameter and returns a `response` result. // interface outgoing-handler { - use types.{outgoing-request, request-options, future-incoming-response, error} + use types.{outgoing-request, request-options, future-incoming-response, error}; // The parameter and result types of the `handle` function allow the caller // to concurrently stream the bodies of the outgoing request and the incoming @@ -41,5 +41,5 @@ interface outgoing-handler { handle: func( request: outgoing-request, options: option - ) -> result + ) -> result; } diff --git a/wit/proxy.wit b/wit/proxy.wit index 162ab32..8ee5892 100644 --- a/wit/proxy.wit +++ b/wit/proxy.wit @@ -1,4 +1,4 @@ -package wasi:http +package wasi:http; // The `wasi:http/proxy` world captures a widely-implementable intersection of // hosts that includes HTTP forward and reverse proxies. Components targeting @@ -6,29 +6,29 @@ package wasi:http // outgoing HTTP requests. world proxy { // HTTP proxies have access to time and randomness. - import wasi:clocks/wall-clock - import wasi:clocks/monotonic-clock - import wasi:clocks/timezone - import wasi:random/random + import wasi:clocks/wall-clock; + import wasi:clocks/monotonic-clock; + import wasi:clocks/timezone; + import wasi:random/random; // Proxies have standard output and error streams which are expected to // terminate in a developer-facing console provided by the host. - import wasi:cli/stdout - import wasi:cli/stderr + import wasi:cli/stdout; + import wasi:cli/stderr; // 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/stdin + import wasi:cli/stdin; // This is the default handler to use when user code simply wants to make an // HTTP request (e.g., via `fetch()`). - import outgoing-handler + import outgoing-handler; // 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`. - export incoming-handler + export incoming-handler; } diff --git a/wit/types.wit b/wit/types.wit index 9b6cd8e..c1e4ae1 100644 --- a/wit/types.wit +++ b/wit/types.wit @@ -2,8 +2,8 @@ // define the HTTP resource types and operations used by the component's // imported and exported interfaces. interface types { - use wasi:io/streams.{input-stream, output-stream} - use wasi:io/poll.{pollable} + use wasi:io/streams.{input-stream, output-stream}; + use wasi:io/poll.{pollable}; // This type corresponds to HTTP standard Methods. variant method { @@ -43,28 +43,28 @@ interface types { resource fields { // Multiple values for a header are multiple entries in the list with the // same key. - constructor(entries: list>>) + constructor(entries: list>>); // Values off wire are not necessarily well formed, so they are given by // list instead of string. - get: func(name: string) -> list> + get: func(name: string) -> list>; // Values off wire are not necessarily well formed, so they are given by // list instead of string. - set: func(name: string, value: list>) - delete: func(name: string) - append: func(name: string, value: list) + set: func(name: string, value: list>); + delete: func(name: string); + append: func(name: string, value: list); // Values off wire are not necessarily well formed, so they are given by // list instead of string. - entries: func() -> list>> + entries: func() -> list>>; // Deep copy of all contents in a fields. - clone: func() -> fields + clone: func() -> fields; } - type headers = fields - type trailers = fields + type headers = fields; + type trailers = fields; // The following block defines the `incoming-request` and `outgoing-request` // resource types that correspond to HTTP standard Requests. Soon, when @@ -75,19 +75,19 @@ interface types { // above). The `consume` and `write` methods may only be called once (and // return failure thereafter). resource incoming-request { - method: func() -> method + method: func() -> method; - path-with-query: func() -> option + path-with-query: func() -> option; - scheme: func() -> option + scheme: func() -> option; - authority: func() -> option + authority: func() -> option; - headers: func() -> headers + headers: func() -> headers; // Will return the incoming-body child at most once. If called more than // once, subsequent calls will return error. - consume: func() -> result + consume: func() -> result; } resource outgoing-request { @@ -97,11 +97,11 @@ interface types { scheme: option, authority: option, headers: borrow - ) + ); // Will return the outgoing-body child at most once. If called more than // once, subsequent calls will return error. - write: func() -> result + write: func() -> result; } // Additional optional parameters that can be set when making a request. @@ -127,11 +127,11 @@ interface types { // (the `wasi:http/handler` interface used for both incoming and outgoing can // simply return a `stream`). resource response-outparam { - set: static func(param: response-outparam, response: result) + set: static func(param: response-outparam, response: result); } // This type corresponds to the HTTP standard Status Code. - type status-code = u16 + type status-code = u16; // The following block defines the `incoming-response` and `outgoing-response` // resource types that correspond to HTTP standard Responses. Soon, when @@ -141,14 +141,14 @@ interface types { // type (that uses the single `stream` type mentioned above). The `consume` and // `write` methods may only be called once (and return failure thereafter). resource incoming-response { - status: func() -> status-code + status: func() -> status-code; - headers: func() -> headers + headers: func() -> headers; // May be called at most once. returns error if called additional times. // TODO: make incoming-request-consume work the same way, giving a child // incoming-body. - consume: func() -> result + consume: func() -> result; } resource incoming-body { @@ -156,40 +156,40 @@ interface types { // incoming-body is dropped (or consumed by call to // incoming-body-finish) before the input-stream is dropped. // May be called at most once. returns error if called additional times. - %stream: func() -> result + %stream: func() -> result; // takes ownership of incoming-body. this will trap if the // incoming-body-stream child is still alive! - finish: static func(this: incoming-body) -> future-trailers + finish: static func(this: incoming-body) -> future-trailers; } resource future-trailers { /// Pollable that resolves when the body has been fully read, and the trailers /// are ready to be consumed. - subscribe: func() -> pollable + subscribe: func() -> pollable; /// Retrieve reference to trailers, if they are ready. - get: func() -> option> + get: func() -> option>; } resource outgoing-response { - constructor(status-code: status-code, headers: borrow) + constructor(status-code: status-code, headers: borrow); /// Will give the child outgoing-response at most once. subsequent calls will /// return an error. - write: func() -> result + write: func() -> result; } resource outgoing-body { /// Will give the child output-stream at most once. subsequent calls will /// return an error. - write: func() -> result + write: func() -> result; /// Finalize an outgoing body, optionally providing trailers. This must be /// called to signal that the response is complete. If the `outgoing-body` is /// dropped without calling `outgoing-body-finalize`, the implementation /// should treat the body as corrupted. - finish: static func(this: outgoing-body, trailers: option) + finish: static func(this: outgoing-body, trailers: option); } /// The following block defines a special resource type used by the @@ -206,8 +206,8 @@ interface types { /// will return an error here. /// inner result indicates whether the incoming-response was available, or an /// error occured. - get: func() -> option>> + get: func() -> option>>; - subscribe: func() -> pollable + subscribe: func() -> pollable; } }