mirror of
https://github.com/gin-gonic/gin.git
synced 2026-07-16 00:01:25 +08:00
test: used http.MethodGet instead constants and fix lints
This commit is contained in:
parent
d89b7fee9e
commit
8b2b6f8ee0
@ -1148,12 +1148,15 @@ func TestContextClientIPWithMultipleHeaders(t *testing.T) {
|
|||||||
engine := New()
|
engine := New()
|
||||||
|
|
||||||
// Set trusted proxies
|
// Set trusted proxies
|
||||||
engine.SetTrustedProxies([]string{"127.0.0.1"})
|
err := engine.SetTrustedProxies([]string{"127.0.0.1"})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed to set trusted proxies: %v", err)
|
||||||
|
}
|
||||||
engine.ForwardedByClientIP = true
|
engine.ForwardedByClientIP = true
|
||||||
engine.RemoteIPHeaders = []string{"X-Forwarded-For"}
|
engine.RemoteIPHeaders = []string{"X-Forwarded-For"}
|
||||||
|
|
||||||
// Create a test request with multiple X-Forwarded-For headers
|
// Create a test request with multiple X-Forwarded-For headers
|
||||||
req := httptest.NewRequest("GET", "/test", nil)
|
req := httptest.NewRequest(http.MethodGet, "/test", nil)
|
||||||
req.Header.Add("X-Forwarded-For", "1.2.3.4, 127.0.0.1")
|
req.Header.Add("X-Forwarded-For", "1.2.3.4, 127.0.0.1")
|
||||||
req.Header.Add("X-Forwarded-For", "5.6.7.8")
|
req.Header.Add("X-Forwarded-For", "5.6.7.8")
|
||||||
req.RemoteAddr = "127.0.0.1:1234"
|
req.RemoteAddr = "127.0.0.1:1234"
|
||||||
@ -1182,7 +1185,7 @@ func TestContextClientIPWithSingleHeader(t *testing.T) {
|
|||||||
engine.ForwardedByClientIP = true
|
engine.ForwardedByClientIP = true
|
||||||
engine.RemoteIPHeaders = []string{"X-Forwarded-For"}
|
engine.RemoteIPHeaders = []string{"X-Forwarded-For"}
|
||||||
|
|
||||||
req := httptest.NewRequest("GET", "/test", nil)
|
req := httptest.NewRequest(http.MethodGet, "/test", nil)
|
||||||
req.Header.Set("X-Forwarded-For", "1.2.3.4, 127.0.0.1")
|
req.Header.Set("X-Forwarded-For", "1.2.3.4, 127.0.0.1")
|
||||||
req.RemoteAddr = "127.0.0.1:1234"
|
req.RemoteAddr = "127.0.0.1:1234"
|
||||||
|
|
||||||
@ -1199,6 +1202,7 @@ func TestContextClientIPWithSingleHeader(t *testing.T) {
|
|||||||
t.Errorf("Expected ClientIP to be %s, got %s", expected, clientIP)
|
t.Errorf("Expected ClientIP to be %s, got %s", expected, clientIP)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tests that the response is serialized as Secure JSON
|
// Tests that the response is serialized as Secure JSON
|
||||||
// and Content-Type is set to application/json
|
// and Content-Type is set to application/json
|
||||||
func TestContextRenderSecureJSON(t *testing.T) {
|
func TestContextRenderSecureJSON(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user