Skip to content

Commit

Permalink
add servecontent to caddy
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Feb 10, 2024
1 parent bac8bf4 commit f8d2c37
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions caddy/pmtiles_proxy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package caddy

Check warning on line 1 in caddy/pmtiles_proxy.go

View workflow job for this annotation

GitHub Actions / fmt_vet_lint

should have a package comment

import (
"bytes"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f8d2c37

Please sign in to comment.