@@ -13,6 +13,7 @@ import (
1313 "mime/multipart"
1414 "net/http"
1515 "net/http/httptest"
16+ "net/http/httputil"
1617 "net/url"
1718 "reflect"
1819 "strconv"
@@ -941,6 +942,7 @@ func TestDefaultBinder_BindBody(t *testing.T) {
941942 givenMethod string
942943 givenContentType string
943944 whenNoPathParams bool
945+ whenChunkedBody bool
944946 whenBindTarget interface {}
945947 expect interface {}
946948 expectError string
@@ -1068,6 +1070,15 @@ func TestDefaultBinder_BindBody(t *testing.T) {
10681070 givenContent : http .NoBody ,
10691071 expect : & Node {ID : 0 , Node : "" },
10701072 },
1073+ {
1074+ name : "ok, JSON POST bind to struct with: path + query + chunked body" ,
1075+ givenURL : "/api/real_node/endpoint?node=xxx" ,
1076+ givenMethod : http .MethodPost ,
1077+ givenContentType : MIMEApplicationJSON ,
1078+ givenContent : httputil .NewChunkedReader (strings .NewReader ("18\r \n " + `{"id": 1, "node": "zzz"}` + "\r \n 0\r \n " )),
1079+ whenChunkedBody : true ,
1080+ expect : & Node {ID : 1 , Node : "zzz" },
1081+ },
10711082 }
10721083
10731084 for _ , tc := range testCases {
@@ -1083,6 +1094,10 @@ func TestDefaultBinder_BindBody(t *testing.T) {
10831094 case MIMEApplicationJSON :
10841095 req .Header .Set (HeaderContentType , MIMEApplicationJSON )
10851096 }
1097+ if tc .whenChunkedBody {
1098+ req .ContentLength = - 1
1099+ req .TransferEncoding = append (req .TransferEncoding , "chunked" )
1100+ }
10861101 rec := httptest .NewRecorder ()
10871102 c := e .NewContext (req , rec )
10881103
0 commit comments