mirror of
https://github.com/kataras/iris.git
synced 2026-02-28 05:26:00 +00:00
General Improvements (UseRouter per Party, fix AutoTLS). Read HISTORY.md
relative to: https://github.com/kataras/iris/issues/1577 and https://github.com/kataras/iris/issues/1578
This commit is contained in:
@@ -740,7 +740,9 @@ func (ctx *Context) RequestPath(escape bool) string {
|
||||
// return false
|
||||
// } no, it will not work because map is a random peek data structure.
|
||||
|
||||
// Host returns the host part of the current URI.
|
||||
// Host returns the host:port part of the request URI, calls the `Request().Host`.
|
||||
// To get the subdomain part as well use the `Request().URL.Host` method instead.
|
||||
// To get the subdomain only use the `Subdomain` method instead.
|
||||
// This method makes use of the `Configuration.HostProxyHeaders` field too.
|
||||
func (ctx *Context) Host() string {
|
||||
for header, ok := range ctx.app.ConfigurationReadOnly().GetHostProxyHeaders() {
|
||||
@@ -762,13 +764,14 @@ func GetHost(r *http.Request) string {
|
||||
return host
|
||||
}
|
||||
|
||||
// contains subdomain.
|
||||
return r.URL.Host
|
||||
}
|
||||
|
||||
// Subdomain returns the subdomain of this request, if any.
|
||||
// Note that this is a fast method which does not cover all cases.
|
||||
func (ctx *Context) Subdomain() (subdomain string) {
|
||||
host := ctx.Host()
|
||||
host := ctx.request.URL.Host // ctx.Host()
|
||||
if index := strings.IndexByte(host, '.'); index > 0 {
|
||||
subdomain = host[0:index]
|
||||
}
|
||||
|
||||
@@ -116,6 +116,31 @@ func HandlerName(h interface{}) string {
|
||||
return trimHandlerName(name)
|
||||
}
|
||||
|
||||
// HandlersNames returns a slice of "handlers" names
|
||||
// separated by commas. Can be used for debugging
|
||||
// or to determinate if end-developer
|
||||
// called the same exactly Use/UseRouter/Done... API methods
|
||||
// so framework can give a warning.
|
||||
func HandlersNames(handlers ...interface{}) string {
|
||||
if len(handlers) == 1 {
|
||||
if hs, ok := handlers[0].(Handlers); ok {
|
||||
asInterfaces := make([]interface{}, 0, len(hs))
|
||||
for _, h := range hs {
|
||||
asInterfaces = append(asInterfaces, h)
|
||||
}
|
||||
|
||||
return HandlersNames(asInterfaces...)
|
||||
}
|
||||
}
|
||||
|
||||
names := make([]string, 0, len(handlers))
|
||||
for _, h := range handlers {
|
||||
names = append(names, HandlerName(h))
|
||||
}
|
||||
|
||||
return strings.Join(names, ",")
|
||||
}
|
||||
|
||||
// HandlerFileLine returns the handler's file and line information.
|
||||
// See `context.HandlerFileLine` to get the file, line of the current running handler in the chain.
|
||||
func HandlerFileLine(h interface{}) (file string, line int) {
|
||||
@@ -304,3 +329,23 @@ func JoinHandlers(h1 Handlers, h2 Handlers) Handlers {
|
||||
copy(newHandlers[nowLen:], h2)
|
||||
return newHandlers
|
||||
}
|
||||
|
||||
// UpsertHandlers like `JoinHandlers` but it does
|
||||
// NOT copies the handlers entries and it does remove duplicates.
|
||||
func UpsertHandlers(h1 Handlers, h2 Handlers) Handlers {
|
||||
reg:
|
||||
for _, handler := range h2 {
|
||||
name := HandlerName(handler)
|
||||
for i, registeredHandler := range h1 {
|
||||
registeredName := HandlerName(registeredHandler)
|
||||
if name == registeredName {
|
||||
h1[i] = handler // replace this handler with the new one.
|
||||
continue reg // break and continue to the next handler.
|
||||
}
|
||||
}
|
||||
|
||||
h1 = append(h1, handler) // or just insert it.
|
||||
}
|
||||
|
||||
return h1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user