Allow extensions to control the redirect policy for the HTTP client (#16162)

This PR extends the extension API with support for controlling the
redirect policy used by the HTTP client.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-08-13 10:40:21 -04:00 committed by GitHub
parent 98a2ab0686
commit 4450ebff6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 42 additions and 14 deletions

View file

@ -21,6 +21,7 @@ pub use wit::{
},
zed::extension::http_client::{
fetch, fetch_stream, HttpMethod, HttpRequest, HttpResponse, HttpResponseStream,
RedirectPolicy,
},
zed::extension::nodejs::{
node_binary_path, npm_install_package, npm_package_installed_version,

View file

@ -5,23 +5,44 @@ interface http-client {
method: http-method,
/// The URL to which the request should be made.
url: string,
/// Headers for the request.
/// The headers for the request.
headers: list<tuple<string, string>>,
/// The request body.
body: option<list<u8>>,
/// The policy to use for redirects.
redirect-policy: redirect-policy,
}
/// HTTP methods.
enum http-method {
/// `GET`
get,
post,
put,
delete,
/// `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 {
/// Redirects from the server will not be followed.
///
/// 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,
}
/// An HTTP response.
record http-response {
/// The response headers.
@ -36,7 +57,8 @@ interface http-client {
/// An HTTP response stream.
resource http-response-stream {
/// Retrieves the next chunk of data from the response stream.
/// Returns None if the stream has ended.
///
/// Returns `Ok(None)` if the stream has ended.
next-chunk: func() -> result<option<list<u8>>, string>;
}