Skip to content

Commit

Permalink
fix the encoder to take the first encoding supported
Browse files Browse the repository at this point in the history
  • Loading branch information
ssoroka committed Feb 25, 2024
1 parent 6bb99b5 commit 4d00768
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion encoding/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package encoding

import (
"context"
"strings"

"github.com/valyala/fasthttp"
)
Expand Down Expand Up @@ -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

Check warning on line 60 in encoding/encode.go

View check run for this annotation

Codecov / codecov/patch

encoding/encode.go#L60

Added line #L60 was not covered by tests
}

var encoders = map[string]ResponseEncoder{}

0 comments on commit 4d00768

Please sign in to comment.