mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 05:25:58 +00:00
remove the complicated fallback handlers, that didn't work and not approve the coblexity addition of the https://github.com/kataras/iris/pull/919, RouteExists accepts first argument the Context, add new AllowMethods per party and fix cors by 048e2be034 https://github.com/kataras/iris/issues/922, rel: https://github.com/iris-contrib/middleware/issues/36, https://github.com/iris-contrib/middleware/issues/34, https://github.com/iris-contrib/middleware/issues/32, https://github.com/iris-contrib/middleware/issues/30, https://github.com/kataras/iris/pull/909
Former-commit-id: 5576c44b64014fb00dd79e618b815b5f52b705e4
This commit is contained in:
@@ -49,6 +49,7 @@ type Application interface {
|
||||
// then it creates & registers a new trivial handler on the-fly.
|
||||
FireErrorCode(ctx Context)
|
||||
|
||||
// RouteExists checks if a route exists
|
||||
RouteExists(method string, path string, ctx Context) bool
|
||||
// RouteExists reports whether a particular route exists
|
||||
// It will search from the current subdomain of context's host, if not inside the root domain.
|
||||
RouteExists(ctx Context, method, path string) bool
|
||||
}
|
||||
|
||||
@@ -910,7 +910,7 @@ type Context interface {
|
||||
// TransactionsSkipped returns true if the transactions skipped or canceled at all.
|
||||
TransactionsSkipped() bool
|
||||
|
||||
// Exec calls the framewrok's ServeCtx
|
||||
// Exec calls the `context/Application#ServeCtx`
|
||||
// based on this context but with a changed method and path
|
||||
// like it was requested by the user, but it is not.
|
||||
//
|
||||
@@ -933,10 +933,11 @@ type Context interface {
|
||||
// Context's Values and the Session are kept in order to be able to communicate via the result route.
|
||||
//
|
||||
// It's for extreme use cases, 99% of the times will never be useful for you.
|
||||
Exec(method string, path string)
|
||||
Exec(method, path string)
|
||||
|
||||
// RouteExists checks if a route exists
|
||||
RouteExists(method string, path string) bool
|
||||
// RouteExists reports whether a particular route exists
|
||||
// It will search from the current subdomain of context's host, if not inside the root domain.
|
||||
RouteExists(method, path string) bool
|
||||
|
||||
// Application returns the iris app instance which belongs to this context.
|
||||
// Worth to notice that this function returns an interface
|
||||
@@ -3164,53 +3165,57 @@ func (ctx *context) TransactionsSkipped() bool {
|
||||
//
|
||||
// It's for extreme use cases, 99% of the times will never be useful for you.
|
||||
func (ctx *context) Exec(method string, path string) {
|
||||
if path != "" {
|
||||
if method == "" {
|
||||
method = "GET"
|
||||
}
|
||||
|
||||
// backup the handlers
|
||||
backupHandlers := ctx.Handlers()[0:]
|
||||
backupPos := ctx.HandlerIndex(-1)
|
||||
|
||||
// backup the request path information
|
||||
backupPath := ctx.Path()
|
||||
backupMethod := ctx.Method()
|
||||
// don't backupValues := ctx.Values().ReadOnly()
|
||||
|
||||
// [sessions stays]
|
||||
// [values stays]
|
||||
// reset handlers
|
||||
ctx.SetHandlers(nil)
|
||||
|
||||
req := ctx.Request()
|
||||
// set the request to be align with the 'againstRequestPath'
|
||||
req.RequestURI = path
|
||||
req.URL.Path = path
|
||||
req.Method = method
|
||||
// execute the route from the (internal) context router
|
||||
// this way we keep the sessions and the values
|
||||
ctx.Application().ServeHTTPC(ctx)
|
||||
|
||||
// set back the old handlers and the last known index
|
||||
ctx.SetHandlers(backupHandlers)
|
||||
ctx.HandlerIndex(backupPos)
|
||||
// set the request back to its previous state
|
||||
req.RequestURI = backupPath
|
||||
req.URL.Path = backupPath
|
||||
req.Method = backupMethod
|
||||
|
||||
// don't fill the values in order to be able to communicate from and to.
|
||||
// // fill the values as they were before
|
||||
// backupValues.Visit(func(key string, value interface{}) {
|
||||
// ctx.Values().Set(key, value)
|
||||
// })
|
||||
if path == "" {
|
||||
return
|
||||
}
|
||||
|
||||
if method == "" {
|
||||
method = "GET"
|
||||
}
|
||||
|
||||
// backup the handlers
|
||||
backupHandlers := ctx.Handlers()[0:]
|
||||
backupPos := ctx.HandlerIndex(-1)
|
||||
|
||||
// backup the request path information
|
||||
backupPath := ctx.Path()
|
||||
backupMethod := ctx.Method()
|
||||
// don't backupValues := ctx.Values().ReadOnly()
|
||||
|
||||
// [values stays]
|
||||
// reset handlers
|
||||
ctx.SetHandlers(nil)
|
||||
|
||||
req := ctx.Request()
|
||||
// set the request to be align with the 'againstRequestPath'
|
||||
req.RequestURI = path
|
||||
req.URL.Path = path
|
||||
req.Method = method
|
||||
req.Host = req.Host
|
||||
|
||||
// execute the route from the (internal) context router
|
||||
// this way we keep the sessions and the values
|
||||
ctx.Application().ServeHTTPC(ctx)
|
||||
|
||||
// set back the old handlers and the last known index
|
||||
ctx.SetHandlers(backupHandlers)
|
||||
ctx.HandlerIndex(backupPos)
|
||||
// set the request back to its previous state
|
||||
req.RequestURI = backupPath
|
||||
req.URL.Path = backupPath
|
||||
req.Method = backupMethod
|
||||
|
||||
// don't fill the values in order to be able to communicate from and to.
|
||||
// // fill the values as they were before
|
||||
// backupValues.Visit(func(key string, value interface{}) {
|
||||
// ctx.Values().Set(key, value)
|
||||
// })
|
||||
}
|
||||
|
||||
// RouteExists checks if a route exists
|
||||
func (ctx *context) RouteExists(method string, path string) bool {
|
||||
return ctx.Application().RouteExists(method, path, ctx)
|
||||
// RouteExists reports whether a particular route exists
|
||||
// It will search from the current subdomain of context's host, if not inside the root domain.
|
||||
func (ctx *context) RouteExists(method, path string) bool {
|
||||
return ctx.Application().RouteExists(ctx, method, path)
|
||||
}
|
||||
|
||||
// Application returns the iris app instance which belongs to this context.
|
||||
|
||||
Reference in New Issue
Block a user