mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-09 00:59:02 +03:00
feat: implements remaining http cache conditionalss (#407)
* implements remaining http conditionals * computed etag is not optional
This commit is contained in:
@@ -15,8 +15,8 @@ use chrono::{LocalResult, TimeZone, Utc};
|
||||
use futures_util::{pin_mut, TryStreamExt};
|
||||
use headers::{
|
||||
AcceptRanges, AccessControlAllowCredentials, AccessControlAllowOrigin, CacheControl,
|
||||
ContentLength, ContentType, ETag, HeaderMap, HeaderMapExt, IfModifiedSince, IfNoneMatch,
|
||||
IfRange, LastModified, Range,
|
||||
ContentLength, ContentType, ETag, HeaderMap, HeaderMapExt, IfMatch, IfModifiedSince,
|
||||
IfNoneMatch, IfRange, IfUnmodifiedSince, LastModified, Range,
|
||||
};
|
||||
use http_body_util::{combinators::BoxBody, BodyExt, StreamBody};
|
||||
use hyper::body::Frame;
|
||||
@@ -796,18 +796,29 @@ impl Server {
|
||||
let size = meta.len();
|
||||
let mut use_range = true;
|
||||
if let Some((etag, last_modified)) = extract_cache_headers(&meta) {
|
||||
let cached = {
|
||||
if let Some(if_none_match) = headers.typed_get::<IfNoneMatch>() {
|
||||
!if_none_match.precondition_passes(&etag)
|
||||
} else if let Some(if_modified_since) = headers.typed_get::<IfModifiedSince>() {
|
||||
!if_modified_since.is_modified(last_modified.into())
|
||||
} else {
|
||||
false
|
||||
if let Some(if_unmodified_since) = headers.typed_get::<IfUnmodifiedSince>() {
|
||||
if !if_unmodified_since.precondition_passes(last_modified.into()) {
|
||||
*res.status_mut() = StatusCode::PRECONDITION_FAILED;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
if let Some(if_match) = headers.typed_get::<IfMatch>() {
|
||||
if !if_match.precondition_passes(&etag) {
|
||||
*res.status_mut() = StatusCode::PRECONDITION_FAILED;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
if let Some(if_modified_since) = headers.typed_get::<IfModifiedSince>() {
|
||||
if !if_modified_since.is_modified(last_modified.into()) {
|
||||
*res.status_mut() = StatusCode::NOT_MODIFIED;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
if let Some(if_none_match) = headers.typed_get::<IfNoneMatch>() {
|
||||
if !if_none_match.precondition_passes(&etag) {
|
||||
*res.status_mut() = StatusCode::NOT_MODIFIED;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
if cached {
|
||||
*res.status_mut() = StatusCode::NOT_MODIFIED;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
res.headers_mut().typed_insert(last_modified);
|
||||
|
||||
Reference in New Issue
Block a user