|
|
|
@ -657,24 +657,32 @@ func testRoute(t *testing.T, test routeTest) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// https://plus.google.com/101022900381697718949/posts/eWy6DjFJ6uW
|
|
|
|
// https://plus.google.com/101022900381697718949/posts/eWy6DjFJ6uW
|
|
|
|
func testSubrouterHeader(t *testing.T, test routeTest) { |
|
|
|
func TestSubrouterHeader(t *testing.T) { |
|
|
|
func1 := func(http.ResponseWriter, *http.Request) {} |
|
|
|
expected := "func1 response" |
|
|
|
|
|
|
|
func1 := func(w http.ResponseWriter, r *http.Request) { |
|
|
|
|
|
|
|
fmt.Fprint(w, expected) |
|
|
|
|
|
|
|
} |
|
|
|
func2 := func(http.ResponseWriter, *http.Request) {} |
|
|
|
func2 := func(http.ResponseWriter, *http.Request) {} |
|
|
|
|
|
|
|
|
|
|
|
r := NewRouter() |
|
|
|
r := NewRouter() |
|
|
|
s := r.Headers("SomeSpecialHeader").Subrouter() |
|
|
|
s := r.Headers("SomeSpecialHeader", "").Subrouter() |
|
|
|
s.HandleFunc("/", func1).Name("func1") |
|
|
|
s.HandleFunc("/", func1).Name("func1") |
|
|
|
r.HandleFunc("/", func2).Name("func2") |
|
|
|
r.HandleFunc("/", func2).Name("func2") |
|
|
|
|
|
|
|
|
|
|
|
req, _ := http.NewRequest("GET", "http://localhost/", nil) |
|
|
|
req, _ := http.NewRequest("GET", "http://localhost/", nil) |
|
|
|
req.Header.Add("SomeSpecialHeader", "") |
|
|
|
req.Header.Add("SomeSpecialHeader", "foo") |
|
|
|
match := new(RouteMatch) |
|
|
|
match := new(RouteMatch) |
|
|
|
matched := r.Match(req, match) |
|
|
|
matched := r.Match(req, match) |
|
|
|
if !matched { |
|
|
|
if !matched { |
|
|
|
t.Errorf("Should match request") |
|
|
|
t.Errorf("Should match request") |
|
|
|
} |
|
|
|
} |
|
|
|
if match.Route.GetName() != "func1" { |
|
|
|
if match.Route.GetName() != "func1" { |
|
|
|
t.Errorf("Expecting func1 handler") |
|
|
|
t.Errorf("Expecting func1 handler, got %s", match.Route.GetName()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
resp := NewRecorder() |
|
|
|
|
|
|
|
match.Handler.ServeHTTP(resp, req) |
|
|
|
|
|
|
|
if resp.Body.String() != expected { |
|
|
|
|
|
|
|
t.Errorf("Expecting %q", expected) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|