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: usizeMaximum Content-Length to accept (0 = unlimited)
required_content_type: Option<String>Required Content-Type prefix (empty = any)
Implementations§
Source§impl ExpectHandler
impl ExpectHandler
Sourcepub fn with_max_content_length(self, max: usize) -> Self
pub fn with_max_content_length(self, max: usize) -> Self
Set the maximum Content-Length to accept.
Sourcepub fn with_required_content_type(self, content_type: impl Into<String>) -> Self
pub fn with_required_content_type(self, content_type: impl Into<String>) -> Self
Set the required Content-Type prefix.
Sourcepub fn check_expect(request: &Request) -> ExpectResult
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 normallyExpectResult::ExpectsContinue- Expect: 100-continue presentExpectResult::UnknownExpectation- Unknown expectation value
Sourcepub fn expects_continue(request: &Request) -> bool
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.
Sourcepub fn validate_content_length(&self, request: &Request) -> Result<(), Response>
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.
Sourcepub fn validate_content_type(&self, request: &Request) -> Result<(), Response>
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.
Sourcepub fn validate_all(&self, request: &Request) -> Result<(), Response>
pub fn validate_all(&self, request: &Request) -> Result<(), Response>
Run all configured validations.
Returns Ok(()) if all validations pass, or the first error response.
Sourcepub fn expectation_failed(detail: impl Into<String>) -> Response
pub fn expectation_failed(detail: impl Into<String>) -> Response
Create a 417 Expectation Failed response.
Create a 401 Unauthorized response.
Sourcepub fn payload_too_large(detail: impl Into<String>) -> Response
pub fn payload_too_large(detail: impl Into<String>) -> Response
Create a 413 Payload Too Large response.
Sourcepub fn unsupported_media_type(detail: impl Into<String>) -> Response
pub fn unsupported_media_type(detail: impl Into<String>) -> Response
Create a 415 Unsupported Media Type response.
Trait Implementations§
Source§impl Clone for ExpectHandler
impl Clone for ExpectHandler
Source§fn clone(&self) -> ExpectHandler
fn clone(&self) -> ExpectHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more