From 4d00768a1224cf98931d25b8493c4bb21fa46d2b Mon Sep 17 00:00:00 2001 From: Steven Soroka Date: Sun, 25 Feb 2024 00:06:17 -0500 Subject: [PATCH] fix the encoder to take the first encoding supported --- encoding/encode.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/encoding/encode.go b/encoding/encode.go index 7823476..bcd7b00 100644 --- a/encoding/encode.go +++ b/encoding/encode.go @@ -2,6 +2,7 @@ package encoding import ( "context" + "strings" "github.com/valyala/fasthttp" ) @@ -50,7 +51,13 @@ func RegisterEncoder[T EncoderConstraint](enc T, mime string, aliases ...string) // GetEncoder returns the response encoder for a given media type. func GetEncoder(mime string) ResponseEncoder { - return encoders[mime] + mimeParts := strings.Split(mime, ",") + for _, part := range mimeParts { + if enc, ok := encoders[part]; ok { + return enc + } + } + return nil } var encoders = map[string]ResponseEncoder{}