1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-12-18 14:16:47 +00:00

minor syntax update

This commit is contained in:
axon-q 2018-06-14 14:23:19 +00:00
parent 2e883cf44f
commit 7f113ef9e4

View file

@ -200,33 +200,35 @@ where
return Ok(middleware::Response::Done(res)); return Ok(middleware::Response::Done(res));
} }
let e = if let Body::Binary(b) = res.body() { // This double match is because we can't do the return in the first match
Some(EntityTag::strong(self.hasher.hash(b.as_ref()))) // as res is still borrowed
} else { let etag = match match res.body() {
None Body::Binary(b) => Some(EntityTag::strong(self.hasher.hash(b.as_ref()))),
_ => None,
} {
Some(tag) => tag,
None => return Ok(middleware::Response::Done(res)),
}; };
if let Some(etag) = e { if !none_match(&etag, req) {
if !none_match(&etag, req) { let mut not_modified =
let mut not_modified = HttpResponse::NotModified().set(header::ETag(etag)).finish();
HttpResponse::NotModified().set(header::ETag(etag)).finish();
// RFC 7232 requires copying over these headers: // RFC 7232 requires copying over these headers:
copy_header(header::CACHE_CONTROL, &res, &mut not_modified); copy_header(header::CACHE_CONTROL, &res, &mut not_modified);
copy_header(header::CONTENT_LOCATION, &res, &mut not_modified); copy_header(header::CONTENT_LOCATION, &res, &mut not_modified);
copy_header(header::DATE, &res, &mut not_modified); copy_header(header::DATE, &res, &mut not_modified);
copy_header(header::EXPIRES, &res, &mut not_modified); copy_header(header::EXPIRES, &res, &mut not_modified);
copy_header(header::VARY, &res, &mut not_modified); copy_header(header::VARY, &res, &mut not_modified);
return Ok(middleware::Response::Done(not_modified)); return Ok(middleware::Response::Done(not_modified));
}
etag.to_string()
.parse::<header::HeaderValue>()
.map(|v| {
res.headers_mut().insert(header::ETAG, v);
})
.unwrap_or(());
} }
etag.to_string()
.parse::<header::HeaderValue>()
.map(|v| {
res.headers_mut().insert(header::ETAG, v);
})
.unwrap_or(());
Ok(middleware::Response::Done(res)) Ok(middleware::Response::Done(res))
} }
} }