From 3f26ee86048243e71a6616b1c1b3879dffabc01a Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Mon, 13 Mar 2023 11:29:05 +0100 Subject: [PATCH] feat(ext/fetch): support fallible request-builder hooks (#18116) This tweaks the signature of `request_builder_hook` in order to support fallible hooks. The rationale for this is mostly on two sides: * it allows a hook to inspect and possibly drop an outgoing request (e.g. for policying purposes), bubbling up a detailed error message to the user. * it wires into newer `reqwest` API which allows to split and then reassemble a `RequestBuilder`, although only in a fallible way (https://github.com/seanmonstar/reqwest/pull/1770) --- ext/fetch/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 75f72233ea59b..20885dda572b9 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -72,7 +72,8 @@ pub struct Options { pub user_agent: String, pub root_cert_store: Option, pub proxy: Option, - pub request_builder_hook: Option RequestBuilder>, + pub request_builder_hook: + Option Result>, pub unsafely_ignore_certificate_errors: Option>, pub client_cert_chain_and_key: Option<(String, String)>, pub file_fetch_handler: Rc, @@ -342,7 +343,8 @@ where let options = state.borrow::(); if let Some(request_builder_hook) = options.request_builder_hook { - request = request_builder_hook(request); + request = request_builder_hook(request) + .map_err(|err| type_error(err.to_string()))?; } let cancel_handle = CancelHandle::new_rc();