forked from mirror/gin
chore: update go.mod and remove space from copyright (#3158)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
parent
ed03102ef0
commit
4b68a5f12a
|
@ -1,3 +1,7 @@
|
|||
// Copyright 2022 Gin Core Team. All rights reserved.
|
||||
// Use of this source code is governed by a MIT style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package binding
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// Copyright 2022 Gin Core Team. All rights reserved.
|
||||
// Use of this source code is governed by a MIT style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package binding
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// Copyright 2022 Gin Core Team. All rights reserved.
|
||||
// Use of this source code is governed by a MIT style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package binding
|
||||
|
||||
import (
|
||||
|
|
|
@ -17,6 +17,16 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type interceptedWriter struct {
|
||||
ResponseWriter
|
||||
b *bytes.Buffer
|
||||
}
|
||||
|
||||
func (i interceptedWriter) WriteHeader(code int) {
|
||||
i.Header().Del("X-Test")
|
||||
i.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func TestContextFormFileFailed17(t *testing.T) {
|
||||
buf := new(bytes.Buffer)
|
||||
mw := multipart.NewWriter(buf)
|
||||
|
@ -31,3 +41,32 @@ func TestContextFormFileFailed17(t *testing.T) {
|
|||
assert.Nil(t, f)
|
||||
})
|
||||
}
|
||||
|
||||
func TestInterceptedHeader(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
c, r := CreateTestContext(w)
|
||||
|
||||
r.Use(func(c *Context) {
|
||||
i := interceptedWriter{
|
||||
ResponseWriter: c.Writer,
|
||||
b: bytes.NewBuffer(nil),
|
||||
}
|
||||
c.Writer = i
|
||||
c.Next()
|
||||
c.Header("X-Test", "overridden")
|
||||
c.Writer = i.ResponseWriter
|
||||
})
|
||||
r.GET("/", func(c *Context) {
|
||||
c.Header("X-Test", "original")
|
||||
c.Header("X-Test-2", "present")
|
||||
c.String(http.StatusOK, "hello world")
|
||||
})
|
||||
c.Request = httptest.NewRequest("GET", "/", nil)
|
||||
r.HandleContext(c)
|
||||
// Result() has headers frozen when WriteHeaderNow() has been called
|
||||
// Compared to this time, this is when the response headers will be flushed
|
||||
// As response is flushed on c.String, the Header cannot be set by the first
|
||||
// middleware. Assert this
|
||||
assert.Equal(t, "", w.Result().Header.Get("X-Test"))
|
||||
assert.Equal(t, "present", w.Result().Header.Get("X-Test-2"))
|
||||
}
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
// +build go1.7
|
||||
|
||||
package gin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type interceptedWriter struct {
|
||||
ResponseWriter
|
||||
b *bytes.Buffer
|
||||
}
|
||||
|
||||
func (i interceptedWriter) WriteHeader(code int) {
|
||||
i.Header().Del("X-Test")
|
||||
i.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
func TestInterceptedHeader(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
c, r := CreateTestContext(w)
|
||||
|
||||
r.Use(func(c *Context) {
|
||||
i := interceptedWriter{
|
||||
ResponseWriter: c.Writer,
|
||||
b: bytes.NewBuffer(nil),
|
||||
}
|
||||
c.Writer = i
|
||||
c.Next()
|
||||
c.Header("X-Test", "overridden")
|
||||
c.Writer = i.ResponseWriter
|
||||
})
|
||||
r.GET("/", func(c *Context) {
|
||||
c.Header("X-Test", "original")
|
||||
c.Header("X-Test-2", "present")
|
||||
c.String(http.StatusOK, "hello world")
|
||||
})
|
||||
c.Request = httptest.NewRequest("GET", "/", nil)
|
||||
r.HandleContext(c)
|
||||
// Result() has headers frozen when WriteHeaderNow() has been called
|
||||
// Compared to this time, this is when the response headers will be flushed
|
||||
// As response is flushed on c.String, the Header cannot be set by the first
|
||||
// middleware. Assert this
|
||||
assert.Equal(t, "", w.Result().Header.Get("X-Test"))
|
||||
assert.Equal(t, "present", w.Result().Header.Get("X-Test-2"))
|
||||
}
|
2
go.mod
2
go.mod
|
@ -8,7 +8,7 @@ require (
|
|||
github.com/goccy/go-json v0.9.7
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/mattn/go-isatty v0.0.14
|
||||
github.com/pelletier/go-toml/v2 v2.0.0-beta.6
|
||||
github.com/pelletier/go-toml/v2 v2.0.1
|
||||
github.com/stretchr/testify v1.7.1
|
||||
github.com/ugorji/go/codec v1.2.7
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
|
||||
|
|
6
go.sum
6
go.sum
|
@ -36,8 +36,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OH
|
|||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pelletier/go-toml/v2 v2.0.0-beta.6 h1:JFNqj2afbbhCqTiyN16D7Tudc/aaDzE2FBDk+VlBQnE=
|
||||
github.com/pelletier/go-toml/v2 v2.0.0-beta.6/go.mod h1:ke6xncR3W76Ba8xnVxkrZG0js6Rd2BsQEAYrfgJ6eQA=
|
||||
github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU=
|
||||
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
|
@ -48,10 +48,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo=
|
||||
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
||||
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
|
||||
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
// Copyright 2022 Gin Core Team. All rights reserved.
|
||||
// Use of this source code is governed by a MIT style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package render
|
||||
|
||||
import (
|
||||
|
|
Loading…
Reference in New Issue