mirror of
https://github.com/kataras/iris.git
synced 2025-12-28 07:17:06 +00:00
fix SubdomainRedirect on loopbacks
fix: https://github.com/kataras/iris/issues/1584#issuecomment-674001454
This commit is contained in:
@@ -904,24 +904,29 @@ func (ctx *Context) GetHeader(name string) string {
|
||||
}
|
||||
|
||||
// GetDomain resolves and returns the server's domain.
|
||||
func (ctx *Context) GetDomain() string {
|
||||
hostport := ctx.Host()
|
||||
if host, _, err := net.SplitHostPort(hostport); err == nil {
|
||||
// has port.
|
||||
switch host {
|
||||
case "127.0.0.1", "0.0.0.0", "::1", "[::1]", "0:0:0:0:0:0:0:0", "0:0:0:0:0:0:0:1":
|
||||
// loopback.
|
||||
return "localhost"
|
||||
default:
|
||||
if domain, err := publicsuffix.EffectiveTLDPlusOne(host); err == nil {
|
||||
host = domain
|
||||
}
|
||||
|
||||
return host
|
||||
}
|
||||
func GetDomain(hostport string) string {
|
||||
host := hostport
|
||||
if tmp, _, err := net.SplitHostPort(hostport); err == nil {
|
||||
host = tmp
|
||||
}
|
||||
|
||||
return hostport
|
||||
// has port.
|
||||
switch host {
|
||||
case "127.0.0.1", "0.0.0.0", "::1", "[::1]", "0:0:0:0:0:0:0:0", "0:0:0:0:0:0:0:1":
|
||||
// loopback.
|
||||
return "localhost"
|
||||
default:
|
||||
if domain, err := publicsuffix.EffectiveTLDPlusOne(host); err == nil {
|
||||
host = domain
|
||||
}
|
||||
|
||||
return host
|
||||
}
|
||||
}
|
||||
|
||||
// GetDomain resolves and returns the server's domain.
|
||||
func (ctx *Context) GetDomain() string {
|
||||
return GetDomain(ctx.Host())
|
||||
}
|
||||
|
||||
// IsAjax returns true if this request is an 'ajax request'( XMLHttpRequest)
|
||||
|
||||
Reference in New Issue
Block a user