diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-16 03:27:00 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-16 03:27:00 +0900 |
| commit | 7f6fab27ab088925ff5640f4a6767e7c19cd1fb9 (patch) | |
| tree | 953081c051b80ead175ecf93809d30d212901c76 | |
| parent | ba23ea4f22b5482d036706124a196fa03ef4b521 (diff) | |
| download | php-shirabe-7f6fab27ab088925ff5640f4a6767e7c19cd1fb9.tar.gz php-shirabe-7f6fab27ab088925ff5640f4a6767e7c19cd1fb9.tar.zst php-shirabe-7f6fab27ab088925ff5640f4a6767e7c19cd1fb9.zip | |
refactor(curl-downloader): wrap AuthHelper in Rc<RefCell<>>
CurlDownloader's download() is about to become an &self async method
as part of the HttpDownloader async rearchitecture; its auth_helper
field needs interior mutability ahead of that change. RemoteFilesystem
keeps its own AuthHelper as a plain field since it stays &mut self.
| -rw-r--r-- | crates/shirabe/src/util/http/curl_downloader.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/crates/shirabe/src/util/http/curl_downloader.rs b/crates/shirabe/src/util/http/curl_downloader.rs index f698fc25..a91455c1 100644 --- a/crates/shirabe/src/util/http/curl_downloader.rs +++ b/crates/shirabe/src/util/http/curl_downloader.rs @@ -72,7 +72,7 @@ pub struct CurlDownloader { next_id: i64, io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, config: std::rc::Rc<std::cell::RefCell<Config>>, - auth_helper: AuthHelper, + auth_helper: std::rc::Rc<std::cell::RefCell<AuthHelper>>, max_redirects: i64, max_retries: i64, } @@ -106,7 +106,10 @@ impl CurlDownloader { // cannot proceed, mirroring PHP aborting when curl is missing. .expect("failed to build reqwest client for CurlDownloader"); - let auth_helper = AuthHelper::new(io.clone(), config.clone()); + let auth_helper = std::rc::Rc::new(std::cell::RefCell::new(AuthHelper::new( + io.clone(), + config.clone(), + ))); Self { client, @@ -304,9 +307,11 @@ impl CurlDownloader { // PHP merges auth options + stream-context options at curl_setopt time. We need the // resulting header/method/content/timeout/ssl/max_file_size, so do it here per send. - let send_options = - self.auth_helper - .add_authentication_options(options.clone(), &origin, &url)?; + let send_options = self.auth_helper.borrow_mut().add_authentication_options( + options.clone(), + &origin, + &url, + )?; let send_options = crate::util::StreamContextFactory::init_options(&url, send_options, true) .map_err(|e| anyhow::anyhow!(e.message))?; @@ -511,7 +516,7 @@ impl CurlDownloader { Some(PhpMixed::Bool(b)) => StoreAuth::Bool(b), _ => StoreAuth::Bool(false), }; - self.auth_helper.store_auth(&origin, store_auth)?; + self.auth_helper.borrow().store_auth(&origin, store_auth)?; } // Atomic rename of the `~` temp file to its final name (file mode). @@ -774,7 +779,7 @@ impl CurlDownloader { { let status_message = response.inner.get_status_message(); let body = response.inner.get_body().map(|s| s.to_string()); - let result = self.auth_helper.prompt_auth_if_needed( + let result = self.auth_helper.borrow_mut().prompt_auth_if_needed( url, origin, response.inner.get_status_code(), @@ -794,7 +799,7 @@ impl CurlDownloader { // check for bitbucket login page asking to authenticate if origin == "bitbucket.org" - && !self.auth_helper.is_public_bit_bucket_download(url) + && !self.auth_helper.borrow().is_public_bit_bucket_download(url) && substr(url, -4, None) == ".zip" && (location_header.is_none() || substr(location_header.as_deref().unwrap_or(""), -4, None) != ".zip") @@ -828,7 +833,7 @@ impl CurlDownloader { if let Some(msg) = needs_auth_retry { if retry_auth_failure { - let result = self.auth_helper.prompt_auth_if_needed( + let result = self.auth_helper.borrow_mut().prompt_auth_if_needed( url, origin, 401, |
