Hopefully fixed the caching problem with random
This commit is contained in:
@@ -100,15 +100,20 @@ type SongData struct {
|
||||
}
|
||||
|
||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
(w).Header().Set("Access-Control-Allow-Origin", "*")
|
||||
setCorsAndNoCacheHeaders(&w, r)
|
||||
|
||||
if r.URL.Path == "/version" {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
testf()
|
||||
|
||||
data := VersionData{Version: "2.0.1",
|
||||
Changelog: "Fixed CORS",
|
||||
data := VersionData{Version: "2.0.2",
|
||||
Changelog: "Hopefully fixed the caching problem with random.",
|
||||
History: []VersionData{
|
||||
{
|
||||
Version: "2.0.1",
|
||||
Changelog: "Fixed CORS",
|
||||
},
|
||||
{
|
||||
Version: "2.0.0",
|
||||
Changelog: "Rebuilt the application in Go.",
|
||||
@@ -165,3 +170,27 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func setCorsAndNoCacheHeaders(w *http.ResponseWriter, r *http.Request) {
|
||||
var etagHeaders = []string{
|
||||
"ETag",
|
||||
"If-Modified-Since",
|
||||
"If-Match",
|
||||
"If-None-Match",
|
||||
"If-Range",
|
||||
"If-Unmodified-Since",
|
||||
}
|
||||
|
||||
(*w).Header().Set("Expires", "Tue, 03 Jul 2001 06:00:00 GMT")
|
||||
(*w).Header().Set("Last-Modified", time.Now().String()+" GMT")
|
||||
(*w).Header().Set("Cache-Control", "no-cache, no-store, private, max-age=0")
|
||||
(*w).Header().Set("Pragma", "no-cache")
|
||||
(*w).Header().Set("X-Accel-Expires", "0")
|
||||
(*w).Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
||||
for _, v := range etagHeaders {
|
||||
if r.Header.Get(v) != "" {
|
||||
r.Header.Del(v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user