craban/server/web/static.go
Miguel de la Cruz f76aa74179 Stuff
2021-09-12 21:57:59 +02:00

35 lines
766 B
Go

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)
}
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)
}