1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 04:47:02 +00:00

init of v11.2.0: add context#FullRequestURI and NewConditionalHandler

As requested at: https://github.com/kataras/iris/issues/1167 and https://github.com/kataras/iris/issues/1170


Former-commit-id: 781c92f444b3e362011be886b32cf88f89998589
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-01-19 23:33:33 +02:00
parent 571ef59adf
commit 3fcc70b891
6 changed files with 152 additions and 6 deletions

View File

@@ -292,7 +292,6 @@ type Context interface {
// RequestPath returns the full request path,
// based on the 'escape'.
RequestPath(escape bool) string
// Host returns the host part of the current url.
Host() string
// Subdomain returns the subdomain of this request, if any.
@@ -300,6 +299,9 @@ type Context interface {
Subdomain() (subdomain string)
// IsWWW returns true if the current subdomain (if any) is www.
IsWWW() bool
// FullRqeuestURI returns the full URI,
// including the scheme, the host and the relative requested path/resource.
FullRequestURI() string
// RemoteAddr tries to parse and return the real client's request IP.
//
// Based on allowed headers names that can be modified from Configuration.RemoteAddrHeaders.
@@ -1465,11 +1467,11 @@ func (ctx *context) Host() string {
// GetHost returns the host part of the current URI.
func GetHost(r *http.Request) string {
h := r.URL.Host
if h == "" {
h = r.Host
if host := r.Host; host != "" {
return host
}
return h
return r.URL.Host
}
// Subdomain returns the subdomain of this request, if any.
@@ -1502,6 +1504,24 @@ func (ctx *context) IsWWW() bool {
return false
}
// FullRqeuestURI returns the full URI,
// including the scheme, the host and the relative requested path/resource.
func (ctx *context) FullRequestURI() string {
scheme := ctx.request.URL.Scheme
if scheme == "" {
if ctx.request.TLS != nil {
scheme = "https:"
} else {
scheme = "http:"
}
}
host := ctx.Host()
path := ctx.Path()
return scheme + "//" + host + path
}
const xForwardedForHeaderKey = "X-Forwarded-For"
// RemoteAddr tries to parse and return the real client's request IP.