From bc9111a05fef91e6912d068f3c4d50b4e1d244cd Mon Sep 17 00:00:00 2001 From: Peter Gerber Date: Tue, 23 Jul 2024 18:42:24 +0000 Subject: [PATCH] Use correct timestamp format for Last-Modified header (#365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HTTP uses GMT [1,2] rather than UTC as timezone for timestamps. However, the Last-Modified header used UTC which confused at least wget. Before, UTC was used: $ wget --no-check-certificate -S --spider https://cb_pages_tests.localhost.mock.directory:4430/images/827679288a.jpg ... Last-Modified: Sun, 11 Sep 2022 08:37:42 UTC ... Last-modified header invalid -- time-stamp ignored. ... After, GMT is used: $ wget --no-check-certificate -S --spider https://cb_pages_tests.localhost.mock.directory:4430/images/827679288a.jpg ... Last-Modified: Sun, 11 Sep 2022 08:37:42 GMT ... (no last-modified-header-invalid warning) [1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified [2]: https://www.rfc-editor.org/rfc/rfc9110#name-date-time-formats Fixes #364 --- Whatt I noticed is that the If-Modified-Since header isn't accepted (neither with GMT nor with UTC): ``` $ wget --header "If-Modified-Since: Sun, 11 Sep 2022 08:37:42 GMT" --no-check-certificate -S --spider https://cb_pages_tests.localhost.mock.directory:4430/images/827679288a.jpg Spider mode enabled. Check if remote file exists. --2024-07-15 23:31:41-- https://cb_pages_tests.localhost.mock.directory:4430/images/827679288a.jpg Resolving cb_pages_tests.localhost.mock.directory (cb_pages_tests.localhost.mock.directory)... 127.0.0.1 Connecting to cb_pages_tests.localhost.mock.directory (cb_pages_tests.localhost.mock.directory)|127.0.0.1|:4430... connected. WARNING: The certificate of ‘cb_pages_tests.localhost.mock.directory’ is not trusted. WARNING: The certificate of ‘cb_pages_tests.localhost.mock.directory’ doesn't have a known issuer. HTTP request sent, awaiting response... HTTP/1.1 200 OK Allow: GET, HEAD, OPTIONS Cache-Control: public, max-age=600 Content-Length: 124635 Content-Type: image/jpeg Etag: "073af1960852e2a4ef446202c7974768b9881814" Last-Modified: Sun, 11 Sep 2022 08:37:42 GMT Referrer-Policy: strict-origin-when-cross-origin Server: pages-server Strict-Transport-Security: max-age=63072000; includeSubdomains; preload Date: Mon, 15 Jul 2024 21:31:42 GMT Length: 124635 (122K) [image/jpeg] Remote file exists ``` I would have expected a 304 (Not Modified) rather than a 200 (OK). I assume this is simply not supported and on production 304 is returned by a caching proxy in front of pages-server. Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/365 Reviewed-by: crapStone Co-authored-by: Peter Gerber Co-committed-by: Peter Gerber --- server/upstream/header.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/upstream/header.go b/server/upstream/header.go index 9575a3f..7b85df1 100644 --- a/server/upstream/header.go +++ b/server/upstream/header.go @@ -24,5 +24,5 @@ func (o *Options) setHeader(ctx *context.Context, header http.Header) { } else { ctx.RespWriter.Header().Set(gitea.ContentTypeHeader, mime) } - ctx.RespWriter.Header().Set(headerLastModified, o.BranchTimestamp.In(time.UTC).Format(time.RFC1123)) + ctx.RespWriter.Header().Set(headerLastModified, o.BranchTimestamp.In(time.UTC).Format(http.TimeFormat)) }