diff options
author | Chris <ccbrown112@gmail.com> | 2017-11-22 09:15:03 -0600 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-11-22 10:15:03 -0500 |
commit | 77a1dc1f2f12198881c00356a04dddef126b985d (patch) | |
tree | 09b5510bb744d0d9e5056783dc7522c5641ec788 /app/app.go | |
parent | cf9cd6a4b6bea717884269879ee8a3ced475ee8a (diff) | |
download | chat-77a1dc1f2f12198881c00356a04dddef126b985d.tar.gz chat-77a1dc1f2f12198881c00356a04dddef126b985d.tar.bz2 chat-77a1dc1f2f12198881c00356a04dddef126b985d.zip |
HTTP client refactor (#7884)
* http client refactor
* simplification
Diffstat (limited to 'app/app.go')
-rw-r--r-- | app/app.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/app.go b/app/app.go index ea79d8e81..7bd4c561b 100644 --- a/app/app.go +++ b/app/app.go @@ -5,8 +5,10 @@ package app import ( "html/template" + "net" "net/http" "runtime/debug" + "strings" "sync/atomic" l4g "github.com/alecthomas/log4go" @@ -351,6 +353,43 @@ func (a *App) HTMLTemplates() *template.Template { return a.htmlTemplateWatcher.Templates() } +func (a *App) HTTPClient(trustURLs bool) *http.Client { + insecure := a.Config().ServiceSettings.EnableInsecureOutgoingConnections != nil && *a.Config().ServiceSettings.EnableInsecureOutgoingConnections + + if trustURLs { + return utils.NewHTTPClient(insecure, nil, nil) + } + + allowHost := func(host string) bool { + if a.Config().ServiceSettings.AllowedUntrustedInternalConnections == nil { + return false + } + for _, allowed := range strings.Fields(*a.Config().ServiceSettings.AllowedUntrustedInternalConnections) { + if host == allowed { + return true + } + } + return false + } + + allowIP := func(ip net.IP) bool { + if !utils.IsReservedIP(ip) { + return true + } + if a.Config().ServiceSettings.AllowedUntrustedInternalConnections == nil { + return false + } + for _, allowed := range strings.Fields(*a.Config().ServiceSettings.AllowedUntrustedInternalConnections) { + if _, ipRange, err := net.ParseCIDR(allowed); err == nil && ipRange.Contains(ip) { + return true + } + } + return false + } + + return utils.NewHTTPClient(insecure, allowHost, allowIP) +} + func (a *App) Handle404(w http.ResponseWriter, r *http.Request) { err := model.NewAppError("Handle404", "api.context.404.app_error", nil, "", http.StatusNotFound) err.Translate(utils.T) |