Debian Codegraph @

.cargo/vendor/wasip2/wit/deps/http/handler.wit

raw
1 /// This interface defines a handler of incoming HTTP Requests. It should
2 /// be exported by components which can respond to HTTP Requests.
3 @since(version = 0.2.0)
4 interface incoming-handler {
5 @since(version = 0.2.0)
6 use types.{incoming-request, response-outparam};
7
8 /// This function is invoked with an incoming HTTP Request, and a resource
9 /// `response-outparam` which provides the capability to reply with an HTTP
10 /// Response. The response is sent by calling the `response-outparam.set`
11 /// method, which allows execution to continue after the response has been
12 /// sent. This enables both streaming to the response body, and performing other
13 /// work.
14 ///
15 /// The implementor of this function must write a response to the
16 /// `response-outparam` before returning, or else the caller will respond
17 /// with an error on its behalf.
18 @since(version = 0.2.0)
19 handle: func(
20 request: incoming-request,
21 response-out: response-outparam
22 );
23 }
24
25 /// This interface defines a handler of outgoing HTTP Requests. It should be
26 /// imported by components which wish to make HTTP Requests.
27 @since(version = 0.2.0)
28 interface outgoing-handler {
29 @since(version = 0.2.0)
30 use types.{
31 outgoing-request, request-options, future-incoming-response, error-code
32 };
33
34 /// This function is invoked with an outgoing HTTP Request, and it returns
35 /// a resource `future-incoming-response` which represents an HTTP Response
36 /// which may arrive in the future.
37 ///
38 /// The `options` argument accepts optional parameters for the HTTP
39 /// protocol's transport layer.
40 ///
41 /// This function may return an error if the `outgoing-request` is invalid
42 /// or not allowed to be made. Otherwise, protocol errors are reported
43 /// through the `future-incoming-response`.
44 @since(version = 0.2.0)
45 handle: func(
46 request: outgoing-request,
47 options: option<request-options>
48 ) -> result<future-incoming-response, error-code>;
49 }