MCPcopy Create free account
hub / github.com/kataras/iris / RedirectHandler

Function RedirectHandler

core/host/proxy.go:185–205  ·  view source on GitHub ↗

RedirectHandler returns a simple redirect handler. See `NewProxy` or `ProxyHandler` for more features.

(target *url.URL, redirectStatus int)

Source from the content-addressed store, hash-verified

183// RedirectHandler returns a simple redirect handler.
184// See `NewProxy` or `ProxyHandler` for more features.
185func RedirectHandler(target *url.URL, redirectStatus int) http.Handler {
186 targetURI := target.String()
187 if redirectStatus <= 300 {
188 // here we should use StatusPermanentRedirect but
189 // that may result on unexpected behavior
190 // for end-developers who might change their minds
191 // after a while, so keep status temporary.
192 // Note thatwe could also use StatusFound
193 // as we do on the `Context#Redirect`.
194 // It will also help us to prevent any post data issues.
195 redirectStatus = http.StatusTemporaryRedirect
196 }
197
198 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
199 redirectTo := path.Join(targetURI, r.URL.Path)
200 if len(r.URL.RawQuery) > 0 {
201 redirectTo += "?" + r.URL.RawQuery
202 }
203 http.Redirect(w, r, redirectTo, redirectStatus)
204 })
205}

Callers 2

NewRedirectionFunction · 0.85
runTLSMethod · 0.85

Calls 2

RedirectMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…