Set content-type before writing status code

This commit is contained in:
Jan-Lukas Else 2023-09-25 11:05:45 +02:00
parent 75e60326ff
commit dfc1af4f2e
2 changed files with 5 additions and 5 deletions

View File

@ -171,8 +171,8 @@ func (a *goBlog) serveAPItem(w http.ResponseWriter, r *http.Request, status int,
return
}
// Send response
w.WriteHeader(status)
w.Header().Set(contentType, contenttype.ASUTF8)
w.WriteHeader(status)
_ = a.min.Get().Minify(contenttype.AS, w, bytes.NewReader(binary))
}

View File

@ -62,10 +62,10 @@ type Compressor struct {
func NewCompressor(level int, types ...string) *Compressor {
// If types are provided, set those as the allowed types. If none are
// provided, use the default list.
allowedTypes := map[string]any{}
for _, t := range lo.If(len(types) > 0, types).Else(defaultCompressibleContentTypes) {
allowedTypes[t] = nil
}
allowedTypes := lo.SliceToMap(
lo.If(len(types) > 0, types).Else(defaultCompressibleContentTypes),
func(t string) (string, any) { return t, nil },
)
c := &Compressor{
level: level,