Skip to content

Commit c9732d0

Browse files
authored
Merge pull request duckdb#11 from lnkuiper/last_modified
Try to parse `"Last-Modified"` field, ignore if fails
2 parents 84fb5f0 + 3cb274a commit c9732d0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

extension/httpfs/httpfs.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -772,16 +772,18 @@ void HTTPFileHandle::Initialize(optional_ptr<FileOpener> opener) {
772772
FullDownload(hfs, should_write_cache);
773773
}
774774
if (!res->headers["Last-Modified"].empty()) {
775-
auto result = StrpTimeFormat::Parse("%a, %d %h %Y %T %Z", res->headers["Last-Modified"]);
776-
struct tm tm {};
777-
tm.tm_year = result.data[0] - 1900;
778-
tm.tm_mon = result.data[1] - 1;
779-
tm.tm_mday = result.data[2];
780-
tm.tm_hour = result.data[3];
781-
tm.tm_min = result.data[4];
782-
tm.tm_sec = result.data[5];
783-
tm.tm_isdst = 0;
784-
last_modified = mktime(&tm);
775+
StrpTimeFormat::ParseResult result;
776+
if (StrpTimeFormat::TryParse("%a, %d %h %Y %T %Z", res->headers["Last-Modified"], result)) {
777+
struct tm tm {};
778+
tm.tm_year = result.data[0] - 1900;
779+
tm.tm_mon = result.data[1] - 1;
780+
tm.tm_mday = result.data[2];
781+
tm.tm_hour = result.data[3];
782+
tm.tm_min = result.data[4];
783+
tm.tm_sec = result.data[5];
784+
tm.tm_isdst = 0;
785+
last_modified = mktime(&tm);
786+
}
785787
}
786788

787789
if (should_write_cache) {

0 commit comments

Comments
 (0)