李伟乐 2 years ago
parent 77f4859dfa
commit 824706362f
  1. 9
      transport/http/codec.go

@ -37,9 +37,7 @@ func DefaultRequestQuery(r *http.Request, v any) error {
return binding.BindQuery(r.URL.Query(), v)
}
func DefaultRequestDecoder(r *http.Request, v any) error {
fmt.Println("DefaultRequestDecoder")
codec, ok := CodeForRequest(r, "Content-type")
fmt.Println("request decoder", ok)
codec, ok := CodeForRequest(r, "Content-Type")
if !ok {
return errors.BadRequest("CODEC", fmt.Sprintf("unregister Content-Type: %s", codec))
}
@ -87,11 +85,8 @@ func DefaultErrorEncoder(w http.ResponseWriter, r *http.Request, err error) {
_, _ = w.Write(body)
}
func CodeForRequest(r *http.Request, name string) (encoding.Codec, bool) {
fmt.Printf("%+v\n", r.Header)
for _, accept := range r.Header[name] {
a := httputil.ContentSubtype(accept)
fmt.Println(name, a)
codec := encoding.GetCodec(a)
codec := encoding.GetCodec(httputil.ContentSubtype(accept))
if codec != nil {
return codec, true
}

Loading…
Cancel
Save