wasmkeep 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,733 @@
1
+ package wasi:http@0.2.12;
2
+
3
+ /// This interface defines all of the types and methods for implementing
4
+ /// HTTP Requests and Responses, both incoming and outgoing, as well as
5
+ /// their headers, trailers, and bodies.
6
+ @since(version = 0.2.0)
7
+ interface types {
8
+ @since(version = 0.2.0)
9
+ use wasi:clocks/monotonic-clock@0.2.12.{duration};
10
+ @since(version = 0.2.0)
11
+ use wasi:io/streams@0.2.12.{input-stream, output-stream};
12
+ @since(version = 0.2.0)
13
+ use wasi:io/error@0.2.12.{error as io-error};
14
+ @since(version = 0.2.0)
15
+ use wasi:io/poll@0.2.12.{pollable};
16
+
17
+ /// This type corresponds to HTTP standard Methods.
18
+ @since(version = 0.2.0)
19
+ variant method {
20
+ get,
21
+ head,
22
+ post,
23
+ put,
24
+ delete,
25
+ connect,
26
+ options,
27
+ trace,
28
+ patch,
29
+ other(string),
30
+ }
31
+
32
+ /// This type corresponds to HTTP standard Related Schemes.
33
+ @since(version = 0.2.0)
34
+ variant scheme {
35
+ HTTP,
36
+ HTTPS,
37
+ other(string),
38
+ }
39
+
40
+ /// Defines the case payload type for `DNS-error` above:
41
+ @since(version = 0.2.0)
42
+ record DNS-error-payload {
43
+ rcode: option<string>,
44
+ info-code: option<u16>,
45
+ }
46
+
47
+ /// Defines the case payload type for `TLS-alert-received` above:
48
+ @since(version = 0.2.0)
49
+ record TLS-alert-received-payload {
50
+ alert-id: option<u8>,
51
+ alert-message: option<string>,
52
+ }
53
+
54
+ /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
55
+ @since(version = 0.2.0)
56
+ record field-size-payload {
57
+ field-name: option<string>,
58
+ field-size: option<u32>,
59
+ }
60
+
61
+ /// These cases are inspired by the IANA HTTP Proxy Error Types:
62
+ /// <https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types>
63
+ @since(version = 0.2.0)
64
+ variant error-code {
65
+ DNS-timeout,
66
+ DNS-error(DNS-error-payload),
67
+ destination-not-found,
68
+ destination-unavailable,
69
+ destination-IP-prohibited,
70
+ destination-IP-unroutable,
71
+ connection-refused,
72
+ connection-terminated,
73
+ connection-timeout,
74
+ connection-read-timeout,
75
+ connection-write-timeout,
76
+ connection-limit-reached,
77
+ TLS-protocol-error,
78
+ TLS-certificate-error,
79
+ TLS-alert-received(TLS-alert-received-payload),
80
+ HTTP-request-denied,
81
+ HTTP-request-length-required,
82
+ HTTP-request-body-size(option<u64>),
83
+ HTTP-request-method-invalid,
84
+ HTTP-request-URI-invalid,
85
+ HTTP-request-URI-too-long,
86
+ HTTP-request-header-section-size(option<u32>),
87
+ HTTP-request-header-size(option<field-size-payload>),
88
+ HTTP-request-trailer-section-size(option<u32>),
89
+ HTTP-request-trailer-size(field-size-payload),
90
+ HTTP-response-incomplete,
91
+ HTTP-response-header-section-size(option<u32>),
92
+ HTTP-response-header-size(field-size-payload),
93
+ HTTP-response-body-size(option<u64>),
94
+ HTTP-response-trailer-section-size(option<u32>),
95
+ HTTP-response-trailer-size(field-size-payload),
96
+ HTTP-response-transfer-coding(option<string>),
97
+ HTTP-response-content-coding(option<string>),
98
+ HTTP-response-timeout,
99
+ HTTP-upgrade-failed,
100
+ HTTP-protocol-error,
101
+ loop-detected,
102
+ configuration-error,
103
+ /// This is a catch-all error for anything that doesn't fit cleanly into a
104
+ /// more specific case. It also includes an optional string for an
105
+ /// unstructured description of the error. Users should not depend on the
106
+ /// string for diagnosing errors, as it's not required to be consistent
107
+ /// between implementations.
108
+ internal-error(option<string>),
109
+ }
110
+
111
+ /// This type enumerates the different kinds of errors that may occur when
112
+ /// setting or appending to a `fields` resource.
113
+ @since(version = 0.2.0)
114
+ variant header-error {
115
+ /// This error indicates that a `field-name` or `field-value` was
116
+ /// syntactically invalid when used with an operation that sets headers in a
117
+ /// `fields`.
118
+ invalid-syntax,
119
+ /// This error indicates that a forbidden `field-name` was used when trying
120
+ /// to set a header in a `fields`.
121
+ forbidden,
122
+ /// This error indicates that the operation on the `fields` was not
123
+ /// permitted because the fields are immutable.
124
+ immutable,
125
+ }
126
+
127
+ /// Field keys are always strings.
128
+ ///
129
+ /// Field keys should always be treated as case insensitive by the `fields`
130
+ /// resource for the purposes of equality checking.
131
+ ///
132
+ /// # Deprecation
133
+ ///
134
+ /// This type has been deprecated in favor of the `field-name` type.
135
+ @since(version = 0.2.0)
136
+ @deprecated(version = 0.2.2)
137
+ type field-key = string;
138
+
139
+ /// Field names are always strings.
140
+ ///
141
+ /// Field names should always be treated as case insensitive by the `fields`
142
+ /// resource for the purposes of equality checking.
143
+ @since(version = 0.2.1)
144
+ type field-name = field-key;
145
+
146
+ /// Field values should always be ASCII strings. However, in
147
+ /// reality, HTTP implementations often have to interpret malformed values,
148
+ /// so they are provided as a list of bytes.
149
+ @since(version = 0.2.0)
150
+ type field-value = list<u8>;
151
+
152
+ /// This following block defines the `fields` resource which corresponds to
153
+ /// HTTP standard Fields. Fields are a common representation used for both
154
+ /// Headers and Trailers.
155
+ ///
156
+ /// A `fields` may be mutable or immutable. A `fields` created using the
157
+ /// constructor, `from-list`, or `clone` will be mutable, but a `fields`
158
+ /// resource given by other means (including, but not limited to,
159
+ /// `incoming-request.headers`, `outgoing-request.headers`) might be
160
+ /// immutable. In an immutable fields, the `set`, `append`, and `delete`
161
+ /// operations will fail with `header-error.immutable`.
162
+ @since(version = 0.2.0)
163
+ resource fields {
164
+ /// Construct an empty HTTP Fields.
165
+ ///
166
+ /// The resulting `fields` is mutable.
167
+ @since(version = 0.2.0)
168
+ constructor();
169
+ /// Construct an HTTP Fields.
170
+ ///
171
+ /// The resulting `fields` is mutable.
172
+ ///
173
+ /// The list represents each name-value pair in the Fields. Names
174
+ /// which have multiple values are represented by multiple entries in this
175
+ /// list with the same name.
176
+ ///
177
+ /// The tuple is a pair of the field name, represented as a string, and
178
+ /// Value, represented as a list of bytes.
179
+ ///
180
+ /// An error result will be returned if any `field-name` or `field-value` is
181
+ /// syntactically invalid, or if a field is forbidden.
182
+ @since(version = 0.2.0)
183
+ from-list: static func(entries: list<tuple<field-name, field-value>>) -> result<fields, header-error>;
184
+ /// Get all of the values corresponding to a name. If the name is not present
185
+ /// in this `fields` or is syntactically invalid, an empty list is returned.
186
+ /// However, if the name is present but empty, this is represented by a list
187
+ /// with one or more empty field-values present.
188
+ @since(version = 0.2.0)
189
+ get: func(name: field-name) -> list<field-value>;
190
+ /// Returns `true` when the name is present in this `fields`. If the name is
191
+ /// syntactically invalid, `false` is returned.
192
+ @since(version = 0.2.0)
193
+ has: func(name: field-name) -> bool;
194
+ /// Set all of the values for a name. Clears any existing values for that
195
+ /// name, if they have been set.
196
+ ///
197
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
198
+ ///
199
+ /// Fails with `header-error.invalid-syntax` if the `field-name` or any of
200
+ /// the `field-value`s are syntactically invalid.
201
+ @since(version = 0.2.0)
202
+ set: func(name: field-name, value: list<field-value>) -> result<_, header-error>;
203
+ /// Delete all values for a name. Does nothing if no values for the name
204
+ /// exist.
205
+ ///
206
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
207
+ ///
208
+ /// Fails with `header-error.invalid-syntax` if the `field-name` is
209
+ /// syntactically invalid.
210
+ @since(version = 0.2.0)
211
+ delete: func(name: field-name) -> result<_, header-error>;
212
+ /// Append a value for a name. Does not change or delete any existing
213
+ /// values for that name.
214
+ ///
215
+ /// Fails with `header-error.immutable` if the `fields` are immutable.
216
+ ///
217
+ /// Fails with `header-error.invalid-syntax` if the `field-name` or
218
+ /// `field-value` are syntactically invalid.
219
+ @since(version = 0.2.0)
220
+ append: func(name: field-name, value: field-value) -> result<_, header-error>;
221
+ /// Retrieve the full set of names and values in the Fields. Like the
222
+ /// constructor, the list represents each name-value pair.
223
+ ///
224
+ /// The outer list represents each name-value pair in the Fields. Names
225
+ /// which have multiple values are represented by multiple entries in this
226
+ /// list with the same name.
227
+ ///
228
+ /// The names and values are always returned in the original casing and in
229
+ /// the order in which they will be serialized for transport.
230
+ @since(version = 0.2.0)
231
+ entries: func() -> list<tuple<field-name, field-value>>;
232
+ /// Make a deep copy of the Fields. Equivalent in behavior to calling the
233
+ /// `fields` constructor on the return value of `entries`. The resulting
234
+ /// `fields` is mutable.
235
+ @since(version = 0.2.0)
236
+ clone: func() -> fields;
237
+ }
238
+
239
+ /// Headers is an alias for Fields.
240
+ @since(version = 0.2.0)
241
+ type headers = fields;
242
+
243
+ /// Trailers is an alias for Fields.
244
+ @since(version = 0.2.0)
245
+ type trailers = fields;
246
+
247
+ /// Represents an incoming HTTP Request.
248
+ @since(version = 0.2.0)
249
+ resource incoming-request {
250
+ /// Returns the method of the incoming request.
251
+ @since(version = 0.2.0)
252
+ method: func() -> method;
253
+ /// Returns the path with query parameters from the request, as a string.
254
+ @since(version = 0.2.0)
255
+ path-with-query: func() -> option<string>;
256
+ /// Returns the protocol scheme from the request.
257
+ @since(version = 0.2.0)
258
+ scheme: func() -> option<scheme>;
259
+ /// Returns the authority of the Request's target URI, if present.
260
+ @since(version = 0.2.0)
261
+ authority: func() -> option<string>;
262
+ /// Get the `headers` associated with the request.
263
+ ///
264
+ /// The returned `headers` resource is immutable: `set`, `append`, and
265
+ /// `delete` operations will fail with `header-error.immutable`.
266
+ ///
267
+ /// The `headers` returned are a child resource: it must be dropped before
268
+ /// the parent `incoming-request` is dropped. Dropping this
269
+ /// `incoming-request` before all children are dropped will trap.
270
+ @since(version = 0.2.0)
271
+ headers: func() -> headers;
272
+ /// Gives the `incoming-body` associated with this request. Will only
273
+ /// return success at most once, and subsequent calls will return error.
274
+ @since(version = 0.2.0)
275
+ consume: func() -> result<incoming-body>;
276
+ }
277
+
278
+ /// Represents an outgoing HTTP Request.
279
+ @since(version = 0.2.0)
280
+ resource outgoing-request {
281
+ /// Construct a new `outgoing-request` with a default `method` of `GET`, and
282
+ /// `none` values for `path-with-query`, `scheme`, and `authority`.
283
+ ///
284
+ /// * `headers` is the HTTP Headers for the Request.
285
+ ///
286
+ /// It is possible to construct, or manipulate with the accessor functions
287
+ /// below, an `outgoing-request` with an invalid combination of `scheme`
288
+ /// and `authority`, or `headers` which are not permitted to be sent.
289
+ /// It is the obligation of the `outgoing-handler.handle` implementation
290
+ /// to reject invalid constructions of `outgoing-request`.
291
+ @since(version = 0.2.0)
292
+ constructor(headers: headers);
293
+ /// Returns the resource corresponding to the outgoing Body for this
294
+ /// Request.
295
+ ///
296
+ /// Returns success on the first call: the `outgoing-body` resource for
297
+ /// this `outgoing-request` can be retrieved at most once. Subsequent
298
+ /// calls will return error.
299
+ @since(version = 0.2.0)
300
+ body: func() -> result<outgoing-body>;
301
+ /// Get the Method for the Request.
302
+ @since(version = 0.2.0)
303
+ method: func() -> method;
304
+ /// Set the Method for the Request. Fails if the string present in a
305
+ /// `method.other` argument is not a syntactically valid method.
306
+ @since(version = 0.2.0)
307
+ set-method: func(method: method) -> result;
308
+ /// Get the combination of the HTTP Path and Query for the Request.
309
+ /// When `none`, this represents an empty Path and empty Query.
310
+ @since(version = 0.2.0)
311
+ path-with-query: func() -> option<string>;
312
+ /// Set the combination of the HTTP Path and Query for the Request.
313
+ /// When `none`, this represents an empty Path and empty Query. Fails is the
314
+ /// string given is not a syntactically valid path and query uri component.
315
+ @since(version = 0.2.0)
316
+ set-path-with-query: func(path-with-query: option<string>) -> result;
317
+ /// Get the HTTP Related Scheme for the Request. When `none`, the
318
+ /// implementation may choose an appropriate default scheme.
319
+ @since(version = 0.2.0)
320
+ scheme: func() -> option<scheme>;
321
+ /// Set the HTTP Related Scheme for the Request. When `none`, the
322
+ /// implementation may choose an appropriate default scheme. Fails if the
323
+ /// string given is not a syntactically valid uri scheme.
324
+ @since(version = 0.2.0)
325
+ set-scheme: func(scheme: option<scheme>) -> result;
326
+ /// Get the authority of the Request's target URI. A value of `none` may be used
327
+ /// with Related Schemes which do not require an authority. The HTTP and
328
+ /// HTTPS schemes always require an authority.
329
+ @since(version = 0.2.0)
330
+ authority: func() -> option<string>;
331
+ /// Set the authority of the Request's target URI. A value of `none` may be used
332
+ /// with Related Schemes which do not require an authority. The HTTP and
333
+ /// HTTPS schemes always require an authority. Fails if the string given is
334
+ /// not a syntactically valid URI authority.
335
+ @since(version = 0.2.0)
336
+ set-authority: func(authority: option<string>) -> result;
337
+ /// Get the headers associated with the Request.
338
+ ///
339
+ /// The returned `headers` resource is immutable: `set`, `append`, and
340
+ /// `delete` operations will fail with `header-error.immutable`.
341
+ ///
342
+ /// This headers resource is a child: it must be dropped before the parent
343
+ /// `outgoing-request` is dropped, or its ownership is transferred to
344
+ /// another component by e.g. `outgoing-handler.handle`.
345
+ @since(version = 0.2.0)
346
+ headers: func() -> headers;
347
+ }
348
+
349
+ /// Parameters for making an HTTP Request. Each of these parameters is
350
+ /// currently an optional timeout applicable to the transport layer of the
351
+ /// HTTP protocol.
352
+ ///
353
+ /// These timeouts are separate from any the user may use to bound a
354
+ /// blocking call to `wasi:io/poll.poll`.
355
+ @since(version = 0.2.0)
356
+ resource request-options {
357
+ /// Construct a default `request-options` value.
358
+ @since(version = 0.2.0)
359
+ constructor();
360
+ /// The timeout for the initial connect to the HTTP Server.
361
+ @since(version = 0.2.0)
362
+ connect-timeout: func() -> option<duration>;
363
+ /// Set the timeout for the initial connect to the HTTP Server. An error
364
+ /// return value indicates that this timeout is not supported.
365
+ @since(version = 0.2.0)
366
+ set-connect-timeout: func(duration: option<duration>) -> result;
367
+ /// The timeout for receiving the first byte of the Response body.
368
+ @since(version = 0.2.0)
369
+ first-byte-timeout: func() -> option<duration>;
370
+ /// Set the timeout for receiving the first byte of the Response body. An
371
+ /// error return value indicates that this timeout is not supported.
372
+ @since(version = 0.2.0)
373
+ set-first-byte-timeout: func(duration: option<duration>) -> result;
374
+ /// The timeout for receiving subsequent chunks of bytes in the Response
375
+ /// body stream.
376
+ @since(version = 0.2.0)
377
+ between-bytes-timeout: func() -> option<duration>;
378
+ /// Set the timeout for receiving subsequent chunks of bytes in the Response
379
+ /// body stream. An error return value indicates that this timeout is not
380
+ /// supported.
381
+ @since(version = 0.2.0)
382
+ set-between-bytes-timeout: func(duration: option<duration>) -> result;
383
+ }
384
+
385
+ /// Represents the ability to send an HTTP Response.
386
+ ///
387
+ /// This resource is used by the `wasi:http/incoming-handler` interface to
388
+ /// allow a Response to be sent corresponding to the Request provided as the
389
+ /// other argument to `incoming-handler.handle`.
390
+ @since(version = 0.2.0)
391
+ resource response-outparam {
392
+ /// Send an HTTP 1xx response.
393
+ ///
394
+ /// Unlike `response-outparam.set`, this does not consume the
395
+ /// `response-outparam`, allowing the guest to send an arbitrary number of
396
+ /// informational responses before sending the final response using
397
+ /// `response-outparam.set`.
398
+ ///
399
+ /// This will return an `HTTP-protocol-error` if `status` is not in the
400
+ /// range [100-199], or an `internal-error` if the implementation does not
401
+ /// support informational responses.
402
+ @unstable(feature = informational-outbound-responses)
403
+ send-informational: func(status: u16, headers: headers) -> result<_, error-code>;
404
+ /// Set the value of the `response-outparam` to either send a response,
405
+ /// or indicate an error.
406
+ ///
407
+ /// This method consumes the `response-outparam` to ensure that it is
408
+ /// called at most once. If it is never called, the implementation
409
+ /// will respond with an error.
410
+ ///
411
+ /// The user may provide an `error` to `response` to allow the
412
+ /// implementation determine how to respond with an HTTP error response.
413
+ @since(version = 0.2.0)
414
+ set: static func(param: response-outparam, response: result<outgoing-response, error-code>);
415
+ }
416
+
417
+ /// This type corresponds to the HTTP standard Status Code.
418
+ @since(version = 0.2.0)
419
+ type status-code = u16;
420
+
421
+ /// Represents an incoming HTTP Response.
422
+ @since(version = 0.2.0)
423
+ resource incoming-response {
424
+ /// Returns the status code from the incoming response.
425
+ @since(version = 0.2.0)
426
+ status: func() -> status-code;
427
+ /// Returns the headers from the incoming response.
428
+ ///
429
+ /// The returned `headers` resource is immutable: `set`, `append`, and
430
+ /// `delete` operations will fail with `header-error.immutable`.
431
+ ///
432
+ /// This headers resource is a child: it must be dropped before the parent
433
+ /// `incoming-response` is dropped.
434
+ @since(version = 0.2.0)
435
+ headers: func() -> headers;
436
+ /// Returns the incoming body. May be called at most once. Returns error
437
+ /// if called additional times.
438
+ @since(version = 0.2.0)
439
+ consume: func() -> result<incoming-body>;
440
+ }
441
+
442
+ /// Represents an incoming HTTP Request or Response's Body.
443
+ ///
444
+ /// A body has both its contents - a stream of bytes - and a (possibly
445
+ /// empty) set of trailers, indicating that the full contents of the
446
+ /// body have been received. This resource represents the contents as
447
+ /// an `input-stream` and the delivery of trailers as a `future-trailers`,
448
+ /// and ensures that the user of this interface may only be consuming either
449
+ /// the body contents or waiting on trailers at any given time.
450
+ @since(version = 0.2.0)
451
+ resource incoming-body {
452
+ /// Returns the contents of the body, as a stream of bytes.
453
+ ///
454
+ /// Returns success on first call: the stream representing the contents
455
+ /// can be retrieved at most once. Subsequent calls will return error.
456
+ ///
457
+ /// The returned `input-stream` resource is a child: it must be dropped
458
+ /// before the parent `incoming-body` is dropped, or consumed by
459
+ /// `incoming-body.finish`.
460
+ ///
461
+ /// This invariant ensures that the implementation can determine whether
462
+ /// the user is consuming the contents of the body, waiting on the
463
+ /// `future-trailers` to be ready, or neither. This allows for network
464
+ /// backpressure is to be applied when the user is consuming the body,
465
+ /// and for that backpressure to not inhibit delivery of the trailers if
466
+ /// the user does not read the entire body.
467
+ @since(version = 0.2.0)
468
+ %stream: func() -> result<input-stream>;
469
+ /// Takes ownership of `incoming-body`, and returns a `future-trailers`.
470
+ /// This function will trap if the `input-stream` child is still alive.
471
+ @since(version = 0.2.0)
472
+ finish: static func(this: incoming-body) -> future-trailers;
473
+ }
474
+
475
+ /// Represents a future which may eventually return trailers, or an error.
476
+ ///
477
+ /// In the case that the incoming HTTP Request or Response did not have any
478
+ /// trailers, this future will resolve to the empty set of trailers once the
479
+ /// complete Request or Response body has been received.
480
+ @since(version = 0.2.0)
481
+ resource future-trailers {
482
+ /// Returns a pollable which becomes ready when either the trailers have
483
+ /// been received, or an error has occurred. When this pollable is ready,
484
+ /// the `get` method will return `some`.
485
+ @since(version = 0.2.0)
486
+ subscribe: func() -> pollable;
487
+ /// Returns the contents of the trailers, or an error which occurred,
488
+ /// once the future is ready.
489
+ ///
490
+ /// The outer `option` represents future readiness. Users can wait on this
491
+ /// `option` to become `some` using the `subscribe` method.
492
+ ///
493
+ /// The outer `result` is used to retrieve the trailers or error at most
494
+ /// once. It will be success on the first call in which the outer option
495
+ /// is `some`, and error on subsequent calls.
496
+ ///
497
+ /// The inner `result` represents that either the HTTP Request or Response
498
+ /// body, as well as any trailers, were received successfully, or that an
499
+ /// error occurred receiving them. The optional `trailers` indicates whether
500
+ /// or not trailers were present in the body.
501
+ ///
502
+ /// When some `trailers` are returned by this method, the `trailers`
503
+ /// resource is immutable, and a child. Use of the `set`, `append`, or
504
+ /// `delete` methods will return an error, and the resource must be
505
+ /// dropped before the parent `future-trailers` is dropped.
506
+ @since(version = 0.2.0)
507
+ get: func() -> option<result<result<option<trailers>, error-code>>>;
508
+ }
509
+
510
+ /// Represents an outgoing HTTP Response.
511
+ @since(version = 0.2.0)
512
+ resource outgoing-response {
513
+ /// Construct an `outgoing-response`, with a default `status-code` of `200`.
514
+ /// If a different `status-code` is needed, it must be set via the
515
+ /// `set-status-code` method.
516
+ ///
517
+ /// * `headers` is the HTTP Headers for the Response.
518
+ @since(version = 0.2.0)
519
+ constructor(headers: headers);
520
+ /// Get the HTTP Status Code for the Response.
521
+ @since(version = 0.2.0)
522
+ status-code: func() -> status-code;
523
+ /// Set the HTTP Status Code for the Response. Fails if the status-code
524
+ /// given is not a valid http status code.
525
+ @since(version = 0.2.0)
526
+ set-status-code: func(status-code: status-code) -> result;
527
+ /// Get the headers associated with the Request.
528
+ ///
529
+ /// The returned `headers` resource is immutable: `set`, `append`, and
530
+ /// `delete` operations will fail with `header-error.immutable`.
531
+ ///
532
+ /// This headers resource is a child: it must be dropped before the parent
533
+ /// `outgoing-request` is dropped, or its ownership is transferred to
534
+ /// another component by e.g. `outgoing-handler.handle`.
535
+ @since(version = 0.2.0)
536
+ headers: func() -> headers;
537
+ /// Returns the resource corresponding to the outgoing Body for this Response.
538
+ ///
539
+ /// Returns success on the first call: the `outgoing-body` resource for
540
+ /// this `outgoing-response` can be retrieved at most once. Subsequent
541
+ /// calls will return error.
542
+ @since(version = 0.2.0)
543
+ body: func() -> result<outgoing-body>;
544
+ }
545
+
546
+ /// Represents an outgoing HTTP Request or Response's Body.
547
+ ///
548
+ /// A body has both its contents - a stream of bytes - and a (possibly
549
+ /// empty) set of trailers, inducating the full contents of the body
550
+ /// have been sent. This resource represents the contents as an
551
+ /// `output-stream` child resource, and the completion of the body (with
552
+ /// optional trailers) with a static function that consumes the
553
+ /// `outgoing-body` resource, and ensures that the user of this interface
554
+ /// may not write to the body contents after the body has been finished.
555
+ ///
556
+ /// If the user code drops this resource, as opposed to calling the static
557
+ /// method `finish`, the implementation should treat the body as incomplete,
558
+ /// and that an error has occurred. The implementation should propagate this
559
+ /// error to the HTTP protocol by whatever means it has available,
560
+ /// including: corrupting the body on the wire, aborting the associated
561
+ /// Request, or sending a late status code for the Response.
562
+ @since(version = 0.2.0)
563
+ resource outgoing-body {
564
+ /// Returns a stream for writing the body contents.
565
+ ///
566
+ /// The returned `output-stream` is a child resource: it must be dropped
567
+ /// before the parent `outgoing-body` resource is dropped (or finished),
568
+ /// otherwise the `outgoing-body` drop or `finish` will trap.
569
+ ///
570
+ /// Returns success on the first call: the `output-stream` resource for
571
+ /// this `outgoing-body` may be retrieved at most once. Subsequent calls
572
+ /// will return error.
573
+ @since(version = 0.2.0)
574
+ write: func() -> result<output-stream>;
575
+ /// Finalize an outgoing body, optionally providing trailers. This must be
576
+ /// called to signal that the response is complete. If the `outgoing-body`
577
+ /// is dropped without calling `outgoing-body.finalize`, the implementation
578
+ /// should treat the body as corrupted.
579
+ ///
580
+ /// Fails if the body's `outgoing-request` or `outgoing-response` was
581
+ /// constructed with a Content-Length header, and the contents written
582
+ /// to the body (via `write`) does not match the value given in the
583
+ /// Content-Length.
584
+ @since(version = 0.2.0)
585
+ finish: static func(this: outgoing-body, trailers: option<trailers>) -> result<_, error-code>;
586
+ }
587
+
588
+ /// Represents a future which may eventually return an incoming HTTP
589
+ /// Response, or an error.
590
+ ///
591
+ /// This resource is returned by the `wasi:http/outgoing-handler` interface to
592
+ /// provide the HTTP Response corresponding to the sent Request.
593
+ @since(version = 0.2.0)
594
+ resource future-incoming-response {
595
+ /// Returns a pollable which becomes ready when either the Response has
596
+ /// been received, or an error has occurred. When this pollable is ready,
597
+ /// the `get` method will return `some`.
598
+ @since(version = 0.2.0)
599
+ subscribe: func() -> pollable;
600
+ /// Returns the incoming HTTP Response, or an error, once one is ready.
601
+ ///
602
+ /// The outer `option` represents future readiness. Users can wait on this
603
+ /// `option` to become `some` using the `subscribe` method.
604
+ ///
605
+ /// The outer `result` is used to retrieve the response or error at most
606
+ /// once. It will be success on the first call in which the outer option
607
+ /// is `some`, and error on subsequent calls.
608
+ ///
609
+ /// The inner `result` represents that either the incoming HTTP Response
610
+ /// status and headers have received successfully, or that an error
611
+ /// occurred. Errors may also occur while consuming the response body,
612
+ /// but those will be reported by the `incoming-body` and its
613
+ /// `output-stream` child.
614
+ @since(version = 0.2.0)
615
+ get: func() -> option<result<result<incoming-response, error-code>>>;
616
+ }
617
+
618
+ /// Attempts to extract a http-related `error` from the wasi:io `error`
619
+ /// provided.
620
+ ///
621
+ /// Stream operations which return
622
+ /// `wasi:io/stream.stream-error.last-operation-failed` have a payload of
623
+ /// type `wasi:io/error.error` with more information about the operation
624
+ /// that failed. This payload can be passed through to this function to see
625
+ /// if there's http-related information about the error to return.
626
+ ///
627
+ /// Note that this function is fallible because not all io-errors are
628
+ /// http-related errors.
629
+ @since(version = 0.2.0)
630
+ http-error-code: func(err: borrow<io-error>) -> option<error-code>;
631
+ }
632
+
633
+ /// This interface defines a handler of incoming HTTP Requests. It should
634
+ /// be exported by components which can respond to HTTP Requests.
635
+ @since(version = 0.2.0)
636
+ interface incoming-handler {
637
+ @since(version = 0.2.0)
638
+ use types.{incoming-request, response-outparam};
639
+
640
+ /// This function is invoked with an incoming HTTP Request, and a resource
641
+ /// `response-outparam` which provides the capability to reply with an HTTP
642
+ /// Response. The response is sent by calling the `response-outparam.set`
643
+ /// method, which allows execution to continue after the response has been
644
+ /// sent. This enables both streaming to the response body, and performing other
645
+ /// work.
646
+ ///
647
+ /// The implementor of this function must write a response to the
648
+ /// `response-outparam` before returning, or else the caller will respond
649
+ /// with an error on its behalf.
650
+ @since(version = 0.2.0)
651
+ handle: func(request: incoming-request, response-out: response-outparam);
652
+ }
653
+
654
+ /// This interface defines a handler of outgoing HTTP Requests. It should be
655
+ /// imported by components which wish to make HTTP Requests.
656
+ @since(version = 0.2.0)
657
+ interface outgoing-handler {
658
+ @since(version = 0.2.0)
659
+ use types.{outgoing-request, request-options, future-incoming-response, error-code};
660
+
661
+ /// This function is invoked with an outgoing HTTP Request, and it returns
662
+ /// a resource `future-incoming-response` which represents an HTTP Response
663
+ /// which may arrive in the future.
664
+ ///
665
+ /// The `options` argument accepts optional parameters for the HTTP
666
+ /// protocol's transport layer.
667
+ ///
668
+ /// This function may return an error if the `outgoing-request` is invalid
669
+ /// or not allowed to be made. Otherwise, protocol errors are reported
670
+ /// through the `future-incoming-response`.
671
+ @since(version = 0.2.0)
672
+ handle: func(request: outgoing-request, options: option<request-options>) -> result<future-incoming-response, error-code>;
673
+ }
674
+
675
+ /// The `wasi:http/imports` world imports all the APIs for HTTP proxies.
676
+ /// It is intended to be `include`d in other worlds.
677
+ @since(version = 0.2.0)
678
+ world imports {
679
+ @since(version = 0.2.0)
680
+ import wasi:io/poll@0.2.12;
681
+ @since(version = 0.2.0)
682
+ import wasi:clocks/monotonic-clock@0.2.12;
683
+ @since(version = 0.2.0)
684
+ import wasi:clocks/wall-clock@0.2.12;
685
+ @since(version = 0.2.0)
686
+ import wasi:random/random@0.2.12;
687
+ @since(version = 0.2.0)
688
+ import wasi:io/error@0.2.12;
689
+ @since(version = 0.2.0)
690
+ import wasi:io/streams@0.2.12;
691
+ @since(version = 0.2.0)
692
+ import wasi:cli/stdout@0.2.12;
693
+ @since(version = 0.2.0)
694
+ import wasi:cli/stderr@0.2.12;
695
+ @since(version = 0.2.0)
696
+ import wasi:cli/stdin@0.2.12;
697
+ @since(version = 0.2.0)
698
+ import types;
699
+ @since(version = 0.2.0)
700
+ import outgoing-handler;
701
+ }
702
+ /// The `wasi:http/proxy` world captures a widely-implementable intersection of
703
+ /// hosts that includes HTTP forward and reverse proxies. Components targeting
704
+ /// this world may concurrently stream in and out any number of incoming and
705
+ /// outgoing HTTP requests.
706
+ @since(version = 0.2.0)
707
+ world proxy {
708
+ @since(version = 0.2.0)
709
+ import wasi:io/poll@0.2.12;
710
+ @since(version = 0.2.0)
711
+ import wasi:clocks/monotonic-clock@0.2.12;
712
+ @since(version = 0.2.0)
713
+ import wasi:clocks/wall-clock@0.2.12;
714
+ @since(version = 0.2.0)
715
+ import wasi:random/random@0.2.12;
716
+ @since(version = 0.2.0)
717
+ import wasi:io/error@0.2.12;
718
+ @since(version = 0.2.0)
719
+ import wasi:io/streams@0.2.12;
720
+ @since(version = 0.2.0)
721
+ import wasi:cli/stdout@0.2.12;
722
+ @since(version = 0.2.0)
723
+ import wasi:cli/stderr@0.2.12;
724
+ @since(version = 0.2.0)
725
+ import wasi:cli/stdin@0.2.12;
726
+ @since(version = 0.2.0)
727
+ import types;
728
+ @since(version = 0.2.0)
729
+ import outgoing-handler;
730
+
731
+ @since(version = 0.2.0)
732
+ export incoming-handler;
733
+ }