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 14D401FF13C for ; Thu, 30 Apr 2026 14:51:09 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E7F0C80B8; Thu, 30 Apr 2026 14:51:08 +0200 (CEST) From: Christoph Heiss To: pdm-devel@lists.proxmox.com Subject: [PATCH installer v4 36/40] fetch-answer: http: prefer json over toml for answer format Date: Thu, 30 Apr 2026 14:47:05 +0200 Message-ID: <20260430124712.1614305-37-c.heiss@proxmox.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260430124712.1614305-1-c.heiss@proxmox.com> References: <20260430124712.1614305-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: 1777553335954 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.075 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: 5ARIJ3RMXJ4WZYN74H2PHDGDQQIO4Y6H X-Message-ID-Hash: 5ARIJ3RMXJ4WZYN74H2PHDGDQQIO4Y6H 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: Let the answer server choose which format it prefers to send. JSON may be more convenient to integrate into existing APIs and/or generate automatically as opposed to TOML. E.g. the integrated answer server in Proxmox Datacenter Manager will only support JSON as answer format. For all other usecases, TOML is thus still fully supported. Reviewed-by: Lukas Wagner Signed-off-by: Christoph Heiss --- Changes v3 -> v4: * add patch description 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 031baca..2282af0 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, - )? - .body) + // Prefer JSON answers over TOML by default, but also accept TOML from. + headers.insert( + http::header::ACCEPT, + HeaderValue::from_str("application/json, application/toml;q=0.5")?, + ); + + let http::Response { body, content_type } = + http::post(&answer_url, fingerprint.as_deref(), headers, payload)?; + + if let Some(ct) = content_type + && ct == http::ContentType::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