|
|
|
@ -22,6 +22,7 @@ package main
@@ -22,6 +22,7 @@ package main
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"app/spreed-speakfreely-server/sleepy" |
|
|
|
|
"bytes" |
|
|
|
|
"flag" |
|
|
|
|
"fmt" |
|
|
|
|
"github.com/gorilla/mux" |
|
|
|
@ -98,13 +99,16 @@ func makeImageHandler(hub *Hub, expires time.Duration) http.HandlerFunc {
@@ -98,13 +99,16 @@ func makeImageHandler(hub *Hub, expires time.Duration) http.HandlerFunc {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
w.Header().Set("Content-Type", image.mimetype) |
|
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(image.data))) |
|
|
|
|
w.Header().Set("Date", time.Now().Format(time.RFC822)) |
|
|
|
|
w.Header().Set("ETag", image.lastChangeId) |
|
|
|
|
age := time.Now().Sub(image.lastChange) |
|
|
|
|
if age >= time.Second { |
|
|
|
|
w.Header().Set("Age", strconv.Itoa(int(age.Seconds()))) |
|
|
|
|
} |
|
|
|
|
if expires >= time.Second { |
|
|
|
|
w.Header().Set("Expires", time.Now().Add(expires).Format(time.RFC1123)) |
|
|
|
|
w.Header().Set("Cache-Control", "max-age="+strconv.Itoa(int(expires.Seconds()))) |
|
|
|
|
w.Header().Set("Cache-Control", "public, no-transform, max-age="+strconv.Itoa(int(expires.Seconds()))) |
|
|
|
|
} |
|
|
|
|
w.Write(image.data) |
|
|
|
|
http.ServeContent(w, r, "", image.lastChange, bytes.NewReader(image.data)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -319,7 +323,7 @@ func runner(runtime phoenix.Runtime) error {
@@ -319,7 +323,7 @@ func runner(runtime phoenix.Runtime) error {
|
|
|
|
|
router := mux.NewRouter() |
|
|
|
|
r := router.PathPrefix(basePath).Subrouter().StrictSlash(true) |
|
|
|
|
r.HandleFunc("/", httputils.MakeGzipHandler(mainHandler)) |
|
|
|
|
r.Handle("/static/img/buddy/{flags}/{imageid}/{idx:.*}", http.StripPrefix(basePath, makeImageHandler(hub, time.Hour))) |
|
|
|
|
r.Handle("/static/img/buddy/{flags}/{imageid}/{idx:.*}", http.StripPrefix(basePath, makeImageHandler(hub, time.Duration(24)*time.Hour))) |
|
|
|
|
r.Handle("/static/{path:.*}", http.StripPrefix(basePath, httputils.FileStaticServer(http.Dir(rootFolder)))) |
|
|
|
|
r.Handle("/robots.txt", http.StripPrefix(basePath, http.FileServer(http.Dir(path.Join(rootFolder, "static"))))) |
|
|
|
|
r.Handle("/favicon.ico", http.StripPrefix(basePath, http.FileServer(http.Dir(path.Join(rootFolder, "static", "img"))))) |
|
|
|
|