pub struct Boundary(/* private fields */);Expand description
A multipart boundary, as RFC 2046 section 5.1.1 defines it: 1 to 70 characters from a restricted set, not ending in a space.
use base_web_multipart::Boundary;
use base_web_media_type::MediaType;
let media_type = MediaType::parse("multipart/form-data; boundary=\"simple boundary\"")?;
let boundary = Boundary::from_media_type(&media_type)?;
assert_eq!(boundary.as_str(), "simple boundary");
let generated = Boundary::generate();
assert_eq!(generated.as_str().len(), 32);
assert_eq!(generated.form_data_media_type().parameter("boundary"), Some(generated.as_str()));Implementations§
Source§impl Boundary
impl Boundary
Sourcepub const LENGTH_LIMIT: usize = 70
pub const LENGTH_LIMIT: usize = 70
The longest boundary RFC 2046 allows.
Sourcepub fn new(text: &str) -> Result<Self, BoundaryError>
pub fn new(text: &str) -> Result<Self, BoundaryError>
A boundary from text.
§Errors
BoundaryError::Invalid when the text is not a boundary RFC 2046 allows.
Sourcepub fn from_media_type(media_type: &MediaType) -> Result<Self, BoundaryError>
pub fn from_media_type(media_type: &MediaType) -> Result<Self, BoundaryError>
The boundary of a multipart media type, from its boundary parameter.
§Errors
BoundaryError::NotMultipart for another type, BoundaryError::Missing when there is no boundary parameter, and BoundaryError::Invalid when it is not a valid boundary.
Sourcepub fn generate() -> Self
pub fn generate() -> Self
A new boundary of 192 random bits from the operating system, written as 32 URL-safe base64 characters, so that content cannot contain it by chance or by an attacker’s design.
§Panics
When the operating system’s random number generator fails, which it does not on supported platforms; the standard library’s hash maps rely on it in the same way.
Sourcepub fn to_media_type(&self, subtype: &str) -> Result<MediaType, MediaTypeError>
pub fn to_media_type(&self, subtype: &str) -> Result<MediaType, MediaTypeError>
The media type multipart/{subtype} with this boundary as its parameter, such as multipart/mixed; boundary=....
§Errors
When the subtype is not a token, or is a wildcard.
Sourcepub fn form_data_media_type(&self) -> MediaType
pub fn form_data_media_type(&self) -> MediaType
The media type multipart/form-data with this boundary as its parameter.