MCPcopy Create free account
hub / github.com/kataras/iris / HandleRequest

Method HandleRequest

core/router/handler.go:452–532  ·  view source on GitHub ↗
(ctx *context.Context)

Source from the content-addressed store, hash-verified

450}
451
452func (h *routerHandler) HandleRequest(ctx *context.Context) {
453 method := ctx.Method()
454 path := ctx.Path()
455
456 if !h.disablePathCorrection {
457 if len(path) > 1 && strings.HasSuffix(path, "/") {
458 // Remove trailing slash and client-permanent rule for redirection,
459 // if confgiuration allows that and path has an extra slash.
460
461 // update the new path and redirect.
462 u := ctx.Request().URL
463 // use Trim to ensure there is no open redirect due to two leading slashes
464 path = "/" + strings.Trim(path, "/")
465 u.Path = path
466 if !h.disablePathCorrectionRedirection {
467 // do redirect, else continue with the modified path without the last "/".
468 url := u.String()
469
470 // Fixes https://github.com/kataras/iris/issues/921
471 // This is caused for security reasons, imagine a payment shop,
472 // you can't just permantly redirect a POST request, so just 307 (RFC 7231, 6.4.7).
473 if method == http.MethodPost || method == http.MethodPut {
474 ctx.Redirect(url, http.StatusTemporaryRedirect)
475 return
476 }
477
478 ctx.Redirect(url, http.StatusMovedPermanently)
479 return
480 }
481
482 }
483 }
484
485 for i := range h.trees {
486 t := h.trees[i]
487 if method != t.method {
488 continue
489 }
490
491 if h.hosts && !canHandleSubdomain(ctx, t.subdomain) {
492 continue
493 }
494
495 n := t.search(path, ctx.Params())
496 if n != nil {
497 ctx.SetCurrentRoute(n.Route)
498 ctx.Do(n.Handlers)
499 // found
500 return
501 }
502 // not found or method not allowed.
503 break
504 }
505
506 if h.fireMethodNotAllowed {
507 for i := range h.trees {
508 t := h.trees[i]
509 // if `Configuration#FireMethodNotAllowed` is kept as defaulted(false) then this function will not

Callers

nothing calls this directly

Calls 14

canHandleSubdomainFunction · 0.85
RequestMethod · 0.80
RedirectMethod · 0.80
searchMethod · 0.80
ParamsMethod · 0.80
SetCurrentRouteMethod · 0.80
FindClosestMethod · 0.80
MethodMethod · 0.65
PathMethod · 0.65
StringMethod · 0.65
StatusCodeMethod · 0.65

Tested by

no test coverage detected