Commit 016344ba authored by Abiola Ibrahim's avatar Abiola Ibrahim

Rewrite: Use middleware.Replacer for simple rule.

parent 0b513699
......@@ -52,7 +52,11 @@ func (s SimpleRule) Rewrite(r *http.Request) bool {
// take note of this rewrite for internal use by fastcgi
// all we need is the URI, not full URL
r.Header.Set(headerFieldName, r.URL.RequestURI())
r.URL.Path = s.To
// replace variables
to := path.Clean(middleware.NewReplacer(r, nil, "").Replace(s.To))
r.URL.Path = to
return true
}
return false
......
......@@ -17,6 +17,7 @@ func TestRewrite(t *testing.T) {
Rules: []Rule{
NewSimpleRule("/from", "/to"),
NewSimpleRule("/a", "/b"),
NewSimpleRule("/b", "/b{uri}"),
},
}
......@@ -50,6 +51,7 @@ func TestRewrite(t *testing.T) {
}{
{"/from", "/to"},
{"/a", "/b"},
{"/b", "/b/b"},
{"/aa", "/aa"},
{"/", "/"},
{"/a?foo=bar", "/b?foo=bar"},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment