From e275ee634c60c475569b9e72e4d37228a5b8f0ed Mon Sep 17 00:00:00 2001 From: yusing Date: Sun, 4 May 2025 16:18:46 +0800 Subject: [PATCH] fix(http): content type detection --- internal/net/gphttp/content_type.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/net/gphttp/content_type.go b/internal/net/gphttp/content_type.go index 5f30d9e..7dd6bbb 100644 --- a/internal/net/gphttp/content_type.go +++ b/internal/net/gphttp/content_type.go @@ -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 }