MCPcopy
hub / github.com/go-chi/chi / TestXRealIP

Function TestXRealIP

middleware/realip_test.go:11–33  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestXRealIP(t *testing.T) {
12 req, _ := http.NewRequest("GET", "/", nil)
13 req.Header.Add("X-Real-IP", "100.100.100.100")
14 w := httptest.NewRecorder()
15
16 r := chi.NewRouter()
17 r.Use(RealIP)
18
19 realIP := ""
20 r.Get("/", func(w http.ResponseWriter, r *http.Request) {
21 realIP = r.RemoteAddr
22 w.Write([]byte("Hello World"))
23 })
24 r.ServeHTTP(w, req)
25
26 if w.Code != 200 {
27 t.Fatal("Response Code should be 200")
28 }
29
30 if realIP != "100.100.100.100" {
31 t.Fatal("Test get real IP error.")
32 }
33}
34
35func TestXForwardForIP(t *testing.T) {
36 xForwardedForIPs := []string{

Callers

nothing calls this directly

Calls 5

UseMethod · 0.95
GetMethod · 0.95
AddMethod · 0.80
WriteMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected