Skip to main content

vary_accept_encoding

Function vary_accept_encoding 

Source
pub async fn vary_accept_encoding(
    req: ServiceRequest,
    next: Next<impl MessageBody>,
) -> Result<ServiceResponse<impl MessageBody>, Error>
Expand description

Middleware making every response Compress would compress for a client accepting it say Vary: accept-encoding, also when sent as it is.

Compress says it only on what it compresses. Sending the same response as it is, to a client without Accept-Encoding (a crawler, curl), it says nothing, and a cache on the way (nginx, a CDN) gives that version to everyone. vertigo serve uses it, a back-end with its own Compress wraps it around that one, i.e. after it:

use actix_web::{App, middleware::{Compress, from_fn}};
use vertigo_cli::serve::vary_accept_encoding;

let app = App::new()
    .wrap(Compress::default())
    .wrap(from_fn(vary_accept_encoding));