Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.

Commit d8cca5c

Browse files
feat: allow independent retrieval of trailers (#154)
This commit changes wasi:http/types#body.finish to forward the optionally present trailers, rather than retrieve them with the possibility of generating an error along the way. With this change, callers of `body.finish` will have to retreive trailers on their own, which *may* produce an efficiency gain in the case where trailers are present but not needed, and avoiding work of checking for trailers in the first place. Signed-off-by: Victor Adossi <[email protected]>
1 parent 19b48d5 commit d8cca5c

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

wit-0.3.0-draft/types.wit

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,27 @@ interface types {
240240
/// trailers at any given time.
241241
resource body {
242242

243+
/// Construct a new `body` with the specified stream.
244+
///
245+
/// This function returns a future, which will resolve
246+
/// to an error code if transmitting stream data fails.
247+
///
248+
/// The returned future resolves to success once body stream
249+
/// is fully transmitted.
250+
new: static func(
251+
%stream: stream<u8>,
252+
) -> tuple<body, future<result<_, error-code>>>;
253+
243254
/// Construct a new `body` with the specified stream and trailers.
255+
///
244256
/// This function returns a future, which will resolve
245257
/// to an error code if transmitting stream data or trailers fails.
258+
///
246259
/// The returned future resolves to success once body stream and trailers
247260
/// are fully transmitted.
248-
new: static func(
261+
new-with-trailers: static func(
249262
%stream: stream<u8>,
250-
trailers: option<future<trailers>>
263+
trailers: future<trailers>
251264
) -> tuple<body, future<result<_, error-code>>>;
252265

253266
/// Returns the contents of the body, as a stream of bytes.
@@ -260,9 +273,10 @@ interface types {
260273
/// The returned future resolves to success if body is closed.
261274
%stream: func() -> result<tuple<stream<u8>>, future<result<_, error-code>>>;
262275

263-
/// Takes ownership of `body`, and returns a `trailers`. This function will
264-
/// trap if a `stream` child is still alive.
265-
finish: static func(this: body) -> result<option<trailers>, error-code>;
276+
/// Takes ownership of `body`, and returns an unresolved optional `trailers`.
277+
///
278+
/// This function will trap if a `stream` child is still alive.
279+
finish: static func(this: body) -> future<option<trailers>>;
266280
}
267281

268282
/// Represents an HTTP Request.

0 commit comments

Comments
 (0)