mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-14 20:22:20 +08:00
Merge 07792fc47878734eace20bad73c7e8611643e548 into f9bd00a6b7939b941fde3fdd239367f4a7d6b137
This commit is contained in:
commit
e6e511da93
@ -792,9 +792,8 @@ func (c *Context) MustBindWith(obj any, b binding.Binding) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
var maxBytesErr *http.MaxBytesError
|
var maxBytesErr *http.MaxBytesError
|
||||||
|
|
||||||
// Note: When using sonic or go-json as JSON encoder, they do not propagate the http.MaxBytesError error
|
// Note: When using go-json as JSON encoder, they do not propagate the http.MaxBytesError error
|
||||||
// https://github.com/goccy/go-json/issues/485
|
// https://github.com/goccy/go-json/issues/485
|
||||||
// https://github.com/bytedance/sonic/issues/800
|
|
||||||
switch {
|
switch {
|
||||||
case errors.As(err, &maxBytesErr):
|
case errors.As(err, &maxBytesErr):
|
||||||
c.AbortWithError(http.StatusRequestEntityTooLarge, err).SetType(ErrorTypeBind) //nolint: errcheck
|
c.AbortWithError(http.StatusRequestEntityTooLarge, err).SetType(ErrorTypeBind) //nolint: errcheck
|
||||||
|
@ -1991,13 +1991,12 @@ func TestContextContentType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestContextBindRequestTooLarge(t *testing.T) {
|
func TestContextBindRequestTooLarge(t *testing.T) {
|
||||||
// When using sonic or go-json as JSON encoder, they do not propagate the http.MaxBytesError error
|
// When using go-json as JSON encoder, they do not propagate the http.MaxBytesError error
|
||||||
// The response will fail with a generic 400 instead of 413
|
// The response will fail with a generic 400 instead of 413
|
||||||
// https://github.com/goccy/go-json/issues/485
|
// https://github.com/goccy/go-json/issues/485
|
||||||
// https://github.com/bytedance/sonic/issues/800
|
|
||||||
var expectedCode int
|
var expectedCode int
|
||||||
switch json.Package {
|
switch json.Package {
|
||||||
case "github.com/goccy/go-json", "github.com/bytedance/sonic":
|
case "github.com/goccy/go-json":
|
||||||
expectedCode = http.StatusBadRequest
|
expectedCode = http.StatusBadRequest
|
||||||
default:
|
default:
|
||||||
expectedCode = http.StatusRequestEntityTooLarge
|
expectedCode = http.StatusRequestEntityTooLarge
|
||||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/gin-gonic/gin
|
|||||||
go 1.23.0
|
go 1.23.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bytedance/sonic v1.13.2
|
github.com/bytedance/sonic v1.13.3
|
||||||
github.com/gin-contrib/sse v1.1.0
|
github.com/gin-contrib/sse v1.1.0
|
||||||
github.com/go-playground/validator/v10 v10.27.0
|
github.com/go-playground/validator/v10 v10.27.0
|
||||||
github.com/goccy/go-json v0.10.2
|
github.com/goccy/go-json v0.10.2
|
||||||
|
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
|||||||
github.com/bytedance/sonic v1.13.2 h1:8/H1FempDZqC4VqjptGo14QQlJx8VdZJegxs6wwfqpQ=
|
github.com/bytedance/sonic v1.13.3 h1:MS8gmaH16Gtirygw7jV91pDCN33NyMrPbN7qiYhEsF0=
|
||||||
github.com/bytedance/sonic v1.13.2/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
github.com/bytedance/sonic v1.13.3/go.mod h1:o68xyaF9u2gvVBuGHPlUVCy+ZfmNNO5ETf1+KgkJhz4=
|
||||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||||
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
|
github.com/bytedance/sonic/loader v0.2.4 h1:ZWCw4stuXUsn1/+zQDqeE7JKP+QO47tz7QCNan80NzY=
|
||||||
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
github.com/bytedance/sonic/loader v0.2.4/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user