1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-23 20:05:59 +00:00

add 'Configuration.PathIntelligence' and 'OnErrorCode' and 'OnAnyErrorCode' on APIContainer

Former-commit-id: bc3d0232106622063205f326bfa4ed3aa84179de
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-05-17 08:10:07 +03:00
parent 21a013569f
commit 1e20996330
10 changed files with 104 additions and 27 deletions

View File

@@ -417,6 +417,16 @@ func (h *routerHandler) HandleRequest(ctx context.Context) {
}
}
if config.GetEnablePathIntelligence() && method == http.MethodGet {
closestPaths := ctx.FindClosest(1)
if len(closestPaths) > 0 {
u := ctx.Request().URL
u.Path = closestPaths[0]
ctx.Redirect(u.String(), http.StatusMovedPermanently)
return
}
}
ctx.StatusCode(http.StatusNotFound)
}