Changes regarding comment.

Used http status code instead of a hardcoded value.
Used url.Parse instead of url.ParseRequestURI, so that you can parse
both absolute and relative URL.
This commit is contained in:
Maxime 2015-07-12 16:43:35 +02:00
parent 8a2d0890a2
commit eea68c34ad

View File

@ -23,9 +23,9 @@ func (rd Redirect) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
for _, rule := range rd.Rules {
if rule.From == "/" {
// Catchall redirect preserves path (TODO: Standardize/formalize this behavior)
toURL, err := url.ParseRequestURI(rule.To)
toURL, err := url.Parse(rule.To)
if err != nil {
return 500, err
return http.StatusInternalServerError, err
}
newPath := toURL.Host + toURL.Path + r.URL.Path
rmSlashs := regexp.MustCompile("//+")