李伟乐 2 years ago
parent 4ff4b3551d
commit 205a5e9a0f
  1. 2
      transport/http/codec.go

@ -38,6 +38,7 @@ func DefaultRequestQuery(r *http.Request, v any) error {
}
func DefaultRequestDecoder(r *http.Request, v any) error {
codec, ok := CodeForRequest(r, "Content-type")
fmt.Println(codec, ok)
if !ok {
return errors.BadRequest("CODEC", fmt.Sprintf("unregister Content-Type: %s", codec))
}
@ -86,6 +87,7 @@ func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, err error) {
}
func CodeForRequest(r *http.Request, name string) (encoding.Codec, bool) {
for _, accept := range r.Header[name] {
fmt.Println(accept)
codec := encoding.GetCodec(httputil.ContentSubtype(accept))
if codec != nil {
return codec, true

Loading…
Cancel
Save