From f8d2c372ed6ac43a41c012a7c8bfa44cd4df9c3c Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Sat, 10 Feb 2024 15:40:50 -0500 Subject: [PATCH] add servecontent to caddy --- caddy/pmtiles_proxy.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/caddy/pmtiles_proxy.go b/caddy/pmtiles_proxy.go index e237bc1..f7386ec 100644 --- a/caddy/pmtiles_proxy.go +++ b/caddy/pmtiles_proxy.go @@ -1,6 +1,7 @@ package caddy import ( + "bytes" "fmt" "io" "log" @@ -72,8 +73,12 @@ func (m Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy for k, v := range headers { w.Header().Set(k, v) } - w.WriteHeader(statusCode) - w.Write(body) + if statusCode == 200 { + http.ServeContent(w, r, "", time.UnixMilli(0), bytes.NewReader(body)) + } else { + w.WriteHeader(statusCode) + w.Write(body) + } m.logger.Info("response", zap.Int("status", statusCode), zap.String("path", r.URL.Path), zap.Duration("duration", time.Since(start))) return next.ServeHTTP(w, r)