From 3864cfce246d2b0d1a61b46578ed39221ebbbd31 Mon Sep 17 00:00:00 2001 From: HugoCasa Date: Thu, 12 Dec 2024 19:18:43 +0100 Subject: [PATCH] feat(backend): handle xml payload as raw_string (#4915) --- backend/windmill-api/src/args.rs | 42 ++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/backend/windmill-api/src/args.rs b/backend/windmill-api/src/args.rs index 5952a5ee5f95d..745f07bc52e91 100644 --- a/backend/windmill-api/src/args.rs +++ b/backend/windmill-api/src/args.rs @@ -36,9 +36,13 @@ impl WebhookArgs { _db: &DB, _w_id: &str, ) -> Result { - return Err(Error::BadRequest(format!( - "Uploading files requires the parquet feature" - ))); + if self.file_req.is_some() { + return Err(Error::BadRequest(format!( + "Uploading files requires the parquet feature" + ))); + } + + Ok(self.args) } #[cfg(feature = "parquet")] @@ -111,6 +115,17 @@ pub struct RequestQuery { pub include_header: Option, } +async fn req_to_string( + req: Request, + _state: &S, +) -> Result { + let bytes = Bytes::from_request(req, _state) + .await + .map_err(IntoResponse::into_response)?; + String::from_utf8(bytes.to_vec()) + .map_err(|e| Error::BadRequest(format!("invalid utf8: {}", e)).into_response()) +} + #[axum::async_trait] impl FromRequest for WebhookArgs where @@ -166,11 +181,7 @@ where .unwrap() .starts_with("application/cloudevents+json") { - let bytes = Bytes::from_request(req, _state) - .await - .map_err(IntoResponse::into_response)?; - let str = String::from_utf8(bytes.to_vec()) - .map_err(|e| Error::BadRequest(format!("invalid utf8: {}", e)).into_response())?; + let str = req_to_string(req, _state).await?; PushArgsOwned::from_ce_json(extra, use_raw, str) .await @@ -184,11 +195,7 @@ where .into_response(), ) } else if content_type.unwrap().starts_with("text/plain") { - let bytes = Bytes::from_request(req, _state) - .await - .map_err(IntoResponse::into_response)?; - let str = String::from_utf8(bytes.to_vec()) - .map_err(|e| Error::BadRequest(format!("invalid utf8: {}", e)).into_response())?; + let str = req_to_string(req, _state).await?; extra.insert("raw_string".to_string(), to_raw_value(&str)); Ok(Self { args: PushArgsOwned { extra: Some(extra), args: HashMap::new() }, @@ -222,6 +229,15 @@ where args: PushArgsOwned { extra: Some(extra), args: payload }, file_req: None, }); + } else if content_type.unwrap().starts_with("application/xml") + || content_type.unwrap().starts_with("text/xml") + { + let str = req_to_string(req, _state).await?; + extra.insert("raw_string".to_string(), to_raw_value(&str)); + Ok(Self { + args: PushArgsOwned { extra: Some(extra), args: HashMap::new() }, + file_req: None, + }) } else { return Ok(Self { args: PushArgsOwned { extra: None, args: HashMap::new() },