interface extension-http {
/// http request
record http-request {
/// http method
method: http-method,
/// http url
url: string,
/// http headers
headers: list<tuple<string,string>>,
/// request body
body: option<list<u8>>,
/// The policy to use for redirects.
redirect-policy: redirect-policy,
}
/// http method
enum http-method {
/// GET
get,
/// HEAD
head,
/// POST
post,
/// PUT
put,
/// DELETE
delete,
/// OPTIONS
options,
/// PATCH
patch,
}
/// The policy for dealing with redirects received from the server.
variant redirect-policy {
/// This is the default behavior.
no-follow,
/// Redirects from the server will be followed up to the specified limit.
follow-limit(u32),
/// All redirects from the server will be followed.
follow-all,
}
/// The response for an http
record http-response {
/// http status
status-code: u16,
/// response headers
headers: list<tuple<string,string>>,
/// response body
body: list<u8>,
}
/// 普通http请求
fetch: func(req: http-request) -> result<http-response,string>;
/// stream http response
resource http-response-stream {
/// Returns `Ok(None)` if the stream has ended.
next-chunk: func() -> result<option<list<u8>>,string>;
}
/// stream http 请求
fetch-stream: func(req: http-request) -> result<http-response-stream,string>;
}