fix(errors,middlewares): Accept header prefersHtml boolean operator

This commit is contained in:
Guz
2024-10-18 00:23:09 -03:00
parent c55a516a3d
commit d74a13bfd6

View File

@@ -227,8 +227,11 @@ func (m *ErrorMiddleware) Wrap(next http.Handler) http.Handler {
}
func prefersHtml(h http.Header) bool {
if h.Get("Accept") == "" {
return false
}
return (strings.Contains(h.Get("Accept"), "text/html") ||
strings.Contains(h.Get("Accept"), "application/xhtml+xml") ||
strings.Contains(h.Get("Accept"), "application/xml")) ||
strings.Contains(h.Get("Accept"), "application/xml")) &&
!strings.Contains(h.Get("Accept"), "application/json")
}