Skip to main content

ExpectHandler

Struct ExpectHandler 

Source
pub struct ExpectHandler {
    pub max_content_length: usize,
    pub required_content_type: Option<String>,
}
Expand description

Handler for HTTP Expect header processing.

Fields§

§max_content_length: usize

Maximum Content-Length to accept (0 = unlimited)

§required_content_type: Option<String>

Required Content-Type prefix (empty = any)

Implementations§

Source§

impl ExpectHandler

Source

pub fn new() -> Self

Create a new ExpectHandler with default settings.

Source

pub fn with_max_content_length(self, max: usize) -> Self

Set the maximum Content-Length to accept.

Source

pub fn with_required_content_type(self, content_type: impl Into<String>) -> Self

Set the required Content-Type prefix.

Source

pub fn check_expect(request: &Request) -> ExpectResult

Check if a request has an Expect header and what it contains.

Returns:

  • ExpectResult::NoExpectation - No Expect header, proceed normally
  • ExpectResult::ExpectsContinue - Expect: 100-continue present
  • ExpectResult::UnknownExpectation - Unknown expectation value
Source

pub fn expects_continue(request: &Request) -> bool

Check if the request expects 100-continue.

This is a convenience method that returns true only for valid Expect: 100-continue headers.

Source

pub fn validate_content_length(&self, request: &Request) -> Result<(), Response>

Validate Content-Length against maximum limit.

Returns Ok(()) if Content-Length is within limits or not specified, or Err(Response) with 413 Payload Too Large if exceeded.

Source

pub fn validate_content_type(&self, request: &Request) -> Result<(), Response>

Validate Content-Type against required type.

Returns Ok(()) if Content-Type matches or no requirement is set, or Err(Response) with 415 Unsupported Media Type if mismatched.

Source

pub fn validate_all(&self, request: &Request) -> Result<(), Response>

Run all configured validations.

Returns Ok(()) if all validations pass, or the first error response.

Source

pub fn expectation_failed(detail: impl Into<String>) -> Response

Create a 417 Expectation Failed response.

Source

pub fn unauthorized(detail: impl Into<String>) -> Response

Create a 401 Unauthorized response.

Source

pub fn forbidden(detail: impl Into<String>) -> Response

Create a 403 Forbidden response.

Source

pub fn payload_too_large(detail: impl Into<String>) -> Response

Create a 413 Payload Too Large response.

Source

pub fn unsupported_media_type(detail: impl Into<String>) -> Response

Create a 415 Unsupported Media Type response.

Trait Implementations§

Source§

impl Clone for ExpectHandler

Source§

fn clone(&self) -> ExpectHandler

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExpectHandler

Source§

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

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

impl Default for ExpectHandler

Source§

fn default() -> ExpectHandler

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ResponseProduces<T> for T