2
2
/// HTTP Requests and Responses, both incoming and outgoing, as well as
3
3
/// their headers, trailers, and bodies.
4
4
interface types {
5
+ use wasi :clocks /monotonic-clock . {duration };
5
6
use wasi :io /streams . {input-stream , output-stream };
6
7
use wasi :io /poll . {pollable };
7
8
@@ -36,6 +37,13 @@ interface types {
36
37
unexpected-error (string )
37
38
}
38
39
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
+
39
47
/// Field keys are always strings.
40
48
type field-key = string ;
41
49
@@ -49,6 +57,9 @@ interface types {
49
57
/// Headers and Trailers.
50
58
resource fields {
51
59
60
+ /// Construct an empty HTTP Fields.
61
+ constructor ();
62
+
52
63
/// Construct an HTTP Fields.
53
64
///
54
65
/// The list represents each key-value pair in the Fields. Keys
@@ -59,22 +70,33 @@ interface types {
59
70
/// Value, represented as a list of bytes. In a valid Fields, all keys
60
71
/// and values are valid UTF-8 strings. However, values are not always
61
72
/// 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 >;
63
79
64
80
/// Get all of the values corresponding to a key.
65
81
get : func (name : field-key ) -> list <field-value >;
66
82
67
83
/// Set all of the values for a key. Clears any existing values for that
68
84
/// 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 >;
70
89
71
90
/// Delete all values for a key. Does nothing if no values for the key
72
91
/// exist.
73
92
delete : func (name : field-key );
74
93
75
94
/// Append a value for a key. Does not change or delete any existing
76
95
/// 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 >;
78
100
79
101
80
102
/// Retrieve the full set of keys and values in the Fields. Like the
@@ -202,21 +224,32 @@ interface types {
202
224
///
203
225
/// These timeouts are separate from any the user may use to bound a
204
226
/// 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 ();
210
230
211
231
/// 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 ;
213
237
214
238
/// 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 ;
216
244
217
245
/// The timeout for receiving subsequent chunks of bytes in the Response
218
246
/// 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 ;
220
253
}
221
254
222
255
/// Represents the ability to send an HTTP Response.
@@ -235,14 +268,10 @@ interface types {
235
268
///
236
269
/// The user may provide an `error` to `response` to allow the
237
270
/// 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.
242
271
set : static func (
243
272
param : response-outparam ,
244
273
response : result <outgoing-response , error >,
245
- ) -> result < _ , error > ;
274
+ );
246
275
}
247
276
248
277
/// This type corresponds to the HTTP standard Status Code.
@@ -314,8 +343,9 @@ interface types {
314
343
///
315
344
/// The `result` represents that either the HTTP Request or Response body,
316
345
/// 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 >>;
319
349
}
320
350
321
351
/// Represents an outgoing HTTP Response.
0 commit comments