Browse Source

Prefer scheme on child route when building URLs.

pull/281/head
Chris Hines 9 years ago committed by Kamil Kisiel
parent
commit
ac112f7d75
  1. 11
      mux_test.go
  2. 2
      route.go

11
mux_test.go

@ -1226,6 +1226,17 @@ func TestSubRouter(t *testing.T) { @@ -1226,6 +1226,17 @@ func TestSubRouter(t *testing.T) {
hostTemplate: `google.com`,
shouldMatch: true,
},
{
title: "Prefer scheme on child route when building URLs",
route: new(Route).Schemes("https", "ftp").Host("google.com").Subrouter().Schemes("ftp").Path("/"),
request: newRequest("GET", "ftp://google.com/"),
scheme: "ftp",
host: "google.com",
path: "/",
pathTemplate: `/`,
hostTemplate: `google.com`,
shouldMatch: true,
},
}
for _, test := range tests {

2
route.go

@ -396,7 +396,7 @@ func (r *Route) Schemes(schemes ...string) *Route { @@ -396,7 +396,7 @@ func (r *Route) Schemes(schemes ...string) *Route {
for k, v := range schemes {
schemes[k] = strings.ToLower(v)
}
if r.getBuildScheme() == "" && len(schemes) > 0 {
if r.buildScheme == "" && len(schemes) > 0 {
r.buildScheme = schemes[0]
}
return r.addMatcher(schemeMatcher(schemes))

Loading…
Cancel
Save