李伟乐 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) return binding.BindQuery(r.URL.Query(), v)
} }
func DefaultRequestDecoder(r *http.Request, v any) error { func DefaultRequestDecoder(r *http.Request, v any) error {
fmt.Println("DefaultRequestDecoder") codec, ok := CodeForRequest(r, "Content-Type")
codec, ok := CodeForRequest(r, "Content-type")
fmt.Println("request decoder", ok)
if !ok { if !ok {
return errors.BadRequest("CODEC", fmt.Sprintf("unregister Content-Type: %s", codec)) 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) _, _ = w.Write(body)
} }
func CodeForRequest(r *http.Request, name string) (encoding.Codec, bool) { func CodeForRequest(r *http.Request, name string) (encoding.Codec, bool) {
fmt.Printf("%+v\n", r.Header)
for _, accept := range r.Header[name] { for _, accept := range r.Header[name] {
a := httputil.ContentSubtype(accept) codec := encoding.GetCodec(httputil.ContentSubtype(accept))
fmt.Println(name, a)
codec := encoding.GetCodec(a)
if codec != nil { if codec != nil {
return codec, true return codec, true
} }

Loading…
Cancel
Save