pub struct MultipartBuilder { /* private fields */ }Expand description
Builder for multipart/form-data bodies per RFC 7578.
§Example
use oxihttp_core::multipart::MultipartBuilder;
let builder = MultipartBuilder::new()
.add_text("username", "alice")
.add_file("avatar", "pic.png", "image/png", b"PNG\r\n".as_ref());
let content_type = builder.content_type();
let body_bytes = builder.build();Implementations§
Source§impl MultipartBuilder
impl MultipartBuilder
Sourcepub fn content_type(&self) -> String
pub fn content_type(&self) -> String
Return the full Content-Type header value including the boundary parameter.
Set this as the Content-Type header when sending the body.
Sourcepub fn add_file(
self,
name: &str,
filename: &str,
content_type: &str,
body: impl Into<Bytes>,
) -> Self
pub fn add_file( self, name: &str, filename: &str, content_type: &str, body: impl Into<Bytes>, ) -> Self
Add a file/binary part.
Sourcepub fn build(self) -> Bytes
pub fn build(self) -> Bytes
Serialise to a Bytes buffer containing the complete multipart wire format.
Automatically handles boundary collision: if the boundary string occurs literally inside any part body, a numeric suffix is appended and the check repeats until the boundary is guaranteed unique across all part bodies.
Note: the uniqueness check searches for the bare boundary string (conservative —
no false negatives). The actual wire delimiter is --<boundary>, but matching
the bare string is safe because any occurrence of the bare string would also
produce a collision in the delimiter form.
Trait Implementations§
Source§impl Clone for MultipartBuilder
impl Clone for MultipartBuilder
Source§fn clone(&self) -> MultipartBuilder
fn clone(&self) -> MultipartBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more