#[non_exhaustive]pub enum FormKind {
Urlencoded,
Multipart(Boundary),
}Expand description
Which form encoding a request body uses.
§Examples
use form_net::{FormError, FormKind};
match FormKind::detect(b"multipart/form-data; boundary=----WebKitFormBoundaryx7Y")? {
FormKind::Urlencoded => { /* parse_urlencoded */ }
FormKind::Multipart(boundary) => assert_eq!(boundary.as_bytes(), b"----WebKitFormBoundaryx7Y"),
_ => return Err(FormError::UnsupportedMediaType),
}
assert_eq!(FormKind::detect(b"Application/X-WWW-Form-Urlencoded; charset=UTF-8")?, FormKind::Urlencoded);
assert_eq!(FormKind::detect(b"text/plain"), Err(FormError::UnsupportedMediaType));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Urlencoded
application/x-www-form-urlencoded.
Multipart(Boundary)
multipart/form-data, with its validated boundary.
Implementations§
Source§impl FormKind
impl FormKind
Sourcepub fn detect(content_type: &[u8]) -> Result<FormKind, FormError>
pub fn detect(content_type: &[u8]) -> Result<FormKind, FormError>
Reads a request’s Content-Type value. A pure function of the header
bytes; it never looks at the body.
application/x-www-form-urlencoded is accepted with any parameters
except a charset other than UTF-8 or US-ASCII. multipart/form-data
needs exactly one valid boundary. Everything else, including
text/plain, is UnsupportedMediaType. A repeated parameter is
refused.
§Errors
UnsupportedMediaType; Syntax { InvalidContentType | MissingBoundary | DuplicateBoundary | InvalidBoundary }; Encoding { UnsupportedCharset }.
§Examples
use form_net::{FormError, FormKind, SyntaxError};
assert!(matches!(
FormKind::detect(b"multipart/form-data; boundary=a; boundary=b"),
Err(FormError::Syntax { reason: SyntaxError::DuplicateBoundary, .. })
));Trait Implementations§
impl Copy for FormKind
impl Eq for FormKind
impl StructuralPartialEq for FormKind
Auto Trait Implementations§
impl Freeze for FormKind
impl RefUnwindSafe for FormKind
impl Send for FormKind
impl Sync for FormKind
impl Unpin for FormKind
impl UnsafeUnpin for FormKind
impl UnwindSafe for FormKind
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more