Struct Intercept

Source
pub struct Intercept {
    pub temp_dir_path: Option<PathBuf>,
    pub file_size_limit: u64,
    pub file_count_limit: u32,
    pub limit_behavior: LimitBehavior,
}
Expand description

A BeforeMiddleware for Iron which will intercept and read-out multipart requests and store the result in the request.

Successful reads will be placed in the extensions: TypeMap field of iron::Request as an Entries instance (as both key-type and value):

extern crate iron;
extern crate qiniu_multipart;

use iron::prelude::*;

use qiniu_multipart::server::Entries;
use qiniu_multipart::server::iron::Intercept;

fn main() {
    let mut chain = Chain::new(|req: &mut Request| if let Some(entries) =
        req.extensions.get::<Entries>() {

        Ok(Response::with(format!("{:?}", entries)))
    } else {
        Ok(Response::with("Not a multipart request"))
    });

    chain.link_before(Intercept::default());

    Iron::new(chain).http("localhost:80").unwrap();
}

Any errors during which occur during reading will be passed on as IronError.

Fields§

§temp_dir_path: Option<PathBuf>

The parent directory for all temporary directories created by this middleware. Will be created if it doesn’t exist (lazy).

If omitted, uses the OS temporary directory.

Default value: None.

§file_size_limit: u64

The size limit of uploaded files, in bytes.

Files which exceed this size will be rejected. See the limit_behavior field for more info.

Default value: DEFAULT_FILE_SIZE_LIMIT

§file_count_limit: u32

The limit on the number of files which will be saved from the request. Requests which exceed this count will be rejected.

Default value: DEFAULT_FILE_COUNT_LIMT

§limit_behavior: LimitBehavior

What to do when a file count or size limit has been exceeded.

See LimitBehavior for more info.

Implementations§

Source§

impl Intercept

Source

pub fn temp_dir_path<P: Into<PathBuf>>(self, path: P) -> Self

Set the temp_dir_path for this middleware.

Source

pub fn file_size_limit(self, limit: u64) -> Self

Set the file_size_limit for this middleware.

Source

pub fn file_count_limit(self, limit: u32) -> Self

Set the file_count_limit for this middleware.

Source

pub fn limit_behavior(self, behavior: LimitBehavior) -> Self

Set the limit_behavior for this middleware.

Trait Implementations§

Source§

impl BeforeMiddleware for Intercept

Source§

fn before(&self, req: &mut IronRequest<'_, '_>) -> IronResult<()>

Do whatever work this middleware should do with a Request object.
Source§

fn catch( &self, _: &mut Request<'_, '_>, err: IronError, ) -> Result<(), IronError>

Respond to an error thrown by a previous BeforeMiddleware. Read more
Source§

impl Debug for Intercept

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Intercept

Source§

fn default() -> Self

Returns the “default value” for a type. 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
Source§

impl<T> DebugAny for T
where T: Any + Debug,

Source§

impl<T> UnsafeAny for T
where T: Any,