Skip to content

Commit 865daa5

Browse files
committed
p3: remove body resource
Signed-off-by: Roman Volosatovs <[email protected]>
1 parent f927cf4 commit 865daa5

File tree

1 file changed

+67
-82
lines changed

1 file changed

+67
-82
lines changed

wit-0.3.0-draft/types.wit

Lines changed: 67 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -230,79 +230,35 @@ interface types {
230230
/// Trailers is an alias for Fields.
231231
type trailers = fields;
232232

233-
/// Represents an HTTP Request or Response's Body.
234-
///
235-
/// A body has both its contents - a stream of bytes - and a (possibly empty)
236-
/// set of trailers, indicating that the full contents of the body have been
237-
/// received. This resource represents the contents as a `stream<u8>` and the
238-
/// delivery of trailers as a `trailers`, and ensures that the user of this
239-
/// interface may only be consuming either the body contents or waiting on
240-
/// trailers at any given time.
241-
resource body {
242-
243-
/// Construct a new `body` with the specified stream and `finish` future.
244-
///
245-
/// The `finish` future must resolve to a result once `stream` has finished.
246-
///
247-
/// This function returns a future, which will resolve to an error code if
248-
/// transmitting of the request or response this body is a part of fails.
249-
///
250-
/// The returned future resolves to success once request or response this
251-
/// body is a part of is fully transmitted.
252-
new: static func(
253-
%stream: stream<u8>,
254-
finish: future<result<option<trailers>, error-code>>,
255-
) -> tuple<body, future<result<_, error-code>>>;
256-
257-
/// Returns the contents of the body, as a stream of bytes.
258-
///
259-
/// This method returns a stream and a future, which will resolve
260-
/// to an error code if receiving data from stream fails.
261-
/// The returned future resolves to success if data section of the
262-
/// body is fully consumed.
263-
///
264-
/// The handles returned by this method are considered to be child
265-
/// handles. Dropping the resource on which this method is called
266-
/// will close the handles with an error context, if they are still open.
267-
///
268-
/// This method may be called multiple times.
269-
/// This method will return an error if it is called while either:
270-
/// - a stream or future returned by a previous call to this method is still open
271-
/// - `finish` was called on another instance of this `body` resource
272-
/// Thus there will always be at most one readable stream open for a given body.
273-
/// Each subsequent stream picks up where the last stream left off,
274-
/// up until `finish` is called on any of the instances of this `body` resource
275-
%stream: func() -> result<tuple<stream<u8>, future<result<_, error-code>>>>;
276-
277-
/// Takes ownership of `body`, and returns an unresolved optional `trailers` result.
278-
///
279-
/// This function will return an error if it is called while either:
280-
/// - a stream or future returned by a previous call to `body.stream` is still open
281-
/// - `finish` was already called on another instance of this `body` resource
282-
finish: static func(this: body) -> result<future<result<option<trailers>, error-code>>>;
283-
}
284-
285233
/// Represents an HTTP Request.
286234
resource request {
287235

288236
/// Construct a new `request` with a default `method` of `GET`, and
289237
/// `none` values for `path-with-query`, `scheme`, and `authority`.
290238
///
291-
/// * `headers` is the HTTP Headers for the Response.
292-
/// * `body` is the contents of the body, possibly including trailers.
293-
/// * `options` is optional `request-options` to be used if the request is
294-
/// sent over a network connection.
239+
/// `headers` is the HTTP Headers for the Request.
240+
///
241+
/// `contents` is the body content stream. Once it is closed,
242+
/// `trailers` future must resolve to a result.
243+
/// If `trailers` resolves to an error, underlying connection
244+
/// will be closed immediately.
245+
///
246+
/// `options` is optional `request-options` resource to be used
247+
/// if the request is sent over a network connection.
295248
///
296249
/// It is possible to construct, or manipulate with the accessor functions
297-
/// below, an `request` with an invalid combination of `scheme`
250+
/// below, a `request` with an invalid combination of `scheme`
298251
/// and `authority`, or `headers` which are not permitted to be sent.
299252
/// It is the obligation of the `handler.handle` implementation
300253
/// to reject invalid constructions of `request`.
301-
constructor(
254+
///
255+
/// The returned future resolves to result of transmission of this request.
256+
new: static func(
302257
headers: headers,
303-
body: body,
258+
contents: stream<u8>,
259+
trailers: future<result<option<trailers>, error-code>>,
304260
options: option<request-options>
305-
);
261+
) -> tuple<request, future<result<_, error-code>>>;
306262

307263
/// Get the Method for the Request.
308264
method: func() -> method;
@@ -352,15 +308,26 @@ interface types {
352308
/// `delete` operations will fail with `header-error.immutable`.
353309
headers: func() -> headers;
354310

355-
/// Get the body associated with the Request, if any.
311+
/// Get body of the Request.
356312
///
357-
/// This body resource is a child: it must be dropped or consumed before
358-
/// the parent `request` is dropped, or its ownership is transferred
359-
/// to another component by e.g. `handler.handle`.
313+
/// Stream returned by this method represents the contents of the body.
314+
/// Once the stream is reported as closed, callers should await the returned future
315+
/// to determine whether the body was received successfully.
316+
/// The future will only resolve after the stream is reported as closed.
360317
///
361-
/// Once `body.finish` is called on a body returned by this method,
362-
/// all subsequent calls to this method will return `none`.
363-
body: func() -> option<body>;
318+
/// The stream and future returned by this method are children:
319+
/// they should be closed or consumed before the parent `response`
320+
/// is dropped, or its ownership is transferred to another component
321+
/// by e.g. `handler.handle`.
322+
///
323+
/// This method may be called multiple times.
324+
///
325+
/// This method will return `none` if it is called while either:
326+
/// - a stream or future returned by a previous call to this method is still open
327+
/// - a stream returned by a previous call to this method has reported itself as closed
328+
/// Thus there will always be at most one readable stream open for a given body.
329+
/// Each subsequent stream picks up where the last stream left off, up until it is finished.
330+
body: func() -> option<tuple<stream<u8>, future<result<option<trailers>, error-code>>>>;
364331
}
365332

366333
/// Parameters for making an HTTP Request. Each of these parameters is
@@ -409,16 +376,23 @@ interface types {
409376
/// Represents an HTTP Response.
410377
resource response {
411378

412-
/// Construct an `response`, with a default `status-code` of `200`. If a
413-
/// different `status-code` is needed, it must be set via the
379+
/// Construct a new `response`, with a default `status-code` of `200`.
380+
/// If a different `status-code` is needed, it must be set via the
414381
/// `set-status-code` method.
415382
///
416-
/// * `headers` is the HTTP Headers for the Response.
417-
/// * `body` is the contents of the body, possibly including trailers.
418-
constructor(
383+
/// `headers` is the HTTP Headers for the Response.
384+
///
385+
/// `contents` is the body content stream. Once it is closed,
386+
/// `trailers` future must resolve to a result.
387+
/// If `trailers` resolves to an error, underlying connection
388+
/// will be closed immediately.
389+
///
390+
/// The returned future resolves to result of transmission of this response.
391+
new: static func(
419392
headers: headers,
420-
body: body,
421-
);
393+
contents: stream<u8>,
394+
trailers: future<result<option<trailers>, error-code>>,
395+
) -> tuple<response, future<result<_, error-code>>>;
422396

423397
/// Get the HTTP Status Code for the Response.
424398
status-code: func() -> status-code;
@@ -427,20 +401,31 @@ interface types {
427401
/// given is not a valid http status code.
428402
set-status-code: func(status-code: status-code) -> result;
429403

430-
/// Get the headers associated with the Request.
404+
/// Get the headers associated with the Response.
431405
///
432406
/// The returned `headers` resource is immutable: `set`, `append`, and
433407
/// `delete` operations will fail with `header-error.immutable`.
434408
headers: func() -> headers;
435409

436-
/// Get the body associated with the Response, if any.
410+
/// Get body of the Response.
411+
///
412+
/// Stream returned by this method represents the contents of the body.
413+
/// Once the stream is reported as closed, callers should await the returned future
414+
/// to determine whether the body was received successfully.
415+
/// The future will only resolve after the stream is reported as closed.
437416
///
438-
/// This body resource is a child: it should be dropped or consumed before
439-
/// the parent `response` is dropped, or its ownership is transferred
440-
/// to another component by e.g. `handler.handle`.
417+
/// The stream and future returned by this method are children:
418+
/// they should be closed or consumed before the parent `response`
419+
/// is dropped, or its ownership is transferred to another component
420+
/// by e.g. `handler.handle`.
441421
///
442-
/// Once `body.finish` is called on a body returned by this method,
443-
/// all subsequent calls to this method will return `none`.
444-
body: func() -> option<body>;
422+
/// This method may be called multiple times.
423+
///
424+
/// This method will return `none` if it is called while either:
425+
/// - a stream or future returned by a previous call to this method is still open
426+
/// - a stream returned by a previous call to this method has reported itself as closed
427+
/// Thus there will always be at most one readable stream open for a given body.
428+
/// Each subsequent stream picks up where the last stream left off, up until it is finished.
429+
body: func() -> option<tuple<stream<u8>, future<result<option<trailers>, error-code>>>>;
445430
}
446431
}

0 commit comments

Comments
 (0)