@@ -230,79 +230,35 @@ interface types {
230
230
/// Trailers is an alias for Fields.
231
231
type trailers = fields ;
232
232
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
-
285
233
/// Represents an HTTP Request.
286
234
resource request {
287
235
288
236
/// Construct a new `request` with a default `method` of `GET` , and
289
237
/// `none` values for `path-with-query` , `scheme` , and `authority` .
290
238
///
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.
295
248
///
296
249
/// 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`
298
251
/// and `authority` , or `headers` which are not permitted to be sent.
299
252
/// It is the obligation of the `handler.handle` implementation
300
253
/// 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 (
302
257
headers : headers ,
303
- body : body ,
258
+ contents : stream <u8 >,
259
+ trailers : future <result <option <trailers >, error-code >>,
304
260
options : option <request-options >
305
- );
261
+ ) -> tuple < request , future < result < _ , error-code >>> ;
306
262
307
263
/// Get the Method for the Request.
308
264
method : func () -> method ;
@@ -352,15 +308,26 @@ interface types {
352
308
/// `delete` operations will fail with `header-error.immutable` .
353
309
headers : func () -> headers ;
354
310
355
- /// Get the body associated with the Request, if any .
311
+ /// Get body of the Request.
356
312
///
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.
360
317
///
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 >>>>;
364
331
}
365
332
366
333
/// Parameters for making an HTTP Request. Each of these parameters is
@@ -409,16 +376,23 @@ interface types {
409
376
/// Represents an HTTP Response.
410
377
resource response {
411
378
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
414
381
/// `set-status-code` method.
415
382
///
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 (
419
392
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 >>>;
422
396
423
397
/// Get the HTTP Status Code for the Response.
424
398
status-code : func () -> status-code ;
@@ -427,20 +401,31 @@ interface types {
427
401
/// given is not a valid http status code.
428
402
set-status-code : func (status-code : status-code ) -> result ;
429
403
430
- /// Get the headers associated with the Request .
404
+ /// Get the headers associated with the Response .
431
405
///
432
406
/// The returned `headers` resource is immutable: `set` , `append` , and
433
407
/// `delete` operations will fail with `header-error.immutable` .
434
408
headers : func () -> headers ;
435
409
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.
437
416
///
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` .
441
421
///
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 >>>>;
445
430
}
446
431
}
0 commit comments