Skip to content

Commit bcddc79

Browse files
committed
Update some signatures
1 parent c4e9358 commit bcddc79

File tree

1 file changed

+48
-18
lines changed

1 file changed

+48
-18
lines changed

wit/types.wit

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/// HTTP Requests and Responses, both incoming and outgoing, as well as
33
/// their headers, trailers, and bodies.
44
interface types {
5+
use wasi:clocks/monotonic-clock.{duration};
56
use wasi:io/streams.{input-stream, output-stream};
67
use wasi:io/poll.{pollable};
78

@@ -36,6 +37,13 @@ interface types {
3637
unexpected-error(string)
3738
}
3839

40+
/// This tyep enumerates the different kinds of errors that may occur when
41+
/// setting or appending to a `fields` resource.
42+
variant header-error {
43+
invalid-syntax,
44+
forbidden,
45+
}
46+
3947
/// Field keys are always strings.
4048
type field-key = string;
4149

@@ -49,6 +57,9 @@ interface types {
4957
/// Headers and Trailers.
5058
resource fields {
5159

60+
/// Construct an empty HTTP Fields.
61+
constructor();
62+
5263
/// Construct an HTTP Fields.
5364
///
5465
/// The list represents each key-value pair in the Fields. Keys
@@ -59,22 +70,33 @@ interface types {
5970
/// Value, represented as a list of bytes. In a valid Fields, all keys
6071
/// and values are valid UTF-8 strings. However, values are not always
6172
/// well-formed, so they are represented as a raw list of bytes.
62-
constructor(entries: list<tuple<field-key,field-value>>);
73+
///
74+
/// An error result will be returned if any header or value was
75+
/// syntactically invalid, or if a header was forbidden.
76+
from-list: static func(
77+
entries: list<tuple<field-key,field-value>>
78+
) -> result<fields, header-error>;
6379

6480
/// Get all of the values corresponding to a key.
6581
get: func(name: field-key) -> list<field-value>;
6682

6783
/// Set all of the values for a key. Clears any existing values for that
6884
/// key, if they have been set.
69-
set: func(name: field-key, value: list<field-value>);
85+
///
86+
/// The operation can fail if the name or value arguments are invalid, or if
87+
/// the name is forbidden.
88+
set: func(name: field-key, value: list<field-value>) -> result<_, header-error>;
7089

7190
/// Delete all values for a key. Does nothing if no values for the key
7291
/// exist.
7392
delete: func(name: field-key);
7493

7594
/// Append a value for a key. Does not change or delete any existing
7695
/// values for that key.
77-
append: func(name: field-key, value: field-value);
96+
///
97+
/// The operation can fail if the name or value arguments are invalid, or if
98+
/// the name is forbidden.
99+
append: func(name: field-key, value: field-value) -> result<_, header-error>;
78100

79101

80102
/// Retrieve the full set of keys and values in the Fields. Like the
@@ -202,21 +224,32 @@ interface types {
202224
///
203225
/// These timeouts are separate from any the user may use to bound a
204226
/// blocking call to `wasi:io/poll.poll-list`.
205-
///
206-
/// FIXME: Make this a resource to allow it to be optionally extended by
207-
/// future evolution of the standard and/or other interfaces at some later
208-
/// date?
209-
record request-options {
227+
resource request-options {
228+
/// Construct a default `request-options` value.
229+
constructor();
210230

211231
/// The timeout for the initial connect to the HTTP Server.
212-
connect-timeout-ms: option<u32>,
232+
connect-timeout-ms: func() -> option<duration>;
233+
234+
/// Set the timeout for the initial connect to the HTTP Server. An error
235+
/// return value indicates that this timeout is not supported.
236+
set-connect-timeout-ms: func(ms: option<duration>) -> result;
213237

214238
/// The timeout for receiving the first byte of the Response body.
215-
first-byte-timeout-ms: option<u32>,
239+
first-byte-timeout-ms: func() -> option<duration>;
240+
241+
/// Set the timeout for receiving the first byte of the Response body. An
242+
/// error return value indicates that this timeout is not supported.
243+
set-first-byte-timeout-ms: func(ms: option<duration>) -> result;
216244

217245
/// The timeout for receiving subsequent chunks of bytes in the Response
218246
/// body stream.
219-
between-bytes-timeout-ms: option<u32>
247+
between-bytes-timeout-ms: func() -> option<duration>;
248+
249+
/// Set the timeout for receiving subsequent chunks of bytes in the Response
250+
/// body stream. An error return value indicates that this timeout is not
251+
/// supported.
252+
set-between-bytes-timeout-ms: func(ms: option<duration>) -> result;
220253
}
221254

222255
/// Represents the ability to send an HTTP Response.
@@ -235,14 +268,10 @@ interface types {
235268
///
236269
/// The user may provide an `error` to `response` to allow the
237270
/// implementation determine how to respond with an HTTP error response.
238-
///
239-
/// This method may return an error when the `outgoing-response` contains
240-
/// a `status-code` or anything else the implementation does not permit or
241-
/// support.
242271
set: static func(
243272
param: response-outparam,
244273
response: result<outgoing-response, error>,
245-
) -> result<_, error>;
274+
);
246275
}
247276

248277
/// This type corresponds to the HTTP standard Status Code.
@@ -314,8 +343,9 @@ interface types {
314343
///
315344
/// The `result` represents that either the HTTP Request or Response body,
316345
/// as well as any trailers, were received successfully, or that an error
317-
/// occured receiving them.
318-
get: func() -> option<result<trailers, error>>;
346+
/// occured receiving them. The optional `trailers` indicates whether or not
347+
/// trailers were present in the body.
348+
get: func() -> option<result<option<trailers>, error>>;
319349
}
320350

321351
/// Represents an outgoing HTTP Response.

0 commit comments

Comments
 (0)