handle Last-Modified and Etag
This commit is contained in:
parent
1b5ab5659d
commit
af903b8fee
1 changed files with 10 additions and 0 deletions
10
lib/web.go
10
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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue