From af4b9fcba1206e3fcc97fc243ffc674f85547942 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Jun 2026 19:47:36 +0900 Subject: refactor(http-response): take url directly instead of request map Response only ever reads the url out of the request array, so accept it as a String directly. With url always present the 'url key missing' LogicException can no longer fire, so Response::new and CurlResponse::new return Self instead of a double Result. Also drops the unused from_php_mixed/to_php_mixed stubs and the request_to_map helper. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/util/http_downloader.rs | 48 +++++------------------------- 1 file changed, 8 insertions(+), 40 deletions(-) (limited to 'crates/shirabe/src/util/http_downloader.rs') diff --git a/crates/shirabe/src/util/http_downloader.rs b/crates/shirabe/src/util/http_downloader.rs index b33ed58..5d0eae6 100644 --- a/crates/shirabe/src/util/http_downloader.rs +++ b/crates/shirabe/src/util/http_downloader.rs @@ -388,10 +388,7 @@ impl HttpDownloader { let headers = rfs.get_last_headers().to_vec(); let code = RemoteFilesystem::find_status_code(&headers); let body = Some(format!("{}~", copy_to)); - match Response::new(Self::request_to_map(&request), code, headers, body)? { - Ok(r) => Ok(r), - Err(e) => Err(e.into()), - } + Ok(Response::new(request.url.clone(), code, headers, body)) } else { let body = match rfs.get_contents(&origin, &url, false, options.clone())? { GetResult::Content(s) => Some(s), @@ -399,10 +396,7 @@ impl HttpDownloader { }; let headers = rfs.get_last_headers().to_vec(); let code = RemoteFilesystem::find_status_code(&headers); - match Response::new(Self::request_to_map(&request), code, headers, body)? { - Ok(r) => Ok(r), - Err(e) => Err(e.into()), - } + Ok(Response::new(request.url.clone(), code, headers, body)) } })() }; @@ -410,30 +404,6 @@ impl HttpDownloader { self.settle_job(id, result); } - /// PHP `new Response($job['request'], ...)` is fed the whole request array; reproduce it. - fn request_to_map(request: &Request) -> IndexMap { - let mut m: IndexMap = IndexMap::new(); - m.insert("url".to_string(), PhpMixed::String(request.url.clone())); - m.insert( - "options".to_string(), - PhpMixed::Array( - request - .options - .iter() - .map(|(k, v)| (k.clone(), Box::new(v.clone()))) - .collect(), - ), - ); - m.insert( - "copyTo".to_string(), - match &request.copy_to { - Some(s) => PhpMixed::String(s.clone()), - None => PhpMixed::Null, - }, - ); - m - } - /// Applies the effect of PHP's promise `.then` handlers: records the response/exception, /// transitions the job status and decrements the running-job counter. fn settle_job(&mut self, id: i64, result: anyhow::Result) { @@ -508,14 +478,12 @@ impl HttpDownloader { } }; if has_if_modified_since { - let mut req_map: IndexMap = IndexMap::new(); - req_map.insert("url".to_string(), PhpMixed::String(url.clone())); - let response = - match Response::new(req_map, Some(304), Vec::new(), Some(String::new())) { - Ok(Ok(r)) => Ok(r), - Ok(Err(e)) => Err(e.into()), - Err(e) => Err(e), - }; + let response = Ok(Response::new( + url.clone(), + Some(304), + Vec::new(), + Some(String::new()), + )); self.settle_job(id, response); } else { let mut e = TransportException::new( -- cgit v1.3.1