mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
fix(http): content type detection
This commit is contained in:
parent
797d88772f
commit
e275ee634c
1 changed files with 9 additions and 1 deletions
|
@ -3,6 +3,7 @@ package gphttp
|
||||||
import (
|
import (
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -33,13 +34,20 @@ func GetContentType(h http.Header) ContentType {
|
||||||
|
|
||||||
func GetAccept(h http.Header) AcceptContentType {
|
func GetAccept(h http.Header) AcceptContentType {
|
||||||
var accepts []ContentType
|
var accepts []ContentType
|
||||||
for _, v := range h["Accept"] {
|
acceptHeader := h["Accept"]
|
||||||
|
if len(acceptHeader) == 1 {
|
||||||
|
acceptHeader = strings.Split(acceptHeader[0], ",")
|
||||||
|
}
|
||||||
|
for _, v := range acceptHeader {
|
||||||
ct, _, err := mime.ParseMediaType(v)
|
ct, _, err := mime.ParseMediaType(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
accepts = append(accepts, ContentType(ct))
|
accepts = append(accepts, ContentType(ct))
|
||||||
}
|
}
|
||||||
|
if len(accepts) == 0 {
|
||||||
|
return []ContentType{"*/*"}
|
||||||
|
}
|
||||||
return accepts
|
return accepts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue