1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-09 04:51:56 +00:00

Add DisableBodyConsumptionOnUnmarshal configuration field as discussed on [chat](https://kataras.rocket.chat/channel/iris). Read HISTORY.md

This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-01-30 12:35:43 +02:00
parent a563b37ba1
commit 2a911a450c
6 changed files with 102 additions and 36 deletions

View File

@@ -251,6 +251,13 @@ func testUnmarshaler(t *testing.T, tb *testBinder,
if write != nil {
write(ctx)
}
if iris.Config.DisableBodyConsumptionOnUnmarshal {
rawData, _ := ioutil.ReadAll(ctx.Request.Body)
if len(rawData) == 0 {
t.Fatalf("Expected data to NOT BE consumed by the previous UnmarshalBody call but we got empty body.")
}
}
}
iris.Post("/bind_req_body", h)
@@ -301,7 +308,6 @@ func TestContextBinders(t *testing.T) {
expectedObj.Birth + `</birth><stars>` +
strconv.Itoa(expectedObj.Stars) + `</stars></info>`
// JSON
vXML := &testBinder{&testBinderXMLData{},
iris.UnmarshalerFunc(xml.Unmarshal), false}
testUnmarshaler(
@@ -315,6 +321,18 @@ func TestContextBinders(t *testing.T) {
Status(iris.StatusOK).
Body().Equal(expectedAndPassedObjText)
// JSON with DisableBodyConsumptionOnUnmarshal
iris.Config.DisableBodyConsumptionOnUnmarshal = true
testUnmarshaler(
t,
vJSON,
func(ctx *iris.Context) {
ctx.JSON(iris.StatusOK, vJSON.vp)
}).
WithJSON(passed).
Expect().
Status(iris.StatusOK).
JSON().Object().Equal(expectedObject)
}
func TestContextReadForm(t *testing.T) {