diff --git a/twilight-http/src/request/base.rs b/twilight-http/src/request/base.rs index 990ac143b4..fd6039146d 100644 --- a/twilight-http/src/request/base.rs +++ b/twilight-http/src/request/base.rs @@ -90,11 +90,10 @@ impl RequestBuilder { self } - /// Set the multipart form. - #[allow(clippy::missing_const_for_fn)] - pub fn form(mut self, form: Form) -> Self { + /// Set the the multipart form from an existing boundary and buffer. + pub fn multipart(mut self, boundary: [u8; 15], buffer: Vec) -> Self { if let Ok(request) = self.0.as_mut() { - request.form = Some(form); + request.form = Some(Form::from_parts(boundary, buffer)); } self @@ -121,6 +120,15 @@ impl RequestBuilder { self } + /// Set the multipart form. + pub fn form(mut self, form: Form) -> Self { + if let Ok(request) = self.0.as_mut() { + request.form = Some(form); + } + + self + } + /// Whether to use the client's authorization token in the request, if one /// is set. /// diff --git a/twilight-http/src/request/multipart.rs b/twilight-http/src/request/multipart.rs index f2192ad664..b53d6fba7b 100644 --- a/twilight-http/src/request/multipart.rs +++ b/twilight-http/src/request/multipart.rs @@ -19,6 +19,10 @@ impl Form { Self::default() } + pub(crate) const fn from_parts(boundary: [u8; 15], buffer: Vec) -> Self { + Self { boundary, buffer } + } + /// Consume the form, returning the buffer's contents. pub fn build(mut self) -> Vec { self.buffer.extend(Self::BOUNDARY_TERMINATOR); @@ -106,6 +110,10 @@ impl Form { self } + + pub fn into_parts(self) -> ([u8; 15], Vec) { + (self.boundary, self.buffer) + } } impl Default for Form {