From 4e59a27293394b6d5529efd13ad711daebbc0eb3 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Wed, 26 Sep 2018 12:42:51 -0400 Subject: Move HTTPService and ConfigService into services package (#9422) * Move HTTPService and ConfigService into utils package * Re-add StaticConfigService * Move config and http services into their own packages --- app/http_service.go | 67 ----------------------------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 app/http_service.go (limited to 'app/http_service.go') diff --git a/app/http_service.go b/app/http_service.go deleted file mode 100644 index 71e72ab2f..000000000 --- a/app/http_service.go +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package app - -import ( - "net" - "net/http" - "strings" - - "github.com/mattermost/mattermost-server/utils" -) - -// Wraps the functionality for creating a new http.Client to encapsulate that and allow it to be mocked when testing -type HTTPService interface { - MakeClient(trustURLs bool) *http.Client - Close() -} - -type HTTPServiceImpl struct { - app *App -} - -func MakeHTTPService(app *App) HTTPService { - return &HTTPServiceImpl{app} -} - -func (h *HTTPServiceImpl) MakeClient(trustURLs bool) *http.Client { - insecure := h.app.Config().ServiceSettings.EnableInsecureOutgoingConnections != nil && *h.app.Config().ServiceSettings.EnableInsecureOutgoingConnections - - if trustURLs { - return utils.NewHTTPClient(insecure, nil, nil) - } - - allowHost := func(host string) bool { - if h.app.Config().ServiceSettings.AllowedUntrustedInternalConnections == nil { - return false - } - for _, allowed := range strings.Fields(*h.app.Config().ServiceSettings.AllowedUntrustedInternalConnections) { - if host == allowed { - return true - } - } - return false - } - - allowIP := func(ip net.IP) bool { - if !utils.IsReservedIP(ip) { - return true - } - if h.app.Config().ServiceSettings.AllowedUntrustedInternalConnections == nil { - return false - } - for _, allowed := range strings.Fields(*h.app.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 (h *HTTPServiceImpl) Close() { - // Does nothing, but allows this to be overridden when mocking the service -} -- cgit v1.2.3-1-g7c22