fix
This commit is contained in:
parent
3c29aa847c
commit
b2fe05111c
@ -13,7 +13,6 @@ import (
|
|||||||
"git.zhangdeman.cn/zhangdeman/wrapper"
|
"git.zhangdeman.cn/zhangdeman/wrapper"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -85,7 +84,7 @@ func (wh *wrapperHandle) GetScheme(ctx *gin.Context, defaultVal string) string {
|
|||||||
func (wh *wrapperHandle) GetQuery(ctx *gin.Context) map[string]string {
|
func (wh *wrapperHandle) GetQuery(ctx *gin.Context) map[string]string {
|
||||||
query := make(map[string]string)
|
query := make(map[string]string)
|
||||||
if nil != ctx && nil != ctx.Request && nil != ctx.Request.URL {
|
if nil != ctx && nil != ctx.Request && nil != ctx.Request.URL {
|
||||||
for paramName, valueList := range {
|
for paramName, valueList := range ctx.Request.URL.Query() {
|
||||||
if len(valueList) == 0 {
|
if len(valueList) == 0 {
|
||||||
query[paramName] = ""
|
query[paramName] = ""
|
||||||
} else {
|
} else {
|
||||||
@ -130,14 +129,6 @@ func (wh *wrapperHandle) GetContentType(ctx *gin.Context, defaultVal string) str
|
|||||||
func (wh *wrapperHandle) GetRequestBody(ctx *gin.Context) map[string]any {
|
func (wh *wrapperHandle) GetRequestBody(ctx *gin.Context) map[string]any {
|
||||||
body := map[string]any{}
|
body := map[string]any{}
|
||||||
contentType := wh.GetContentType(ctx, "")
|
contentType := wh.GetContentType(ctx, "")
|
||||||
if strings.Contains(contentType, consts.MimeTypeJson) { // json请求
|
|
||||||
data, err := io.ReadAll(ctx.Request.Body)
|
|
||||||
if nil != err {
|
|
||||||
return body
|
|
||||||
}
|
|
||||||
ctx.Request.Body = io.NopCloser(bytes.NewBuffer(data))
|
|
||||||
return body
|
|
||||||
}
|
|
||||||
if strings.Contains(contentType, consts.MimeTypeXWWWFormUrlencoded) { // form请求
|
if strings.Contains(contentType, consts.MimeTypeXWWWFormUrlencoded) { // form请求
|
||||||
if err := ctx.Request.ParseForm(); nil != err {
|
if err := ctx.Request.ParseForm(); nil != err {
|
||||||
return body
|
return body
|
||||||
@ -151,6 +142,16 @@ func (wh *wrapperHandle) GetRequestBody(ctx *gin.Context) map[string]any {
|
|||||||
}
|
}
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Contains(contentType, consts.MimeTypeJson) || nil != ctx.Request.Body { // json请求 或者非 json请求 存在 body
|
||||||
|
data, err := io.ReadAll(ctx.Request.Body)
|
||||||
|
if nil != err {
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
ctx.Request.Body = io.NopCloser(bytes.NewBuffer(data))
|
||||||
|
return body
|
||||||
|
}
|
||||||
|
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user