-
Notifications
You must be signed in to change notification settings - Fork 39
[v0.3] model bodies after stream<u8, trailers, error-code>, trap less
#162
Changes from 2 commits
aba4ece
1b2455f
128af94
55db2ff
70ad39c
eac8416
f927cf4
865daa5
c3517c6
ae89575
848eaf5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -265,17 +265,26 @@ 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 function 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. | ||||||||||||||||||||||||||||||||||||||||
| %stream: func() -> result<tuple<stream<u8>, future<result<_, error-code>>>>; | ||||||||||||||||||||||||||||||||||||||||
| /// The returned future resolves to success if data section of the | ||||||||||||||||||||||||||||||||||||||||
| /// body is fully consumed. | ||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// The handles returned by this function are considered to be child | ||||||||||||||||||||||||||||||||||||||||
| /// handles. Dropping the resource on which this function is called | ||||||||||||||||||||||||||||||||||||||||
| /// will close the handles with an error context, if they are still open. | ||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// This function may be called multiple times. | ||||||||||||||||||||||||||||||||||||||||
| /// If it is called while either a stream or future returned by a previous | ||||||||||||||||||||||||||||||||||||||||
| /// call to this function is still open, those handles will be closed | ||||||||||||||||||||||||||||||||||||||||
| /// with an error context. | ||||||||||||||||||||||||||||||||||||||||
| %stream: func() -> 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. | ||||||||||||||||||||||||||||||||||||||||
| /// Developers are encouraged to close any open handles returned by previous | ||||||||||||||||||||||||||||||||||||||||
| /// calls to `stream`, if any, before calling this function, | ||||||||||||||||||||||||||||||||||||||||
| /// but calling `finish` will close them with an error context. | ||||||||||||||||||||||||||||||||||||||||
| finish: static func(this: body) -> future<result<option<trailers>, error-code>>; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -348,21 +357,34 @@ 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`. | ||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// Only a single body resource can be active at a time. | ||||||||||||||||||||||||||||||||||||||||
| /// If this function is called before the body resource returned by | ||||||||||||||||||||||||||||||||||||||||
| /// a previous call to this function is dropped, the previously-returned | ||||||||||||||||||||||||||||||||||||||||
| /// body will be transitioned into an "error state" and all operations | ||||||||||||||||||||||||||||||||||||||||
| /// on it will fail. | ||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// In case, that a `body.finish` was called on the body returned by a previous | ||||||||||||||||||||||||||||||||||||||||
| /// call to this function, this function returns `none`. | ||||||||||||||||||||||||||||||||||||||||
|
rvolosatovs marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||||||||||||||||
| body: func() -> option<body>; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /// Takes ownership of the `request` and returns the `headers`, `body` | ||||||||||||||||||||||||||||||||||||||||
| /// and `request-options`, if any. | ||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// The headers returned by this function are considered to be a clone of the headers | ||||||||||||||||||||||||||||||||||||||||
| /// of the request. Changes to the `headers` returned by this function will not be reflected | ||||||||||||||||||||||||||||||||||||||||
| /// in the immutable `headers` resources, that could have been acquired by calls to `headers` | ||||||||||||||||||||||||||||||||||||||||
| /// prior to this function being called. | ||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is what we discussed, and it is the friendliest option but I remembered later that, when we discussed this as a group in the BA C-M impl call, the idea was to instead say: if you call (and similarly in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we'd need to wrap
Otherwise, I'm afraid this behavior would inevitably cause bugs in applications using this API. I feel like the behavior proposed in this PR is less surprising, provide better developer experience and introduce no overhead. That said I'm happy to add a new |
||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// In case, that a `body.finish` was called on the body returned by a previous | ||||||||||||||||||||||||||||||||||||||||
| /// call to `body`, this function returns body as `none`. | ||||||||||||||||||||||||||||||||||||||||
| into-parts: static func(this: request) -> tuple<headers, option<body>, option<request-options>>; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -431,21 +453,34 @@ 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`. | ||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// Only a single body resource can be active at a time. | ||||||||||||||||||||||||||||||||||||||||
| /// If this function is called before the body resource returned by | ||||||||||||||||||||||||||||||||||||||||
| /// a previous call to this function is dropped, the previously-returned | ||||||||||||||||||||||||||||||||||||||||
| /// body will be transitioned into an "error state" and all operations | ||||||||||||||||||||||||||||||||||||||||
| /// on it will fail. | ||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// In case, that a `body.finish` was called on the body returned by a previous | ||||||||||||||||||||||||||||||||||||||||
| /// call to this function, this function returns `none`. | ||||||||||||||||||||||||||||||||||||||||
| body: func() -> option<body>; | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| /// Takes ownership of the `response` and returns the `headers` and `body`, | ||||||||||||||||||||||||||||||||||||||||
| /// if any. | ||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// The headers returned by this function are considered to be a clone of the headers | ||||||||||||||||||||||||||||||||||||||||
| /// of the response. Changes to the `headers` returned by this function will not be reflected | ||||||||||||||||||||||||||||||||||||||||
| /// in the immutable `headers` resources, that could have been acquired by calls to `headers` | ||||||||||||||||||||||||||||||||||||||||
| /// prior to this function being called. | ||||||||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||||||||
| /// In case, that a `body.finish` was called on the body returned by a previous | ||||||||||||||||||||||||||||||||||||||||
| /// call to `body`, this function returns body as `none`. | ||||||||||||||||||||||||||||||||||||||||
| into-parts: static func(this: response) -> tuple<headers, option<body>>; | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.