From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 467D31FF137 for ; Tue, 14 Apr 2026 14:12:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 79C4316D9A; Tue, 14 Apr 2026 14:13:42 +0200 (CEST) Content-Type: text/plain; charset=UTF-8 Date: Tue, 14 Apr 2026 14:13:37 +0200 Message-Id: To: "Christoph Heiss" , Subject: Re: [PATCH installer v3 26/38] common: http: allow passing custom headers to post() From: "Lukas Wagner" Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 X-Mailer: aerc 0.21.0-0-g5549850facc2-dirty References: <20260403165437.2166551-1-c.heiss@proxmox.com> <20260403165437.2166551-27-c.heiss@proxmox.com> In-Reply-To: <20260403165437.2166551-27-c.heiss@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1776168741713 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.053 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: NW2YVS6ZH7PNWDFV466V3THWRP5OIPVM X-Message-ID-Hash: NW2YVS6ZH7PNWDFV466V3THWRP5OIPVM X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On Fri Apr 3, 2026 at 6:53 PM CEST, Christoph Heiss wrote: > Add an additional parameter to allow passing in additional headers. > > No functional changes. > > Signed-off-by: Christoph Heiss [...] > +/// > +/// # Returns > +/// > +/// A tuple containing > +/// * The body contents, as returned by the server > +/// * The content type of the response, if set in the response headers > +pub fn post( > + url: &str, > + fingerprint: Option<&str>, > + headers: header::HeaderMap, > + payload: String, > +) -> Result<(String, Option)> { Maybe a custom type for the response would be a bit nicer here, instead of the tuple? > // TODO: read_to_string limits the size to 10 MB, should be increase= that? > - Ok(build_agent(fingerprint)? > + > + let mut request =3D build_agent(fingerprint)? > .post(url) > - .header("Content-Type", "application/json; charset=3Dutf-8") > - .send(&payload)? > - .body_mut() > - .read_to_string()?) > + .header("Content-Type", "application/json; charset=3Dutf-8"); > + > + for (name, value) in headers.iter() { > + request =3D request.header(name, value); > + } > + > + let mut response =3D request.send(&payload)?; > + let content_type =3D response > + .headers() > + .get(header::CONTENT_TYPE) > + .and_then(|h| h.to_str().ok()) > + .map(|s| s.to_owned()); > + > + Ok((response.body_mut().read_to_string()?, content_type)) > } > =20 [...] > =20 > /// Information about the system boot status. > #[derive(Serialize)] > @@ -536,11 +537,7 @@ impl PostHookInfo { > .map(|v| { > // /proc/version: "Linux version 6.17.2-1-pve (...) #1 S= MP ..." > // extract everything after the second space > - v.splitn(3, ' ') > - .nth(2) > - .unwrap_or("") > - .trim() > - .to_owned() > + v.splitn(3, ' ').nth(2).unwrap_or("").trim().to_owned() > }) > .unwrap_or_default(); > =20 > @@ -640,16 +637,12 @@ impl PostHookInfo { > sockets.insert(value); > } > // x86: "flags", ARM64: "Features" > - Some((key, value)) > - if key.trim() =3D=3D "flags" > - || key.trim() =3D=3D "Features" =3D> > - { > + Some((key, value)) if key.trim() =3D=3D "flags" || key.t= rim() =3D=3D "Features" =3D> { > value.trim().clone_into(&mut result.flags); > } > // x86: "model name", ARM64: "CPU implementer" > Some((key, value)) > - if key.trim() =3D=3D "model name" > - || key.trim() =3D=3D "CPU implementer" =3D> > + if key.trim() =3D=3D "model name" || key.trim() =3D= =3D "CPU implementer" =3D> > { These seem to be unrelated changes caused by your auto-formatter, maybe split these out into a separate patch? > if result.model.is_empty() { > value.trim().clone_into(&mut result.model); > @@ -727,9 +720,10 @@ fn do_main() -> Result<()> { > ); > } > =20 > - proxmox_installer_common::http::post( > + http::post( > url, > cert_fingerprint.as_deref(), > + HeaderMap::new(), > serde_json::to_string(&info)?, > )?; > } else { Looks good in general, my suggestion with the custom type is a mere suggestion, not a requirement. Reviewed-by: Lukas Wagner