|
@@ -54,16 +54,16 @@ func etag(str string) string {
|
|
|
return hex.EncodeToString(hasher.Sum(nil))
|
|
|
}
|
|
|
|
|
|
-func modified(p string, s int, v int64, w *http.ResponseWriter, r *http.Request) bool {
|
|
|
- (*w).Header().Set("Content-Length", fmt.Sprintf("%d", s))
|
|
|
- (*w).Header().Set("Cache-Control", "no-cache")
|
|
|
+func modified(p string, s int, v int64, w http.ResponseWriter, r *http.Request) bool {
|
|
|
+ w.Header().Set("Content-Length", fmt.Sprintf("%d", s))
|
|
|
+ w.Header().Set("Cache-Control", "no-cache")
|
|
|
|
|
|
// Set: ETag
|
|
|
ehash := etag(fmt.Sprintf("%s-%d-%d", p, s, v))
|
|
|
- (*w).Header().Set("ETag", fmt.Sprintf("%s", ehash))
|
|
|
+ w.Header().Set("ETag", fmt.Sprintf("%s", ehash))
|
|
|
|
|
|
// Set: Last-Modified
|
|
|
- (*w).Header().Set(
|
|
|
+ w.Header().Set(
|
|
|
"Last-Modified",
|
|
|
time.Unix(v, 0).In(time.FixedZone("GMT", 0)).Format("Wed, 01 Oct 2006 15:04:05 GMT"),
|
|
|
)
|
|
@@ -71,7 +71,7 @@ func modified(p string, s int, v int64, w *http.ResponseWriter, r *http.Request)
|
|
|
// Check: ETag
|
|
|
if cc := r.Header.Get("Cache-Control"); cc != "no-cache" {
|
|
|
if inm := r.Header.Get("If-None-Match"); inm == ehash {
|
|
|
- (*w).WriteHeader(http.StatusNotModified)
|
|
|
+ w.WriteHeader(http.StatusNotModified)
|
|
|
return false
|
|
|
}
|
|
|
}
|
|
@@ -81,7 +81,7 @@ func modified(p string, s int, v int64, w *http.ResponseWriter, r *http.Request)
|
|
|
if ims := r.Header.Get("If-Modified-Since"); ims != "" {
|
|
|
if t, err := time.Parse("Wed, 01 Oct 2006 15:04:05 GMT", ims); err == nil {
|
|
|
if time.Unix(v, 0).In(time.FixedZone("GMT", 0)).Unix() <= t.In(time.FixedZone("GMT", 0)).Unix() {
|
|
|
- (*w).WriteHeader(http.StatusNotModified)
|
|
|
+ w.WriteHeader(http.StatusNotModified)
|
|
|
return false
|
|
|
}
|
|
|
}
|
|
@@ -97,28 +97,28 @@ func (this *bootstrap) handler(w http.ResponseWriter, r *http.Request) {
|
|
|
}
|
|
|
if r.URL.Path == "/"+this.opts.Path+"/bootstrap.css" {
|
|
|
w.Header().Set("Content-Type", "text/css")
|
|
|
- if !modified(r.URL.Path, len(rbc), rbcm, &w, r) {
|
|
|
+ if !modified(r.URL.Path, len(rbc), rbcm, w, r) {
|
|
|
return
|
|
|
}
|
|
|
w.Write(rbc)
|
|
|
return
|
|
|
} else if r.URL.Path == "/"+this.opts.Path+"/bootstrap.js" {
|
|
|
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
|
|
|
- if !modified(r.URL.Path, len(rbj), rbjm, &w, r) {
|
|
|
+ if !modified(r.URL.Path, len(rbj), rbjm, w, r) {
|
|
|
return
|
|
|
}
|
|
|
w.Write(rbj)
|
|
|
return
|
|
|
} else if r.URL.Path == "/"+this.opts.Path+"/jquery.js" {
|
|
|
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
|
|
|
- if !modified(r.URL.Path, len(rjj), rjjm, &w, r) {
|
|
|
+ if !modified(r.URL.Path, len(rjj), rjjm, w, r) {
|
|
|
return
|
|
|
}
|
|
|
w.Write(rjj)
|
|
|
return
|
|
|
} else if r.URL.Path == "/"+this.opts.Path+"/popper.js" {
|
|
|
w.Header().Set("Content-Type", "application/javascript; charset=utf-8")
|
|
|
- if !modified(r.URL.Path, len(rpj), rpjm, &w, r) {
|
|
|
+ if !modified(r.URL.Path, len(rpj), rpjm, w, r) {
|
|
|
return
|
|
|
}
|
|
|
w.Write(rpj)
|