1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-10 05:25:58 +00:00
Former-commit-id: 5576c44b64014fb00dd79e618b815b5f52b705e4
This commit is contained in:
Gerasimos Maropoulos
2018-03-10 14:22:56 +02:00
parent 1165b4527a
commit 4993918a12
11 changed files with 131 additions and 364 deletions

View File

@@ -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
}

View File

@@ -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.