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

Function canHandleSubdomain

core/router/handler.go:414–450  ·  view source on GitHub ↗
(ctx *context.Context, subdomain string)

Source from the content-addressed store, hash-verified

412}
413
414func 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
452func (h *routerHandler) HandleRequest(ctx *context.Context) {
453 method := ctx.Method()

Callers 3

defaultPartyMatcherFunction · 0.85
HandleRequestMethod · 0.85
FireErrorCodeMethod · 0.85

Calls 4

HostMethod · 0.80
ApplicationMethod · 0.80
GetVHostMethod · 0.65
ConfigurationReadOnlyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…