We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 14464bf commit 7b331eeCopy full SHA for 7b331ee
bind.go
@@ -67,14 +67,7 @@ func (b *DefaultBinder) BindQueryParams(c Context, i interface{}) error {
67
// See MIMEMultipartForm: https://golang.org/pkg/net/http/#Request.ParseMultipartForm
68
func (b *DefaultBinder) BindBody(c Context, i interface{}) (err error) {
69
req := c.Request()
70
- var isChunked bool
71
- for _, enc := range req.TransferEncoding {
72
- if enc == "chunked" {
73
- isChunked = true
74
- break
75
- }
76
77
- if req.ContentLength <= 0 && !isChunked {
+ if req.ContentLength == 0 {
78
return
79
}
80
bind_test.go
@@ -1063,12 +1063,21 @@ func TestDefaultBinder_BindBody(t *testing.T) {
1063
expectError: "code=415, message=Unsupported Media Type",
1064
},
1065
{
1066
- name: "ok, JSON POST bind to struct with: path + query + http.NoBody",
+ name: "nok, JSON POST with http.NoBody",
1067
givenURL: "/api/real_node/endpoint?node=xxx",
1068
givenMethod: http.MethodPost,
1069
givenContentType: MIMEApplicationJSON,
1070
givenContent: http.NoBody,
1071
expect: &Node{ID: 0, Node: ""},
1072
+ expectError: "code=400, message=EOF, internal=EOF",
1073
+ },
1074
+ {
1075
+ name: "ok, JSON POST with empty body",
1076
+ givenURL: "/api/real_node/endpoint?node=xxx",
1077
+ givenMethod: http.MethodPost,
1078
+ givenContentType: MIMEApplicationJSON,
1079
+ givenContent: strings.NewReader(""),
1080
+ expect: &Node{ID: 0, Node: ""},
1081
1082
1083
name: "ok, JSON POST bind to struct with: path + query + chunked body",
0 commit comments