Skip to content

Commit

Permalink
#208 fixed redirect issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm committed Aug 18, 2018
1 parent da81cf3 commit 353d858
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions aah.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,9 @@ func (a *app) aahRecover() {
func (a *app) ServeHTTP(w http.ResponseWriter, r *http.Request) {
defer a.aahRecover()
if a.redirect {
a.he.doRedirect(w, r)
return
if a.he.doRedirect(w, r) {
return
}
}

upgrade := r.Header.Get(ahttp.HeaderUpgrade)
Expand Down
6 changes: 5 additions & 1 deletion http_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ const (
nonwww = "non-www"
)

func (e *HTTPEngine) doRedirect(w http.ResponseWriter, r *http.Request) {
func (e *HTTPEngine) doRedirect(w http.ResponseWriter, r *http.Request) bool {
cfg := e.a.Config()
redirectTo := cfg.StringDefault("server.redirect.to", nonwww)
redirectCode := cfg.IntDefault("server.redirect.code", http.StatusMovedPermanently)
Expand All @@ -442,10 +442,14 @@ func (e *HTTPEngine) doRedirect(w http.ResponseWriter, r *http.Request) {
case www:
if host[:3] != www {
http.Redirect(w, r, ahttp.Scheme(r)+"://www."+host+r.URL.RequestURI(), redirectCode)
return true
}

case nonwww:
if host[:3] == www {
http.Redirect(w, r, ahttp.Scheme(r)+"://"+host[4:]+r.URL.RequestURI(), redirectCode)
return true
}
}
return false
}

0 comments on commit 353d858

Please sign in to comment.