(ctx *context.Context, t *trie, method, path string)
| 652 | } |
| 653 | |
| 654 | func (h *routerHandler) subdomainAndPathAndMethodExists(ctx *context.Context, t *trie, method, path string) bool { |
| 655 | if method != "" && method != t.method { |
| 656 | return false |
| 657 | } |
| 658 | |
| 659 | if h.hosts && t.subdomain != "" { |
| 660 | requestHost := ctx.Host() |
| 661 | if netutil.IsLoopbackSubdomain(requestHost) { |
| 662 | // this fixes a bug when listening on |
| 663 | // 127.0.0.1:8080 for example |
| 664 | // and have a wildcard subdomain and a route registered to root domain. |
| 665 | return false // it's not a subdomain, it's something like 127.0.0.1 probably |
| 666 | } |
| 667 | // it's a dynamic wildcard subdomain, we have just to check if ctx.subdomain is not empty |
| 668 | if t.subdomain == SubdomainWildcardIndicator { |
| 669 | // mydomain.com -> invalid |
| 670 | // localhost -> invalid |
| 671 | // sub.mydomain.com -> valid |
| 672 | // sub.localhost -> valid |
| 673 | serverHost := ctx.Application().ConfigurationReadOnly().GetVHost() |
| 674 | if serverHost == requestHost { |
| 675 | return false // it's not a subdomain, it's a full domain (with .com...) |
| 676 | } |
| 677 | |
| 678 | dotIdx := strings.IndexByte(requestHost, '.') |
| 679 | slashIdx := strings.IndexByte(requestHost, '/') |
| 680 | if dotIdx > 0 && (slashIdx == -1 || slashIdx > dotIdx) { |
| 681 | // if "." was found anywhere but not at the first path segment (host). |
| 682 | } else { |
| 683 | return false |
| 684 | } |
| 685 | // continue to that, any subdomain is valid. |
| 686 | } else if !strings.HasPrefix(requestHost, t.subdomain) { // t.subdomain contains the dot. |
| 687 | return false |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | n := t.search(path, ctx.Params()) |
| 692 | return n != nil |
| 693 | } |
| 694 | |
| 695 | // RouteExists reports whether a particular route exists |
| 696 | // It will search from the current subdomain of context's host, if not inside the root domain. |
no test coverage detected