mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Former-commit-id: ca8bebf64f71d84a13f95295863e17dd72fbb9f5
This commit is contained in:
parent
d5974f6411
commit
10656e171d
16
context.go
16
context.go
|
@ -732,9 +732,21 @@ func (ctx *Context) Redirect(urlToRedirect string, statusHeader ...int) {
|
|||
httpStatus = statusHeader[0]
|
||||
}
|
||||
|
||||
if urlToRedirect == ctx.Path() {
|
||||
ctx.Log(DevMode, "trying to redirect to itself. FROM: %s TO: %s", ctx.Path(), urlToRedirect)
|
||||
// we don't know the Method of the url to redirect,
|
||||
// sure we can find it by reverse routing as we already implemented
|
||||
// but it will take too much time for a simple redirect, it doesn't worth it.
|
||||
// So we are checking the CURRENT Method for GET, HEAD, CONNECT and TRACE.
|
||||
// the
|
||||
// Fixes: http: //support.iris-go.com/d/21-wrong-warning-message-while-redirecting
|
||||
shouldCheckForCycle := urlToRedirect == ctx.Path() && ctx.Method() == MethodGet
|
||||
// from POST to GET on the same path will give a warning message but developers don't use the iris.DevLogger
|
||||
// for production, so I assume it's OK to let it logs it
|
||||
// (it can solve issues when developer redirects to the same handler over and over again)
|
||||
// Note: it doesn't stops the redirect, the developer gets what he/she expected.
|
||||
if shouldCheckForCycle {
|
||||
ctx.Log(DevMode, "warning: redirect from: '%s' to: '%s',\ncurrent method: '%s'", ctx.Path(), urlToRedirect, ctx.Method())
|
||||
}
|
||||
|
||||
http.Redirect(ctx.ResponseWriter, ctx.Request, urlToRedirect, httpStatus)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user