...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package runtime
16
17 import (
18 "mime"
19 "net/http"
20
21 "github.com/go-openapi/errors"
22 )
23
24
25 func ContentType(headers http.Header) (string, string, error) {
26 ct := headers.Get(HeaderContentType)
27 orig := ct
28 if ct == "" {
29 ct = DefaultMime
30 }
31 if ct == "" {
32 return "", "", nil
33 }
34
35 mt, opts, err := mime.ParseMediaType(ct)
36 if err != nil {
37 return "", "", errors.NewParseError(HeaderContentType, "header", orig, err)
38 }
39
40 if cs, ok := opts[charsetKey]; ok {
41 return mt, cs, nil
42 }
43
44 return mt, "", nil
45 }
46
View as plain text