mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01:00
fix(http): content type detection
This commit is contained in:
@@ -3,6 +3,7 @@ package gphttp
|
||||
import (
|
||||
"mime"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -33,13 +34,20 @@ func GetContentType(h http.Header) ContentType {
|
||||
|
||||
func GetAccept(h http.Header) AcceptContentType {
|
||||
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)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
accepts = append(accepts, ContentType(ct))
|
||||
}
|
||||
if len(accepts) == 0 {
|
||||
return []ContentType{"*/*"}
|
||||
}
|
||||
return accepts
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user