diff --git a/context/context.go b/context/context.go index 900785fc..1f2a1f52 100644 --- a/context/context.go +++ b/context/context.go @@ -2575,8 +2575,12 @@ func (ctx *Context) RecordRequestBody(b bool) { // IsRecordingBody reports whether the request body can be readen multiple times. func (ctx *Context) IsRecordingBody() bool { - return ctx.values.GetBoolDefault(disableRequestBodyConsumptionContextKey, - ctx.app.ConfigurationReadOnly().GetDisableBodyConsumptionOnUnmarshal()) + if ctx.app.ConfigurationReadOnly().GetDisableBodyConsumptionOnUnmarshal() { + return true + } + + value, _ := ctx.values.GetBool(disableRequestBodyConsumptionContextKey) + return value } // GetBody reads and returns the request body. @@ -2672,7 +2676,20 @@ type JSONReader struct { // Note(@kataras): struct instead of optional funcs to } var ReadJSON = func(ctx *Context, outPtr interface{}, opts ...JSONReader) error { - decoder := json.NewDecoder(ctx.request.Body) + var body io.Reader + + if ctx.IsRecordingBody() { + data, err := io.ReadAll(ctx.request.Body) + if err != nil { + return err + } + setBody(ctx.request, data) + body = bytes.NewReader(data) + } else { + body = ctx.request.Body + } + + decoder := json.NewDecoder(body) // decoder := gojson.NewDecoder(ctx.Request().Body) if len(opts) > 0 { options := opts[0] diff --git a/x/jsonx/iso8601.go b/x/jsonx/iso8601.go index 8fc26512..cae75ebe 100644 --- a/x/jsonx/iso8601.go +++ b/x/jsonx/iso8601.go @@ -27,7 +27,7 @@ const ( // ISO8601ZLayout same as ISO8601Layout but with the timezone suffix. ISO8601ZLayout = "2006-01-02T15:04:05Z" // ISO8601ZUTCOffsetLayout ISO 8601 format, with full time and zone with UTC offset. - // Example: 2022-08-10T03:21:00.000000+03:00. + // Example: 2022-08-10T03:21:00.000000+03:00, 2022-08-09T00:00:00.000000. ISO8601ZUTCOffsetLayout = "2006-01-02T15:04:05.999999Z07:00" )