pub struct Etag { /* private fields */ }Expand description
§Etag and If-None-Match header handler
Trillium handler that provides an outbound etag header
after other handlers have been run, and if the request includes an
if-none-match
header, compares these values and sends a
304 not modified status,
omitting the response body.
The conditional comparison applies only to GET and HEAD requests with successful
responses; responses to other methods, error responses, and redirects pass through unchanged,
and only successful responses receive a generated etag. Enforcing preconditions on
state-changing requests — refusing the write with 412 Precondition Failed — requires
knowing the resource’s entity tag before the write runs, so it is up to the application.
§Streamed bodies
Note that this handler does not currently provide an etag trailer for streamed bodies, but may do so in the future.
§Strong vs weak comparison
Etags can be compared using a strong method or a weak
method. By default, this handler allows weak comparison. To change
this setting, construct your handler with Etag::new().strong().
See etag::EntityTag
for further documentation.
Implementations§
Trait Implementations§
impl Copy for Etag
Source§impl Handler for Etag
impl Handler for Etag
Source§async fn run(&self, conn: Conn) -> Conn
async fn run(&self, conn: Conn) -> Conn
Source§async fn before_send(&self, conn: Conn) -> Conn
async fn before_send(&self, conn: Conn) -> Conn
Source§fn init(&mut self, info: &mut Info) -> impl Future<Output = ()> + Send
fn init(&mut self, info: &mut Info) -> impl Future<Output = ()> + Send
Source§fn has_upgrade(&self, upgrade: &Upgrade) -> bool
fn has_upgrade(&self, upgrade: &Upgrade) -> bool
Handler::upgrade. The first handler that responds true to this will receive
ownership of the trillium::Upgrade in a subsequent call to
Handler::upgradeSource§fn upgrade(&self, upgrade: Upgrade) -> impl Future<Output = ()> + Send
fn upgrade(&self, upgrade: Upgrade) -> impl Future<Output = ()> + Send
Handler::has_upgrade and will
only be called once for this upgrade. There is no return value, and this function takes
exclusive ownership of the underlying transport once this is called. You can downcast
the transport to whatever the source transport type is and perform any non-http protocol
communication that has been negotiated. You probably don’t want this unless you’re
implementing something like websockets. Please note that for many transports such as
TcpStreams, dropping the transport (and therefore the Upgrade) will hang up /
disconnect.