mirror of
https://github.com/kataras/iris.git
synced 2026-01-08 12:31:58 +00:00
Fix https://github.com/iris-contrib/community-board/issues/10 and upgrade the minor version number
Former-commit-id: 02f6656aceb890217bfc19688d7f45224df274ec
This commit is contained in:
@@ -147,6 +147,7 @@ func (rb *APIBuilder) Handle(method string, registeredPath string, handlers ...c
|
||||
}
|
||||
// global
|
||||
rb.routes.register(r)
|
||||
|
||||
// per -party
|
||||
rb.apiRoutes = append(rb.apiRoutes, r)
|
||||
// should we remove the rb.apiRoutes on the .Party (new children party) ?, No, because the user maybe use this party later
|
||||
@@ -163,6 +164,11 @@ func (rb *APIBuilder) Party(relativePath string, handlers ...context.Handler) Pa
|
||||
parentPath = parentPath[1:] // remove first slash
|
||||
}
|
||||
|
||||
// this is checked later on but for easier debug is better to do it here:
|
||||
if rb.relativePath[0] == '/' && relativePath[0] == '/' {
|
||||
parentPath = parentPath[1:] // remove first slash if parent ended with / and new one started with /.
|
||||
}
|
||||
|
||||
fullpath := parentPath + relativePath
|
||||
// append the parent's +child's handlers
|
||||
middleware := joinHandlers(rb.middleware, handlers)
|
||||
|
||||
@@ -60,7 +60,6 @@ func (h *routerHandler) addRoute(method, subdomain, path string, handlers contex
|
||||
t = &tree{Method: method, Subdomain: subdomain, Nodes: &n}
|
||||
h.trees = append(h.trees, t)
|
||||
}
|
||||
|
||||
return t.Nodes.Add(path, handlers)
|
||||
}
|
||||
|
||||
@@ -99,7 +98,6 @@ func (h *routerHandler) Build(provider RoutesProvider) error {
|
||||
func (h *routerHandler) HandleRequest(ctx context.Context) {
|
||||
method := ctx.Method()
|
||||
path := ctx.Path()
|
||||
|
||||
if !ctx.Application().ConfigurationReadOnly().GetDisablePathCorrection() {
|
||||
|
||||
if len(path) > 1 && path[len(path)-1] == '/' {
|
||||
@@ -165,7 +163,6 @@ func (h *routerHandler) HandleRequest(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
handlers := t.Nodes.Find(path, ctx.Params())
|
||||
if len(handlers) > 0 {
|
||||
ctx.Do(handlers)
|
||||
|
||||
@@ -183,6 +183,12 @@ func compileRoutePathAndHandlers(handlers context.Handlers, tmpl *macro.Template
|
||||
|
||||
func convertTmplToNodePath(tmpl *macro.Template) (string, error) {
|
||||
routePath := tmpl.Src
|
||||
if len(tmpl.Params) > 0 {
|
||||
if routePath[len(routePath)-1] == '/' {
|
||||
routePath = routePath[0 : len(routePath)-2] // remove the last "/" if macro syntax instead of underline's
|
||||
}
|
||||
}
|
||||
|
||||
// if it has started with {} and it's valid
|
||||
// then the tmpl.Params will be filled,
|
||||
// so no any further check needed
|
||||
@@ -191,7 +197,6 @@ func convertTmplToNodePath(tmpl *macro.Template) (string, error) {
|
||||
if i != len(tmpl.Params)-1 {
|
||||
return "", errors.New("parameter type \"ParamTypePath\" should be putted to the very last of a path")
|
||||
}
|
||||
|
||||
routePath = strings.Replace(routePath, p.Src, WildcardParam(p.Name), 1)
|
||||
} else {
|
||||
routePath = strings.Replace(routePath, p.Src, Param(p.Name), 1)
|
||||
@@ -210,13 +215,15 @@ func convertTmplToHandler(tmpl *macro.Template) context.Handler {
|
||||
// 1. if we don't have, then we don't need to add a handler before the main route's handler (as I said, no performance if macro is not really used)
|
||||
// 2. if we don't have any named params then we don't need a handler too.
|
||||
for _, p := range tmpl.Params {
|
||||
if len(p.Funcs) == 0 && (p.Type == ast.ParamTypeString || p.Type == ast.ParamTypePath) && p.ErrCode == http.StatusNotFound {
|
||||
if len(p.Funcs) == 0 && (p.Type == ast.ParamTypeUnExpected || p.Type == ast.ParamTypeString || p.Type == ast.ParamTypePath) && p.ErrCode == http.StatusNotFound {
|
||||
} else {
|
||||
// println("we need handler for: " + tmpl.Src)
|
||||
needMacroHandler = true
|
||||
}
|
||||
}
|
||||
|
||||
if !needMacroHandler {
|
||||
// println("we don't need handler for: " + tmpl.Src)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ func (nodes *Nodes) Add(path string, handlers context.Handlers) error {
|
||||
return err
|
||||
}
|
||||
// create a second, empty, dynamic parameter node without the last slash
|
||||
if nidx := idx + 1; len(path) < nidx {
|
||||
if nidx := idx + 1; len(path) > nidx {
|
||||
if err := nodes.add(path[:nidx], nil, nil, true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -102,6 +102,12 @@ func newSubdomainDivider(sep string) unis.DividerFunc {
|
||||
subdomainDevider := unis.NewInvertOnFailureDivider(unis.NewDivider(sep))
|
||||
return func(fullpath string) (string, string) {
|
||||
subdomain, path := subdomainDevider.Divide(fullpath)
|
||||
if len(path) > 1 {
|
||||
if path[0] == '/' && path[1] == '/' {
|
||||
path = path[1:]
|
||||
}
|
||||
}
|
||||
|
||||
return subdomain, path //cleanPath(path)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user