mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-31 01:11:23 -05:00
Merge pull request #4809 from wkloucek/dont-cache-web-index-html
don't cache the web index.html
This commit is contained in:
6
changelog/unreleased/fix-static-asset-caching.md
Normal file
6
changelog/unreleased/fix-static-asset-caching.md
Normal file
@@ -0,0 +1,6 @@
|
||||
Bugfix: Disable cache for selected static web assets
|
||||
|
||||
We've disabled caching for some static web assets.
|
||||
Files like the web index.html, oidc-callback.html or similar contain paths to timestamped resources and should not be cached.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/4809
|
||||
@@ -22,18 +22,24 @@ func (f *fileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
upath := path.Clean(path.Join("/", r.URL.Path))
|
||||
r.URL.Path = upath
|
||||
|
||||
asset, err := f.root.Open(upath)
|
||||
if err != nil {
|
||||
disableCache := func() {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
}
|
||||
handleIndex := func() {
|
||||
disableCache()
|
||||
r.URL.Path = "/index.html"
|
||||
f.ServeHTTP(w, r)
|
||||
}
|
||||
asset, err := f.root.Open(upath)
|
||||
if err != nil {
|
||||
handleIndex()
|
||||
return
|
||||
}
|
||||
defer asset.Close()
|
||||
|
||||
s, _ := asset.Stat()
|
||||
if s.IsDir() {
|
||||
r.URL.Path = "/index.html"
|
||||
f.ServeHTTP(w, r)
|
||||
handleIndex()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -43,6 +49,7 @@ func (f *fileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
switch s.Name() {
|
||||
case "index.html", "oidc-callback.html", "oidc-silent-redirect.html":
|
||||
disableCache()
|
||||
_ = withBase(buf, asset, "/")
|
||||
default:
|
||||
_, _ = buf.ReadFrom(asset)
|
||||
|
||||
@@ -3,7 +3,6 @@ package svc
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -90,7 +89,7 @@ func (p Web) getPayload() (payload []byte, err error) {
|
||||
Msg("web config doesn't exist")
|
||||
}
|
||||
|
||||
payload, err = ioutil.ReadFile(p.config.Web.Path)
|
||||
payload, err = os.ReadFile(p.config.Web.Path)
|
||||
|
||||
if err != nil {
|
||||
p.logger.Fatal().
|
||||
@@ -102,7 +101,7 @@ func (p Web) getPayload() (payload []byte, err error) {
|
||||
}
|
||||
|
||||
// Config implements the Service interface.
|
||||
func (p Web) Config(w http.ResponseWriter, r *http.Request) {
|
||||
func (p Web) Config(w http.ResponseWriter, _ *http.Request) {
|
||||
|
||||
payload, err := p.getPayload()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user