Re: [PATCH installer v3 26/38] common: http: allow passing custom headers to post()

Lukas Wagner
2026-04-14T12:12:53Z

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 <c.heiss@proxmox.com>

[...]

> +///
> +/// # 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<String>)> {

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 = build_agent(fingerprint)?
> .post(url)
> - .header("Content-Type", "application/json; charset=utf-8")
> - .send(&payload)?
> - .body_mut()
> - .read_to_string()?)
> + .header("Content-Type", "application/json; charset=utf-8");
> +
> + for (name, value) in headers.iter() {
> + request = request.header(name, value);
> + }
> +
> + let mut response = request.send(&payload)?;
> + let content_type = 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))
> }
>

[...]

>
> /// 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 SMP ..."
> // 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();
>
> @@ -640,16 +637,12 @@ impl PostHookInfo {
> sockets.insert(value);
> }
> // x86: "flags", ARM64: "Features"
> - Some((key, value))
> - if key.trim() == "flags"
> - || key.trim() == "Features" =>
> - {
> + Some((key, value)) if key.trim() == "flags" || key.trim() == "Features" => {
> value.trim().clone_into(&mut result.flags);
> }
> // x86: "model name", ARM64: "CPU implementer"
> Some((key, value))
> - if key.trim() == "model name"
> - || key.trim() == "CPU implementer" =>
> + if key.trim() == "model name" || key.trim() == "CPU implementer" =>
> {

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<()> {
> );
> }
>
> - 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 <l.wagner@proxmox.com>