diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2018-09-07 09:24:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-07 09:24:18 -0400 |
commit | 0027d998555d47f9a75a896d8c6c85a8b4645ad0 (patch) | |
tree | 4a15d63c143e9891921d75f102dd008852c9abb2 /app/app.go | |
parent | 291000703320cc53c3bdecd2553fa4a3021d7234 (diff) | |
download | chat-0027d998555d47f9a75a896d8c6c85a8b4645ad0.tar.gz chat-0027d998555d47f9a75a896d8c6c85a8b4645ad0.tar.bz2 chat-0027d998555d47f9a75a896d8c6c85a8b4645ad0.zip |
MM-11855 Add App.HTTPService to allow mocking of HTTP client (#9359)
* MM-11855 Add App.HTTPService to allow mocking of HTTP client
* Initialize HTTPService earlier
Diffstat (limited to 'app/app.go')
-rw-r--r-- | app/app.go | 46 |
1 files changed, 7 insertions, 39 deletions
diff --git a/app/app.go b/app/app.go index 2e0433d23..c3fcc7aec 100644 --- a/app/app.go +++ b/app/app.go @@ -7,12 +7,10 @@ import ( "crypto/ecdsa" "fmt" "html/template" - "net" "net/http" "path" "reflect" "strconv" - "strings" "sync" "sync/atomic" @@ -100,6 +98,8 @@ type App struct { diagnosticId string phase2PermissionsMigrationComplete bool + + HTTPService HTTPService } var appCount = 0 @@ -125,6 +125,9 @@ func New(options ...Option) (outApp *App, outErr error) { clientConfig: make(map[string]string), licenseListeners: map[string]func(){}, } + + app.HTTPService = MakeHTTPService(app) + defer func() { if outErr != nil { app.Shutdown() @@ -285,6 +288,8 @@ func (a *App) Shutdown() { mlog.Info("Server stopped") a.DisableConfigWatch() + + a.HTTPService.Close() } var accountMigrationInterface func(*App) einterfaces.AccountMigrationInterface @@ -505,43 +510,6 @@ func (a *App) HTMLTemplates() *template.Template { return nil } -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) |