(c *Context)
| 688 | } |
| 689 | |
| 690 | func (engine *Engine) handleHTTPRequest(c *Context) { |
| 691 | httpMethod := c.Request.Method |
| 692 | rPath := c.Request.URL.Path |
| 693 | unescape := false |
| 694 | |
| 695 | if engine.UseEscapedPath { |
| 696 | rPath = c.Request.URL.EscapedPath() |
| 697 | unescape = engine.UnescapePathValues |
| 698 | } else if engine.UseRawPath && len(c.Request.URL.RawPath) > 0 { |
| 699 | rPath = c.Request.URL.RawPath |
| 700 | unescape = engine.UnescapePathValues |
| 701 | } |
| 702 | |
| 703 | if engine.RemoveExtraSlash { |
| 704 | rPath = cleanPath(rPath) |
| 705 | } |
| 706 | |
| 707 | // Find root of the tree for the given HTTP method |
| 708 | t := engine.trees |
| 709 | for i, tl := 0, len(t); i < tl; i++ { |
| 710 | if t[i].method != httpMethod { |
| 711 | continue |
| 712 | } |
| 713 | root := t[i].root |
| 714 | // Find route in tree |
| 715 | value := root.getValue(rPath, c.params, c.skippedNodes, unescape) |
| 716 | if value.params != nil { |
| 717 | c.Params = *value.params |
| 718 | } |
| 719 | if value.handlers != nil { |
| 720 | c.handlers = value.handlers |
| 721 | c.fullPath = value.fullPath |
| 722 | c.Next() |
| 723 | c.writermem.WriteHeaderNow() |
| 724 | return |
| 725 | } |
| 726 | if httpMethod != http.MethodConnect && rPath != "/" { |
| 727 | if value.tsr && engine.RedirectTrailingSlash { |
| 728 | redirectTrailingSlash(c) |
| 729 | return |
| 730 | } |
| 731 | if engine.RedirectFixedPath && redirectFixedPath(c, root, engine.RedirectFixedPath) { |
| 732 | return |
| 733 | } |
| 734 | } |
| 735 | break |
| 736 | } |
| 737 | |
| 738 | if engine.HandleMethodNotAllowed && len(t) > 0 { |
| 739 | // According to RFC 7231 section 6.5.5, MUST generate an Allow header field in response |
| 740 | // containing a list of the target resource's currently supported methods. |
| 741 | allowed := make([]string, 0, len(t)-1) |
| 742 | for _, tree := range engine.trees { |
| 743 | if tree.method == httpMethod { |
| 744 | continue |
| 745 | } |
| 746 | if value := tree.root.getValue(rPath, nil, c.skippedNodes, unescape); value.handlers != nil { |
| 747 | allowed = append(allowed, tree.method) |
no test coverage detected