mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
fix #1949
This commit is contained in:
parent
dd4bc50f78
commit
3715a66ef0
|
@ -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]
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user