fn handle_cache_hit(
    uid: &str,
    gs: &Arc<GlobalState>,
    req: &HttpRequest,
    image: crate::cache::ImageEntry,
) -> HttpResponse {
    // check whether the browser already has the image cached locally
    let etag = header::EntityTag::strong(image.get_checksum_hex());
    let is_client_cached = is_browser_cached(req, &etag);

    // create response object with headers that should be in every response
    let mut res = HttpResponse::build(StatusCode::OK);
    res.append_header(header::ContentType(image.get_mime()))
        .append_header(header::ETag(etag))
        .append_header(("Vary", "Accept-Encoding"));

    // if the image is already cached in the browser, then we can just return the associated code
    // telling the browser that it doesn't need to download anything
    if is_client_cached {
        log::debug!("({}) browser cache HIT", uid);
        return res.status(StatusCode::NOT_MODIFIED).finish();
    }

    // stream the data to the client
    let bytes = image.get_bytes();
    gs.metrics.bytes_up.inc_by(bytes.len() as u64);
    res.body(bytes)
}
/// Handles a cache HIT, returning an HttpResponse that represents that data of the cached image
///
/// Sends the bytes of the cached image to the client unless the client has already proved that
/// they have the image cached locally. Will also set gzip (if enabled by client) and provide
/// necessary headers (like `ETag` and `Vary`)
Handles a cache HIT, returning an HttpResponse that represents that data of the cached image
Sends the bytes of the cached image to the client unless the client has already proved that
they have the image cached locally. Will also set gzip (if enabled by client) and provide
necessary headers (like `ETag` and `Vary`)
Handles a cache HIT returning an HttpResponse that represents that data of the cached image Sends the bytes of the cached image to the client unless the client has already proved that they have the image cached locally . Will also set gzip ( if enabled by client ) and provide necessary headers ( like ` ETag ` and ` Vary ` )
fn handle_cache_hit(
    uid: &str,
    gs: &Arc<GlobalState>,
    req: &HttpRequest,
    image: crate::cache::ImageEntry,
) -> HttpResponse {
    // check whether the browser already has the image cached locally
    let etag = header::EntityTag::strong(image.get_checksum_hex());
    let is_client_cached = is_browser_cached(req, &etag);
    // create response object with headers that should be in every response
    let mut res = HttpResponse::build(StatusCode::OK);
    res.append_header(header::ContentType(image.get_mime()))
        .append_header(header::ETag(etag))
        .append_header(("Vary", "Accept-Encoding"));
    // if the image is already cached in the browser, then we can just return the associated code
    // telling the browser that it doesn't need to download anything
    if is_client_cached {
        log::debug!("({}) browser cache HIT", uid);
        return res.status(StatusCode::NOT_MODIFIED).finish();
    }
    // stream the data to the client
    let bytes = image.get_bytes();
    gs.metrics.bytes_up.inc_by(bytes.len() as u64);
    res.body(bytes)
}
fn handle_cache_hit ( uid : & str , gs : & Arc < GlobalState > , req : & HttpRequest , image : crate :: cache :: ImageEntry , ) -> HttpResponse { // check whether the browser already has the image cached locally let etag = header :: EntityTag :: strong ( image . get_checksum_hex ( ) ) ; let is_client_cached = is_browser_cached ( req , & etag ) ; // create response object with headers that should be in every response let mut res = HttpResponse :: build ( StatusCode :: OK ) ; res . append_header ( header :: ContentType ( image . get_mime ( ) ) ) . append_header ( header :: ETag ( etag ) ) . append_header ( ( " " , " " ) ) ; // if the image is already cached in the browser, then we can just return the associated code // telling the browser that it doesn't need to download anything if is_client_cached { log :: debug ! ( " " uid ) ; return res . status ( StatusCode :: NOT_MODIFIED ) . finish ( ) ; } // stream the data to the client let bytes = image . get_bytes ( ) ; gs . metrics . bytes_up . inc_by ( bytes . len ( ) as u64 ) ; res . body ( bytes ) }
Handles a cache HIT, returning an HttpResponse that represents that data of the cached image
Sends the bytes of the cached image to the client unless the client has already proved that
they have the image cached locally.
Handles a cache HIT returning an HttpResponse that represents that data of the cached image Sends the bytes of the cached image to the client unless the client has already proved that they have the image cached locally .
uid
&str
gs
&Arc<GlobalState>
req
&HttpRequest
image
crate::cache::ImageEntry