From 024bbb7784efe44b6a8c3c6e5919a3ee2f3f7099 Mon Sep 17 00:00:00 2001 From: Richard Whitehouse Date: Thu, 15 Aug 2024 10:04:59 +0100 Subject: [PATCH] [Rust Server] Improve RFC 13341 compliance for multipart/related (#19355) * [Rust Server] Improve RFC 13341 compliance for multipart/related * Update samples --- .../rust-server/generate-multipart-related.mustache | 5 ++++- .../rust-server/output/multipart-v3/src/client/mod.rs | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/rust-server/generate-multipart-related.mustache b/modules/openapi-generator/src/main/resources/rust-server/generate-multipart-related.mustache index 94ab9db18c2..59b647a4130 100644 --- a/modules/openapi-generator/src/main/resources/rust-server/generate-multipart-related.mustache +++ b/modules/openapi-generator/src/main/resources/rust-server/generate-multipart-related.mustache @@ -30,7 +30,10 @@ {{#-last}} // Write the body into a vec. - let mut body: Vec = vec![]; + // RFC 13341 Section 7.2.1 suggests that the body should begin with a + // CRLF prior to the first boundary. The mime_multipart library doesn't + // do this, so we do it instead. + let mut body: Vec = vec![b'\r', b'\n']; write_multipart(&mut body, &boundary, &body_parts) .expect("Failed to write multipart body"); {{/-last}} diff --git a/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs b/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs index 9f6583b96c4..42a5fbc96b8 100644 --- a/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs +++ b/samples/server/petstore/rust-server/output/multipart-v3/src/client/mod.rs @@ -469,7 +469,10 @@ impl Api for Client where } // Write the body into a vec. - let mut body: Vec = vec![]; + // RFC 13341 Section 7.2.1 suggests that the body should begin with a + // CRLF prior to the first boundary. The mime_multipart library doesn't + // do this, so we do it instead. + let mut body: Vec = vec![b'\r', b'\n']; write_multipart(&mut body, &boundary, &body_parts) .expect("Failed to write multipart body"); @@ -741,7 +744,10 @@ impl Api for Client where } // Write the body into a vec. - let mut body: Vec = vec![]; + // RFC 13341 Section 7.2.1 suggests that the body should begin with a + // CRLF prior to the first boundary. The mime_multipart library doesn't + // do this, so we do it instead. + let mut body: Vec = vec![b'\r', b'\n']; write_multipart(&mut body, &boundary, &body_parts) .expect("Failed to write multipart body");