...
1 package httpx
2
3 import (
4 "mime"
5 "net/http"
6 "strings"
7
8 "github.com/ory/x/stringslice"
9 )
10
11
12
13
14
15 func HasContentType(r *http.Request, mimetypes ...string) bool {
16 contentType := r.Header.Get("Content-Type")
17 if contentType == "" {
18 return stringslice.Has(mimetypes, "application/octet-stream")
19 }
20
21 for _, v := range strings.Split(contentType, ",") {
22 t, _, err := mime.ParseMediaType(strings.TrimSpace(v))
23 if err != nil {
24 break
25 }
26 if stringslice.Has(mimetypes, t) {
27 return true
28 }
29 }
30 return false
31 }
32
View as plain text