Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: object store http header last modified #4834

Merged
merged 5 commits into from
Sep 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions object_store/src/client/header.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@

use crate::path::Path;
use crate::ObjectMeta;
use chrono::{DateTime, Utc};
use chrono::{DateTime, TimeZone, Utc};
use hyper::header::{CONTENT_LENGTH, ETAG, LAST_MODIFIED};
use hyper::HeaderMap;
use snafu::{OptionExt, ResultExt, Snafu};
@@ -53,19 +53,22 @@ pub enum Error {

/// Extracts [`ObjectMeta`] from the provided [`HeaderMap`]
pub fn header_meta(location: &Path, headers: &HeaderMap) -> Result<ObjectMeta, Error> {
let last_modified = headers
.get(LAST_MODIFIED)
.context(MissingLastModifiedSnafu)?;
let last_modified = headers.get(LAST_MODIFIED);
let last_modified = match last_modified {
Some(last_modified) => {
let last_modified = last_modified.to_str().context(BadHeaderSnafu)?;
DateTime::parse_from_rfc2822(last_modified)
.context(InvalidLastModifiedSnafu { last_modified })?
.with_timezone(&Utc)
}
// If the last modified header is missing, assume the object was created at the epoch
None => chrono::Utc.timestamp_nanos(0),
universalmind303 marked this conversation as resolved.
Show resolved Hide resolved
};

let content_length = headers
.get(CONTENT_LENGTH)
.context(MissingContentLengthSnafu)?;

let last_modified = last_modified.to_str().context(BadHeaderSnafu)?;
let last_modified = DateTime::parse_from_rfc2822(last_modified)
.context(InvalidLastModifiedSnafu { last_modified })?
.with_timezone(&Utc);

let content_length = content_length.to_str().context(BadHeaderSnafu)?;
let content_length = content_length
.parse()