1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-24 12:25:57 +00:00
This commit is contained in:
Makis Maropoulos
2016-06-30 05:58:04 +03:00
parent b2d1e6396d
commit 66a66fdfa0
5 changed files with 114 additions and 61 deletions

View File

@@ -215,12 +215,21 @@ func (ctx *Context) HostString() string {
// VirtualHostname returns the hostname that user registers, host path maybe differs from the real which is HostString, which taken from a net.listener
func (ctx *Context) VirtualHostname() string {
realhost := ctx.HostString()
hostname := realhost
virtualhost := ctx.framework.HTTPServer.VirtualHostname()
hostname := strings.Replace(realhost, "127.0.0.1", virtualhost, 1)
hostname = strings.Replace(realhost, "localhost", virtualhost, 1)
if portIdx := strings.IndexByte(hostname, ':'); portIdx > 0 {
hostname = hostname[0:portIdx]
}
if idxDotAnd := strings.LastIndexByte(hostname, '.'); idxDotAnd > 0 {
s := hostname[idxDotAnd:]
if s == ".1" {
hostname = strings.Replace(hostname, "127.0.0.1", virtualhost, 1)
}
} else {
hostname = strings.Replace(hostname, "localhost", virtualhost, 1)
}
return hostname
}
@@ -288,6 +297,15 @@ func (ctx *Context) PostFormMulti(name string) []string {
return arrStr
}
// Domain same as VirtualHostname but without the :port part (if any)
func (ctx *Context) Domain() string {
domain := ctx.VirtualHostname()
if idx := strings.IndexByte(domain, ':'); idx > 0 {
domain = domain[0 : idx-1]
}
return domain
}
// Subdomain returns the subdomain (string) of this request, if any
func (ctx *Context) Subdomain() (subdomain string) {
host := ctx.HostString()