This commit is contained in:
Gerasimos (Makis) Maropoulos 2022-08-12 21:07:39 +03:00
parent dd4bc50f78
commit 3715a66ef0
No known key found for this signature in database
GPG Key ID: 403EEB7885C79503
2 changed files with 21 additions and 4 deletions

View File

@ -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]

View File

@ -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"
)