Skip to main content

UploadSession

Struct UploadSession 

Source
pub struct UploadSession { /* private fields */ }
Available on crate feature fs only.
Expand description

The push-style form for event-driven servers: hand each body chunk to push as reads complete, then finish.

Dropping a session without finish deletes every file it stored. captured_token is available as soon as the token field ends, so the token can be verified while files are still arriving.

§Examples

use form_net::{Limits, NoInspector, Policy, Store, UploadSession};

let store = Store::temp()?;
let body = b"--X\r\nContent-Disposition: form-data; name=a\r\n\r\n1\r\n--X--";
let mut session = UploadSession::new(b"multipart/form-data; boundary=X", &Limits::DEFAULT, &Policy::DEFAULT, &store)?;
for chunk in body.chunks(5) {
    session.push(chunk, &mut NoInspector)?;
}
let upload = session.finish(&mut NoInspector)?;
assert_eq!(upload.field("a"), Some("1"));

Implementations§

Source§

impl UploadSession

Source

pub fn new( content_type: &[u8], limits: &Limits, policy: &Policy, store: &Store, ) -> Result<Self, FormError>

A session for one request body.

§Errors

UnsupportedMediaType and the boundary errors of FormKind::detect; InvalidLimits.

Source

pub fn push<I: Inspector>( &mut self, chunk: &[u8], inspector: &mut I, ) -> Result<(), FormError>

Feeds one chunk; consumes all of it or fails.

§Errors

Every multipart error, Refused, Io, Store, Limit { Disk }; Poisoned after an error.

Source

pub fn finish<I: Inspector>( self, inspector: &mut I, ) -> Result<Upload, FormError>

Ends the body and returns the upload.

§Errors

Syntax { Truncated } if the close delimiter was not seen; as push.

Source

pub fn captured_token(&self) -> Option<&str>

The token field’s value, once its part has ended.

Source

pub fn bytes_seen(&self) -> u64

Body bytes consumed so far.

Trait Implementations§

Source§

impl Debug for UploadSession

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.