(ctx *context.Context, subdomain string)
| 412 | } |
| 413 | |
| 414 | func canHandleSubdomain(ctx *context.Context, subdomain string) bool { |
| 415 | if subdomain == "" { |
| 416 | return true |
| 417 | } |
| 418 | |
| 419 | requestHost := ctx.Host() |
| 420 | if netutil.IsLoopbackSubdomain(requestHost) { |
| 421 | // this fixes a bug when listening on |
| 422 | // 127.0.0.1:8080 for example |
| 423 | // and have a wildcard subdomain and a route registered to root domain. |
| 424 | return false // it's not a subdomain, it's something like 127.0.0.1 probably |
| 425 | } |
| 426 | // it's a dynamic wildcard subdomain, we have just to check if ctx.subdomain is not empty |
| 427 | if subdomain == SubdomainWildcardIndicator { |
| 428 | // mydomain.com -> invalid |
| 429 | // localhost -> invalid |
| 430 | // sub.mydomain.com -> valid |
| 431 | // sub.localhost -> valid |
| 432 | serverHost := ctx.Application().ConfigurationReadOnly().GetVHost() |
| 433 | if serverHost == requestHost { |
| 434 | return false // it's not a subdomain, it's a full domain (with .com...) |
| 435 | } |
| 436 | |
| 437 | dotIdx := strings.IndexByte(requestHost, '.') |
| 438 | slashIdx := strings.IndexByte(requestHost, '/') |
| 439 | if dotIdx > 0 && (slashIdx == -1 || slashIdx > dotIdx) { |
| 440 | // if "." was found anywhere but not at the first path segment (host). |
| 441 | } else { |
| 442 | return false |
| 443 | } |
| 444 | // continue to that, any subdomain is valid. |
| 445 | } else if !strings.HasPrefix(requestHost, subdomain) { // subdomain contains the dot, e.g. "admin." |
| 446 | return false |
| 447 | } |
| 448 | |
| 449 | return true |
| 450 | } |
| 451 | |
| 452 | func (h *routerHandler) HandleRequest(ctx *context.Context) { |
| 453 | method := ctx.Method() |
no test coverage detected
searching dependent graphs…