From 218295dcdee648b2de3d872ecf569365e6e69d00 Mon Sep 17 00:00:00 2001 From: Victor Adossi Date: Wed, 19 Feb 2025 20:05:59 +0900 Subject: [PATCH] feat: allow independent retrieval of trailers 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 --- wit-0.3.0-draft/types.wit | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/wit-0.3.0-draft/types.wit b/wit-0.3.0-draft/types.wit index d720fbe..2e785a8 100644 --- a/wit-0.3.0-draft/types.wit +++ b/wit-0.3.0-draft/types.wit @@ -240,14 +240,27 @@ interface types { /// trailers at any given time. resource body { + /// Construct a new `body` with the specified stream. + /// + /// This function returns a future, which will resolve + /// to an error code if transmitting stream data fails. + /// + /// The returned future resolves to success once body stream + /// is fully transmitted. + new: static func( + %stream: stream, + ) -> tuple>>; + /// Construct a new `body` with the specified stream and trailers. + /// /// This function returns a future, which will resolve /// to an error code if transmitting stream data or trailers fails. + /// /// The returned future resolves to success once body stream and trailers /// are fully transmitted. - new: static func( + new-with-trailers: static func( %stream: stream, - trailers: option> + trailers: future ) -> tuple>>; /// Returns the contents of the body, as a stream of bytes. @@ -260,9 +273,10 @@ interface types { /// The returned future resolves to success if body is closed. %stream: func() -> result>, future>>; - /// Takes ownership of `body`, and returns a `trailers`. This function will - /// trap if a `stream` child is still alive. - finish: static func(this: body) -> result, error-code>; + /// Takes ownership of `body`, and returns an unresolved optional `trailers`. + /// + /// This function will trap if a `stream` child is still alive. + finish: static func(this: body) -> future>; } /// Represents an HTTP Request.