craban/server/web/static.go

36 lines
766 B
Go
Raw Permalink Normal View History

package web
import (
"net/http"
)
type NotFoundIndexResponseWriter struct {
http.ResponseWriter
status int
}
func (nfr *NotFoundIndexResponseWriter) WriteHeader(status int) {
nfr.status = status
if status != http.StatusNotFound {
nfr.ResponseWriter.WriteHeader(status)
}
}
func (nfr *NotFoundIndexResponseWriter) Write(p []byte) (int, error) {
if nfr.status != http.StatusNotFound {
return nfr.ResponseWriter.Write(p)
}
nfr.Header().Add("Content-Type", "text/html; charset=utf-8")
return nfr.ResponseWriter.Write(indexBytes)
}
2021-09-12 20:57:59 +01:00
type StaticFSHandler struct {
Handler http.Handler
}
func (s StaticFSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
srw := &NotFoundIndexResponseWriter{ResponseWriter: w}
s.Handler.ServeHTTP(srw, r)
}