From 353d858f2f85d602b88f78ab253b1dcf76d7196a Mon Sep 17 00:00:00 2001 From: Jeevanandam M Date: Fri, 17 Aug 2018 21:51:26 -0700 Subject: [PATCH] #208 fixed redirect issue --- aah.go | 5 +++-- http_engine.go | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/aah.go b/aah.go index c8f0e049..b3a816aa 100644 --- a/aah.go +++ b/aah.go @@ -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) diff --git a/http_engine.go b/http_engine.go index 11070a9a..497a2e52 100644 --- a/http_engine.go +++ b/http_engine.go @@ -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) @@ -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 }