MCPcopy Create free account
hub / github.com/golang/appengine / TestRemoteAddr

Function TestRemoteAddr

internal/api_test.go:381–417  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

379}
380
381func TestRemoteAddr(t *testing.T) {
382 var addr string
383 http.HandleFunc("/remote_addr", func(w http.ResponseWriter, r *http.Request) {
384 addr = r.RemoteAddr
385 })
386
387 testCases := []struct {
388 headers http.Header
389 addr string
390 }{
391 {http.Header{"X-Appengine-User-Ip": []string{"10.5.2.1"}}, "10.5.2.1:80"},
392 {http.Header{"X-Appengine-Remote-Addr": []string{"1.2.3.4"}}, "1.2.3.4:80"},
393 {http.Header{"X-Appengine-Remote-Addr": []string{"1.2.3.4:8080"}}, "1.2.3.4:8080"},
394 {
395 http.Header{"X-Appengine-Remote-Addr": []string{"2401:fa00:9:1:7646:a0ff:fe90:ca66"}},
396 "[2401:fa00:9:1:7646:a0ff:fe90:ca66]:80",
397 },
398 {
399 http.Header{"X-Appengine-Remote-Addr": []string{"[::1]:http"}},
400 "[::1]:http",
401 },
402 {http.Header{}, "127.0.0.1:80"},
403 }
404
405 for _, tc := range testCases {
406 r := &http.Request{
407 Method: "GET",
408 URL: &url.URL{Scheme: "http", Path: "/remote_addr"},
409 Header: tc.headers,
410 Body: ioutil.NopCloser(bytes.NewReader(nil)),
411 }
412 Middleware(http.DefaultServeMux).ServeHTTP(httptest.NewRecorder(), r)
413 if addr != tc.addr {
414 t.Errorf("Header %v, got %q, want %q", tc.headers, addr, tc.addr)
415 }
416 }
417}
418
419func TestPanickingHandler(t *testing.T) {
420 http.HandleFunc("/panic", func(http.ResponseWriter, *http.Request) {

Callers

nothing calls this directly

Calls 2

MiddlewareFunction · 0.70
ServeHTTPMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…