v0.0.299 pctx.RawBody( *[]byte )
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m41s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m41s
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package ginext
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/dataext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"io"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
)
|
||||
@@ -17,6 +20,7 @@ type PreContext struct {
|
||||
uri any
|
||||
query any
|
||||
body any
|
||||
rawbody *[]byte
|
||||
form any
|
||||
header any
|
||||
timeout *time.Duration
|
||||
@@ -37,6 +41,11 @@ func (pctx *PreContext) Body(body any) *PreContext {
|
||||
return pctx
|
||||
}
|
||||
|
||||
func (pctx *PreContext) RawBody(rawbody *[]byte) *PreContext {
|
||||
pctx.rawbody = rawbody
|
||||
return pctx
|
||||
}
|
||||
|
||||
func (pctx *PreContext) Form(form any) *PreContext {
|
||||
pctx.form = form
|
||||
return pctx
|
||||
@@ -90,6 +99,23 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
if pctx.rawbody != nil {
|
||||
if brc, ok := pctx.ginCtx.Request.Body.(dataext.BufferedReadCloser); ok {
|
||||
v, err := brc.BufferedAll()
|
||||
if err != nil {
|
||||
return nil, nil, langext.Ptr(Error(err))
|
||||
}
|
||||
*pctx.rawbody = v
|
||||
} else {
|
||||
buf := &bytes.Buffer{}
|
||||
_, err := io.Copy(buf, pctx.ginCtx.Request.Body)
|
||||
if err != nil {
|
||||
return nil, nil, langext.Ptr(Error(err))
|
||||
}
|
||||
*pctx.rawbody = buf.Bytes()
|
||||
}
|
||||
}
|
||||
|
||||
if pctx.form != nil {
|
||||
if pctx.ginCtx.ContentType() == "multipart/form-data" {
|
||||
if err := pctx.ginCtx.ShouldBindWith(pctx.form, binding.Form); err != nil {
|
||||
|
Reference in New Issue
Block a user