diff options
| author | Maxim Cournoyer <maxim@guixotic.coop> | 2026-01-19 10:43:52 +0900 |
|---|---|---|
| committer | Maxim Cournoyer <maxim@guixotic.coop> | 2026-01-27 14:27:25 +0900 |
| commit | 33bb5f129d8e2070cbce5c8e34b9a0bab8e0f61f (patch) | |
| tree | 0d585f4cb6625ffa9c74c725210da8475e663f55 /gnu | |
| parent | d5cd7679d3d81aa11e15fe0f2c8902d6aa620160 (diff) | |
gnu: mitm-cache: Apply patch to gracefully handle HEAD requests.
* gnu/packages/patches/mitm-cache-head-requests.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register.
* gnu/packages/rust-apps.scm (mitm-cache): Apply it.
Change-Id: I3480735340ef72be2acf8a3fdcfa9e71a6961b45
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/local.mk | 1 | ||||
| -rw-r--r-- | gnu/packages/patches/mitm-cache-head-requests.patch | 69 | ||||
| -rw-r--r-- | gnu/packages/rust-apps.scm | 3 |
3 files changed, 72 insertions, 1 deletions
diff --git a/gnu/local.mk b/gnu/local.mk index 99d38943214..241729add75 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1901,6 +1901,7 @@ dist_patch_DATA = \ %D%/packages/patches/minisat-install.patch \ %D%/packages/patches/miniz-for-pytorch.patch \ %D%/packages/patches/mit-krb5-hurd.patch \ + %D%/packages/patches/mitm-cache-head-requests.patch \ %D%/packages/patches/mpc123-initialize-ao.patch \ %D%/packages/patches/mpg321-CVE-2019-14247.patch \ %D%/packages/patches/mpg321-gcc-10.patch \ diff --git a/gnu/packages/patches/mitm-cache-head-requests.patch b/gnu/packages/patches/mitm-cache-head-requests.patch new file mode 100644 index 00000000000..5e641c01b5e --- /dev/null +++ b/gnu/packages/patches/mitm-cache-head-requests.patch @@ -0,0 +1,69 @@ +Upstream-status: <https://github.com/chayleaf/mitm-cache/pull/5> + +diff --git a/src/main.rs b/src/main.rs +index d9f760f..215ed89 100644 +--- a/src/main.rs ++++ b/src/main.rs +@@ -1,5 +1,6 @@ + use base64::Engine; + use clap::{Parser, Subcommand}; ++use futures_util::StreamExt; + use http_body_util::BodyExt; + use hudsucker::{ + certificate_authority::RcgenAuthority, +@@ -11,6 +12,7 @@ use hudsucker::{ + tokio_tungstenite::tungstenite::http::uri::Scheme, + Body, HttpContext, HttpHandler, Proxy, RequestOrResponse, + }; ++use hyper::Method; + use hyper::{StatusCode, Uri}; + use hyper_rustls::{HttpsConnector, HttpsConnectorBuilder}; + use hyper_util::{ +@@ -137,11 +139,15 @@ impl HttpHandler for Handler { + "GET" | "POST" | "HEAD" => { + let original_url = req.uri().clone(); + println!("{req:?}"); +- let Ok(req) = decode_request(req) else { ++ let Ok(mut req) = decode_request(req) else { + let mut res = Response::new("not found".into()); + *res.status_mut() = StatusCode::NOT_FOUND; + return res.into(); + }; ++ let is_head_request = req.method() == "HEAD"; ++ if is_head_request { ++ *req.method_mut() = Method::GET; ++ } + let (info, body) = req.into_parts(); + let Ok(req_body) = body.collect().await.map(|x| x.to_bytes()) + else { +@@ -165,7 +171,7 @@ impl HttpHandler for Handler { + req_body + )])), + ); +- let store_body_info = req.method() != "HEAD"; ++ let store_body_info = true; + let url = process_uri(original_url); + if matches!(forget_regex, Some(x) if x.is_match(&url.to_string())) { + forget = true; +@@ -307,7 +313,20 @@ impl HttpHandler for Handler { + } + } + }); +- Response::from_parts(info, ret_body) ++ if is_head_request { ++ // For HEAD requests, drain the channel ++ // output; otherwise rx will be dropped, ++ // which closes the channel and causes ++ // the tx.poll_ready call above to ++ // return an error ++ let mut stream = ret_body.into_data_stream(); ++ while let Some(_) = stream.next().await { ++ // do nothing ++ } ++ Response::from_parts(info, Body::empty()) ++ } else { ++ Response::from_parts(info, ret_body) ++ } + } else { + // remove hash headers to force the software to download this + // so we get sha256 diff --git a/gnu/packages/rust-apps.scm b/gnu/packages/rust-apps.scm index 5b5a9de115f..a6f3595474a 100644 --- a/gnu/packages/rust-apps.scm +++ b/gnu/packages/rust-apps.scm @@ -1976,7 +1976,8 @@ specified image or color, easing the process of theme creation.") (commit (string-append "v" version)))) (file-name (git-file-name name version)) (sha256 - (base32 "0hbjzf3jb8gpisq3qi5z7wc20hawcgvjwnw2xp80bwq1cj12d3vr")))) + (base32 "0hbjzf3jb8gpisq3qi5z7wc20hawcgvjwnw2xp80bwq1cj12d3vr")) + (patches (search-patches "mitm-cache-head-requests.patch")))) (build-system cargo-build-system) (arguments '(#:install-source? #f)) |
