Merge branch 'master' into master

This commit is contained in:
Bo-Yi Wu 2025-12-30 21:46:54 +08:00 committed by GitHub
commit d89b7fee9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 5 deletions

View File

@ -65,7 +65,7 @@ jobs:
with: with:
ref: ${{ github.ref }} ref: ${{ github.ref }}
- uses: actions/cache@v4 - uses: actions/cache@v5
with: with:
path: | path: |
${{ matrix.go-build }} ${{ matrix.go-build }}

View File

@ -1966,7 +1966,7 @@ func TestContextClientIP(t *testing.T) {
resetContextForClientIPTests(c) resetContextForClientIPTests(c)
// IPv6 support // IPv6 support
c.Request.RemoteAddr = "[::1]:12345" c.Request.RemoteAddr = fmt.Sprintf("[%s]:12345", localhostIPv6)
assert.Equal(t, "20.20.20.20", c.ClientIP()) assert.Equal(t, "20.20.20.20", c.ClientIP())
resetContextForClientIPTests(c) resetContextForClientIPTests(c)
@ -3268,7 +3268,7 @@ func TestContextCopyShouldNotCancel(t *testing.T) {
}() }()
addr := strings.Split(l.Addr().String(), ":") addr := strings.Split(l.Addr().String(), ":")
res, err := http.Get(fmt.Sprintf("http://127.0.0.1:%s/", addr[len(addr)-1])) res, err := http.Get(fmt.Sprintf("http://%s:%s/", localhostIP, addr[len(addr)-1]))
if err != nil { if err != nil {
t.Error(fmt.Errorf("request error: %w", err)) t.Error(fmt.Errorf("request error: %w", err))
return return

View File

@ -83,7 +83,7 @@ func TestLoadHTMLGlobDebugMode(t *testing.T) {
} }
func TestH2c(t *testing.T) { func TestH2c(t *testing.T) {
ln, err := net.Listen("tcp", "127.0.0.1:0") ln, err := net.Listen("tcp", localhostIP+":0")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }

View File

@ -128,7 +128,9 @@ func (w *responseWriter) CloseNotify() <-chan bool {
// Flush implements the http.Flusher interface. // Flush implements the http.Flusher interface.
func (w *responseWriter) Flush() { func (w *responseWriter) Flush() {
w.WriteHeaderNow() w.WriteHeaderNow()
w.ResponseWriter.(http.Flusher).Flush() if f, ok := w.ResponseWriter.(http.Flusher); ok {
f.Flush()
}
} }
func (w *responseWriter) Pusher() (pusher http.Pusher) { func (w *responseWriter) Pusher() (pusher http.Pusher) {

View File

@ -19,6 +19,12 @@ import (
// BindKey indicates a default bind key. // BindKey indicates a default bind key.
const BindKey = "_gin-gonic/gin/bindkey" const BindKey = "_gin-gonic/gin/bindkey"
// localhostIP indicates the default localhost IP address.
const localhostIP = "127.0.0.1"
// localhostIPv6 indicates the default localhost IPv6 address.
const localhostIPv6 = "::1"
// Bind is a helper function for given interface object and returns a Gin middleware. // Bind is a helper function for given interface object and returns a Gin middleware.
func Bind(val any) HandlerFunc { func Bind(val any) HandlerFunc {
value := reflect.ValueOf(val) value := reflect.ValueOf(val)