Skip to main content

ConditionalRequest

Trait ConditionalRequest 

Source
pub trait ConditionalRequest {
    // Required methods
    fn conditional_headers(&self) -> ConditionalHeaders;
    fn if_none_match(&self) -> Option<ETagList>;
    fn if_match(&self) -> Option<ETagList>;
    fn if_modified_since(&self) -> Option<SystemTime>;
    fn if_unmodified_since(&self) -> Option<SystemTime>;
    fn if_none_match_matches(&self, etag: &ETag) -> bool;
    fn if_match_matches(&self, etag: &ETag) -> bool;
    fn not_modified_since(&self, last_modified: SystemTime) -> bool;
    fn modified_since_precondition(&self, last_modified: SystemTime) -> bool;
    fn evaluate_conditionals(
        &self,
        etag: Option<&ETag>,
        last_modified: Option<SystemTime>,
    ) -> Option<u16>;
}
Expand description

Extension trait for conditional request handling on HttpRequest.

Required Methods§

Source

fn conditional_headers(&self) -> ConditionalHeaders

Get parsed conditional headers from the request.

Source

fn if_none_match(&self) -> Option<ETagList>

Get the If-None-Match header as an ETag list.

Source

fn if_match(&self) -> Option<ETagList>

Get the If-Match header as an ETag list.

Source

fn if_modified_since(&self) -> Option<SystemTime>

Get the If-Modified-Since header as a SystemTime.

Source

fn if_unmodified_since(&self) -> Option<SystemTime>

Get the If-Unmodified-Since header as a SystemTime.

Source

fn if_none_match_matches(&self, etag: &ETag) -> bool

Check if If-None-Match contains a matching ETag (weak comparison).

Returns true if the request should get a 304 Not Modified response.

Source

fn if_match_matches(&self, etag: &ETag) -> bool

Check if If-Match contains a matching ETag (strong comparison).

Returns false if the precondition fails (should return 412).

Source

fn not_modified_since(&self, last_modified: SystemTime) -> bool

Check if If-Modified-Since indicates the resource hasn’t changed.

Source

fn modified_since_precondition(&self, last_modified: SystemTime) -> bool

Check if If-Unmodified-Since precondition fails.

Source

fn evaluate_conditionals( &self, etag: Option<&ETag>, last_modified: Option<SystemTime>, ) -> Option<u16>

Evaluate all conditional headers and return the appropriate response.

Returns:

  • Some(304) if resource is not modified
  • Some(412) if precondition failed
  • None if request should proceed normally

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§