mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 05:26:26 +01:00
Context.GetDomain: use net.SplitHostPort better
Former-commit-id: e0a13062f9c4d37e48a82367d23bc16be8f1d1ce
This commit is contained in:
parent
c32dd0d95c
commit
cbe336a583
|
@ -1942,13 +1942,12 @@ func (ctx *context) GetHeader(name string) string {
|
||||||
|
|
||||||
// GetDomain resolves and returns the server's domain.
|
// GetDomain resolves and returns the server's domain.
|
||||||
func (ctx *context) GetDomain() string {
|
func (ctx *context) GetDomain() string {
|
||||||
host := ctx.Host()
|
hostport := ctx.Host()
|
||||||
if portIdx := strings.IndexByte(host, ':'); portIdx > 0 {
|
if host, _, err := net.SplitHostPort(hostport); err == nil {
|
||||||
host = host[0:portIdx]
|
// has port.
|
||||||
}
|
|
||||||
|
|
||||||
switch host {
|
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:1":
|
case "127.0.0.1", "0.0.0.0", "::1", "[::1]", "0:0:0:0:0:0:0", "0:0:0:0:0:0:1":
|
||||||
|
// loopback.
|
||||||
return "localhost"
|
return "localhost"
|
||||||
default:
|
default:
|
||||||
if domain, err := publicsuffix.EffectiveTLDPlusOne(host); err == nil {
|
if domain, err := publicsuffix.EffectiveTLDPlusOne(host); err == nil {
|
||||||
|
@ -1959,6 +1958,9 @@ func (ctx *context) GetDomain() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return hostport
|
||||||
|
}
|
||||||
|
|
||||||
// IsAjax returns true if this request is an 'ajax request'( XMLHttpRequest)
|
// IsAjax returns true if this request is an 'ajax request'( XMLHttpRequest)
|
||||||
//
|
//
|
||||||
// There is no a 100% way of knowing that a request was made via Ajax.
|
// There is no a 100% way of knowing that a request was made via Ajax.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user