mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-07 04:38:19 +08:00
test(context): add test for ClientIP method with no valid forwarded headers
This commit is contained in:
parent
9ef3ade402
commit
334dbdb8ac
@ -1984,6 +1984,12 @@ func TestContextClientIP(t *testing.T) {
|
||||
c.Request.RemoteAddr = addr.String()
|
||||
assert.Equal(t, "20.20.20.20", c.ClientIP())
|
||||
|
||||
// unix address with no valid forwarded header: remoteIP stays zero, must return ""
|
||||
c.Request.Header.Del("X-Forwarded-For")
|
||||
c.Request.Header.Del("X-Real-IP")
|
||||
assert.Empty(t, c.ClientIP())
|
||||
resetContextForClientIPTests(c)
|
||||
|
||||
// reset
|
||||
c.Request = c.Request.WithContext(context.Background())
|
||||
resetContextForClientIPTests(c)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user