Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
64 changes: 35 additions & 29 deletions wit-0.3.0-draft/types.wit
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,30 @@ interface types {

/// Returns the contents of the body, as a stream of bytes.
///
/// This function may be called multiple times as long as any `stream`s
/// returned by previous calls have been dropped first.
///
/// On success, this function returns a stream and a future, which will resolve
/// This method returns a stream and a future, which will resolve
/// to an error code if receiving data from stream fails.
/// The returned future resolves to success if body is closed.
/// The returned future resolves to success if data section of the
/// body is fully consumed.
///
/// The handles returned by this method are considered to be child
/// handles. Dropping the resource on which this method is called
/// will close the handles with an error context, if they are still open.
///
Comment thread
lukewagner marked this conversation as resolved.
Outdated
/// This method may be called multiple times.
/// This method will return an error if it is called while either:
/// - a stream or future returned by a previous call to this method is still open
/// - `finish` was called on another instance of this `body` resource
/// Thus there will always be at most one readable stream open for a given body.
/// Each subsequent stream picks up where the last stream left off,
/// up until `finish` is called on any of the instances of this `body` resource
%stream: func() -> result<tuple<stream<u8>, future<result<_, error-code>>>>;

/// Takes ownership of `body`, and returns an unresolved optional `trailers` result.
///
/// This function will trap if a `stream` child is still alive.
finish: static func(this: body) -> future<result<option<trailers>, error-code>>;
/// This function will return an error if it is called while either:
/// - a stream or future returned by a previous call to `body.stream` is still open
/// - `finish` was already called on another instance of this `body` resource
finish: static func(this: body) -> result<future<result<option<trailers>, error-code>>>;
}

/// Represents an HTTP Request.
Expand Down Expand Up @@ -348,22 +360,17 @@ interface types {
///
/// The returned `headers` resource is immutable: `set`, `append`, and
/// `delete` operations will fail with `header-error.immutable`.
///
/// This headers resource is a child: it must be dropped before the parent
/// `request` is dropped, or its ownership is transferred to another
/// component by e.g. `handler.handle`.
headers: func() -> headers;

/// Get the body associated with the Request, if any.
///
/// This body resource is a child: it must be dropped before the parent
/// `request` is dropped, or its ownership is transferred to another
/// component by e.g. `handler.handle`.
/// This body resource is a child: it must be dropped or consumed before
/// the parent `request` is dropped, or its ownership is transferred
/// to another component by e.g. `handler.handle`.
///
/// Once `body.finish` is called on a body returned by this method,
/// all subsequent calls to this method will return `none`.
body: func() -> option<body>;

/// Takes ownership of the `request` and returns the `headers`, `body`
/// and `request-options`, if any.
into-parts: static func(this: request) -> tuple<headers, option<body>, option<request-options>>;
}

/// Parameters for making an HTTP Request. Each of these parameters is
Expand Down Expand Up @@ -400,6 +407,10 @@ interface types {
/// body stream. An error return value indicates that this timeout is not
/// supported or that this handle is immutable.
set-between-bytes-timeout: func(duration: option<duration>) -> result<_, request-options-error>;

/// Make a deep copy of the `request-options`.
/// The resulting `request-options` is mutable.
clone: func() -> request-options;
}

/// This type corresponds to the HTTP standard Status Code.
Expand Down Expand Up @@ -431,21 +442,16 @@ interface types {
///
/// The returned `headers` resource is immutable: `set`, `append`, and
/// `delete` operations will fail with `header-error.immutable`.
///
/// This headers resource is a child: it must be dropped before the parent
/// `response` is dropped, or its ownership is transferred to another
/// component by e.g. `handler.handle`.
headers: func() -> headers;

/// Get the body associated with the Response, if any.
///
/// This body resource is a child: it must be dropped before the parent
/// `response` is dropped, or its ownership is transferred to another
/// component by e.g. `handler.handle`.
/// This body resource is a child: it should be dropped or consumed before
/// the parent `response` is dropped, or its ownership is transferred
/// to another component by e.g. `handler.handle`.
///
/// Once `body.finish` is called on a body returned by this method,
/// all subsequent calls to this method will return `none`.
body: func() -> option<body>;

/// Takes ownership of the `response` and returns the `headers` and `body`,
/// if any.
into-parts: static func(this: response) -> tuple<headers, option<body>>;
}
}