Skip to content

Commit

Permalink
Tries to fix IPFS Cache-Control headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Dec 11, 2024
1 parent c43342b commit 1fce603
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions backend/mttnet/filemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func (fm *FileManager) GetFile(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Cache-Control, ETag")
w.Header().Set("Access-Control-Allow-Methods", "OPTIONS, GET")

if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}

if r.Method != "GET" {
w.WriteHeader(http.StatusMethodNotAllowed)
fmt.Fprintf(w, "Only GET method is supported.")
Expand Down Expand Up @@ -137,10 +142,11 @@ func (fm *FileManager) GetFile(w http.ResponseWriter, r *http.Request) {
return
}
}

w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("ETag", cidStr)
w.Header().Set("Cache-Control", "public, max-age=29030400, immutable")
w.WriteHeader(http.StatusOK)
w.Header().Add("Content-Type", "application/octet-stream")
w.Header().Add("ETag", cidStr)
w.Header().Add("Cache-Control", "public, max-age=29030400, immutable")
_, _ = w.Write(buf.Bytes())
}

Expand Down

0 comments on commit 1fce603

Please sign in to comment.