收敛 JSON 请求解析测试实现
This commit is contained in:
parent
be84ecfb91
commit
5f7930ce35
@ -11,8 +11,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestBindJSONRejectsUnknownFieldsAndTrailingValues(t *testing.T) {
|
func TestBindJSONRejectsUnknownFieldsAndTrailingValues(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
body string
|
body string
|
||||||
|
|||||||
@ -93,13 +93,6 @@ func (s *Server) sameOriginForAPI(request *http.Request) bool {
|
|||||||
return strings.EqualFold(parsed.Host, request.Host) && strings.EqualFold(parsed.Scheme, requestScheme)
|
return strings.EqualFold(parsed.Host, request.Host) && strings.EqualFold(parsed.Scheme, requestScheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
func limitJSONBody(c *gin.Context) {
|
|
||||||
if c == nil || c.Request == nil || c.Request.Body == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, jsonRequestBodyLimit)
|
|
||||||
}
|
|
||||||
|
|
||||||
func requestIDFromContext(c *gin.Context) string {
|
func requestIDFromContext(c *gin.Context) string {
|
||||||
value, exists := c.Get("request_id")
|
value, exists := c.Get("request_id")
|
||||||
if !exists {
|
if !exists {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user