summaryrefslogtreecommitdiff
path: root/srv/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'srv/cmd')
-rw-r--r--srv/cmd/mediocre-blog/main.go6
-rw-r--r--srv/cmd/mediocre-blog/middleware.go9
2 files changed, 15 insertions, 0 deletions
diff --git a/srv/cmd/mediocre-blog/main.go b/srv/cmd/mediocre-blog/main.go
index 5233a2c..66c17ee 100644
--- a/srv/cmd/mediocre-blog/main.go
+++ b/srv/cmd/mediocre-blog/main.go
@@ -172,6 +172,12 @@ func main() {
apiHandler := logMiddleware(logger.WithNamespace("api"), apiMux)
apiHandler = annotateMiddleware(apiHandler)
+ apiHandler = addResponseHeaders(map[string]string{
+ "Cache-Control": "no-store, max-age=0",
+ "Pragma": "no-cache",
+ "Expires": "0",
+ }, apiHandler)
+
mux.Handle("/api/", http.StripPrefix("/api", apiHandler))
// run
diff --git a/srv/cmd/mediocre-blog/middleware.go b/srv/cmd/mediocre-blog/middleware.go
index 4ffba2c..165f82f 100644
--- a/srv/cmd/mediocre-blog/middleware.go
+++ b/srv/cmd/mediocre-blog/middleware.go
@@ -9,6 +9,15 @@ import (
"github.com/mediocregopher/mediocre-go-lib/v2/mlog"
)
+func addResponseHeaders(headers map[string]string, h http.Handler) http.Handler {
+ return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
+ for k, v := range headers {
+ rw.Header().Set(k, v)
+ }
+ h.ServeHTTP(rw, r)
+ })
+}
+
func annotateMiddleware(h http.Handler) http.Handler {
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {