pub struct PartHead<'p> { /* private fields */ }Expand description
The validated header block of one part, borrowed.
A head is only produced after every header budget and rule passed.
§Examples
let body = b"--X\r\nContent-Disposition: form-data; name=doc; filename=a.pdf\r\nContent-Type: application/pdf\r\n\r\n%PDF\r\n--X--";
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
assert_eq!(head.name(), "doc");
assert!(head.is_file());
assert!(head.content_type().unwrap().is("application", "pdf"));Implementations§
Source§impl<'p> PartHead<'p>
impl<'p> PartHead<'p>
Sourcepub const fn index(&self) -> u32
pub const fn index(&self) -> u32
The part index, from 0, in body order.
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
assert_eq!(head.index(), 0);Sourcepub const fn name(&self) -> &'p str
pub const fn name(&self) -> &'p str
The field name, with %0A, %0D, %22 decoded to LF, CR, " (no
other escape is decoded). Always valid UTF-8 and never empty.
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
assert_eq!(head.name(), "a\"b");Sourcepub const fn name_raw(&self) -> &'p [u8] ⓘ
pub const fn name_raw(&self) -> &'p [u8] ⓘ
The field name as sent.
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
assert_eq!(head.name_raw(), b"a%22b");Sourcepub const fn kind(&self) -> PartKind
pub const fn kind(&self) -> PartKind
Field or file.
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
assert_eq!(head.kind(), PartKind::File);Sourcepub const fn is_file(&self) -> bool
pub const fn is_file(&self) -> bool
Whether this is a file part.
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
assert!(!head.is_file());Sourcepub const fn filename(&self) -> Option<FileName<'p>>
pub const fn filename(&self) -> Option<FileName<'p>>
The client’s file name, for file parts.
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
assert_eq!(head.filename().unwrap().raw(), b"a.txt");Sourcepub fn content_type(&self) -> Option<ContentType<'p>>
pub fn content_type(&self) -> Option<ContentType<'p>>
The declared Content-Type: a hint, never trusted.
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
assert!(head.content_type().unwrap().is("text", "plain"));Sourcepub const fn charset(&self) -> Charset
pub const fn charset(&self) -> Charset
The part’s own charset parameter (Unspecified when absent).
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
assert_eq!(head.charset(), Charset::Ascii);Sourcepub fn headers(&self) -> Headers<'p> ⓘ
pub fn headers(&self) -> Headers<'p> ⓘ
Every header line, in order, as raw (name, value) bytes.
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
let (name, value) = head.headers().nth(1).unwrap();
assert_eq!((name, value), (&b"Content-Type"[..], &b"text/plain"[..]));Sourcepub const fn header_bytes(&self) -> u32
pub const fn header_bytes(&self) -> u32
The size of the header block, the final CRLF CRLF included.
§Examples
let MultipartEvent::PartStart(head) = parser.parse(body, true)?.event else { unreachable!() };
// The block ends with the blank line.
let block = "Content-Disposition: form-data; name=a\r\n\r\n";
assert_eq!(head.header_bytes() as usize, block.len());Trait Implementations§
Auto Trait Implementations§
impl<'p> Forget for PartHead<'p>
impl<'p> Freeze for PartHead<'p>
impl<'p> Move for PartHead<'p>
impl<'p> RefUnwindSafe for PartHead<'p>
impl<'p> Send for PartHead<'p>
impl<'p> Sync for PartHead<'p>
impl<'p> Unpin for PartHead<'p>
impl<'p> UnsafeUnpin for PartHead<'p>
impl<'p> UnwindSafe for PartHead<'p>
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