From af903b8fee606c6e5754aab0010d7e80e4a4ec8f Mon Sep 17 00:00:00 2001 From: Ronmi Ren Date: Tue, 7 Jan 2025 21:41:48 +0800 Subject: [PATCH] handle Last-Modified and Etag --- lib/web.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/web.go b/lib/web.go index d2d225b..842cab3 100644 --- a/lib/web.go +++ b/lib/web.go @@ -54,6 +54,16 @@ func (f *Forgejo) handle(w http.ResponseWriter, r *http.Request) { trySet(w.Header(), "Etag", info.ETag) trySet(w.Header(), "Last-Modified", info.LastModified) trySet(w.Header(), "Content-Length", info.Size) + + if r.Header.Get("If-None-Match") == info.ETag { + w.WriteHeader(http.StatusNotModified) + return + } + if r.Header.Get("If-Modified-Since") == info.LastModified { + w.WriteHeader(http.StatusNotModified) + return + } + w.WriteHeader(http.StatusOK) io.Copy(w, content) }