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
impl UploadSession
Sourcepub fn new(
content_type: &[u8],
limits: &Limits,
policy: &Policy,
store: &Store,
) -> Result<Self, FormError>
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.
Sourcepub fn push<I: Inspector>(
&mut self,
chunk: &[u8],
inspector: &mut I,
) -> Result<(), FormError>
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.
Sourcepub fn captured_token(&self) -> Option<&str>
pub fn captured_token(&self) -> Option<&str>
The token field’s value, once its part has ended.
Sourcepub fn bytes_seen(&self) -> u64
pub fn bytes_seen(&self) -> u64
Body bytes consumed so far.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UploadSession
impl RefUnwindSafe for UploadSession
impl Send for UploadSession
impl Sync for UploadSession
impl Unpin for UploadSession
impl UnsafeUnpin for UploadSession
impl UnwindSafe for UploadSession
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