From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id D201C1FF13E for ; Fri, 03 Apr 2026 18:57:21 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 9AEA18F6B; Fri, 3 Apr 2026 18:57:52 +0200 (CEST) From: Christoph Heiss To: pdm-devel@lists.proxmox.com Subject: [PATCH installer v3 35/38] fetch-answer: http: prefer json over toml for answer format Date: Fri, 3 Apr 2026 18:54:07 +0200 Message-ID: <20260403165437.2166551-36-c.heiss@proxmox.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260403165437.2166551-1-c.heiss@proxmox.com> References: <20260403165437.2166551-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1775235406620 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.068 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 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: OROXRA5CFQMQ5RDMJEMYPBU4XM4F5TLL X-Message-ID-Hash: OROXRA5CFQMQ5RDMJEMYPBU4XM4F5TLL X-MailFrom: c.heiss@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: Signed-off-by: Christoph Heiss --- Changes v2 -> v3: * new patch .../src/fetch_plugins/http.rs | 43 +++++++++++++++---- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/proxmox-fetch-answer/src/fetch_plugins/http.rs b/proxmox-fetch-answer/src/fetch_plugins/http.rs index 9e5a87a..6508721 100644 --- a/proxmox-fetch-answer/src/fetch_plugins/http.rs +++ b/proxmox-fetch-answer/src/fetch_plugins/http.rs @@ -6,9 +6,14 @@ use std::{ }; use proxmox_auto_installer::{sysinfo, utils::HttpOptions}; -use proxmox_installer_common::http::{self, header::HeaderMap, +use proxmox_installer_common::http::{ + self, + header::{HeaderMap, HeaderValue}, +}; +use proxmox_installer_types::answer::{ + AutoInstallerConfig, + fetch::{AnswerFetchData, AnswerFetchDataSchema}, }; -use proxmox_installer_types::answer::fetch::{AnswerFetchData, AnswerFetchDataSchema}; static ANSWER_URL_SUBDOMAIN: &str = "proxmox-auto-installer"; static ANSWER_CERT_FP_SUBDOMAIN: &str = "proxmox-auto-installer-cert-fingerprint"; @@ -40,6 +45,14 @@ impl FetchFromHTTP { /// needs to be either trusted by the root certs or a SHA256 fingerprint needs to be provided. /// The SHA256 SSL fingerprint can either be defined in the ISO, as DHCP option, or as DNS TXT /// record. If provided, the fingerprint provided in the ISO has preference. + /// + /// # Parameters + /// + /// * `settings` - HTTP fetch options from the baked-in auto-installer configuration. + /// + /// # Returns + /// + /// The TOML-formatted answer retrieved from the given server. pub fn get_answer(settings: &HttpOptions) -> Result { let mut fingerprint: Option = match settings.cert_fingerprint.clone() { Some(fp) => { @@ -74,14 +87,26 @@ impl FetchFromHTTP { })?; info!("Sending POST request to '{answer_url}'."); + let mut headers = HeaderMap::new(); - Ok(http::post( - &answer_url, - fingerprint.as_deref(), - HeaderMap::new(), - payload, - )? - .0) + // Prefer JSON answers over TOML. The TOML path might be deprecated in the future. + headers.insert( + http::header::ACCEPT, + HeaderValue::from_str("application/json, application/toml;q=0.5")?, + ); + + let (body, content_type) = + http::post(&answer_url, fingerprint.as_deref(), headers, payload)?; + + if let Some(ct) = content_type + && ct.starts_with("application/json") + { + // do a round-trip with serde into TOML, if we received JSON from the server + let answer: AutoInstallerConfig = serde_json::from_str(&body)?; + Ok(toml::to_string(&answer)?) + } else { + Ok(body) + } } /// Fetches search domain from resolv.conf file -- 2.53.0