diff --git a/app/app.go b/app/app.go index bd929472dc..a4aafa149a 100644 --- a/app/app.go +++ b/app/app.go @@ -125,10 +125,10 @@ func (a *App) Cloud() einterfaces.CloudInterface { return a.ch.srv.Cloud } func (a *App) HTTPService() httpservice.HTTPService { - return a.ch.httpService + return a.ch.srv.httpService } func (a *App) ImageProxy() *imageproxy.ImageProxy { - return a.ch.srv.ImageProxy + return a.ch.imageProxy } func (a *App) Timezones() *timezones.Timezones { return a.ch.srv.timezones diff --git a/app/channels.go b/app/channels.go index 1aefcb4793..f703430df7 100644 --- a/app/channels.go +++ b/app/channels.go @@ -3,13 +3,15 @@ package app -import "github.com/mattermost/mattermost-server/v6/services/httpservice" +import ( + "github.com/mattermost/mattermost-server/v6/services/imageproxy" +) // Channels contains all channels related state. type Channels struct { srv *Server - httpService httpservice.HTTPService + imageProxy *imageproxy.ImageProxy } func init() { @@ -20,8 +22,8 @@ func init() { func NewChannels(s *Server) (*Channels, error) { return &Channels{ - srv: s, - httpService: httpservice.MakeHTTPService(s), + srv: s, + imageProxy: imageproxy.MakeImageProxy(s, s.httpService, s.Log), }, nil } @@ -32,7 +34,3 @@ func (c *Channels) Start() error { func (c *Channels) Stop() error { return nil } - -func (c *Channels) HTTPService() httpservice.HTTPService { - return c.httpService -} diff --git a/app/post.go b/app/post.go index 3ddfe0bb72..c45c5fd8d7 100644 --- a/app/post.go +++ b/app/post.go @@ -1408,7 +1408,7 @@ func (a *App) ImageProxyAdder() func(string) string { } return func(url string) string { - return a.Srv().ImageProxy.GetProxiedImageURL(url) + return a.ImageProxy().GetProxiedImageURL(url) } } @@ -1418,7 +1418,7 @@ func (a *App) ImageProxyRemover() (f func(string) string) { } return func(url string) string { - return a.Srv().ImageProxy.GetUnproxiedImageURL(url) + return a.ImageProxy().GetUnproxiedImageURL(url) } } diff --git a/app/post_metadata_test.go b/app/post_metadata_test.go index 848b09d5c4..c7831e33f4 100644 --- a/app/post_metadata_test.go +++ b/app/post_metadata_test.go @@ -647,7 +647,7 @@ func TestPreparePostForClientWithImageProxy(t *testing.T) { *cfg.ImageProxySettings.RemoteImageProxyOptions = "foo" }) - th.Server.ImageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) + th.App.ch.imageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) return th } diff --git a/app/post_test.go b/app/post_test.go index 13e8ceb547..808a1692fa 100644 --- a/app/post_test.go +++ b/app/post_test.go @@ -469,7 +469,7 @@ func TestImageProxy(t *testing.T) { *cfg.ServiceSettings.SiteURL = "http://mymattermost.com" }) - th.Server.ImageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) + th.App.ch.imageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) for name, tc := range map[string]struct { ProxyType string @@ -686,7 +686,7 @@ func TestCreatePost(t *testing.T) { *cfg.ImageProxySettings.RemoteImageProxyOptions = "foo" }) - th.Server.ImageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) + th.App.ch.imageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) imageURL := "http://mydomain.com/myimage" proxiedImageURL := "http://mymattermost.com/api/v4/image?url=http%3A%2F%2Fmydomain.com%2Fmyimage" @@ -841,7 +841,7 @@ func TestPatchPost(t *testing.T) { *cfg.ImageProxySettings.RemoteImageProxyOptions = "foo" }) - th.Server.ImageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) + th.App.ch.imageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) imageURL := "http://mydomain.com/myimage" proxiedImageURL := "http://mymattermost.com/api/v4/image?url=http%3A%2F%2Fmydomain.com%2Fmyimage" @@ -1134,7 +1134,7 @@ func TestUpdatePost(t *testing.T) { *cfg.ImageProxySettings.RemoteImageProxyOptions = "foo" }) - th.Server.ImageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) + th.App.ch.imageProxy = imageproxy.MakeImageProxy(th.Server, th.Server.HTTPService(), th.Server.Log) imageURL := "http://mydomain.com/myimage" proxiedImageURL := "http://mymattermost.com/api/v4/image?url=http%3A%2F%2Fmydomain.com%2Fmyimage" diff --git a/app/server.go b/app/server.go index ec58586642..e970d285b9 100644 --- a/app/server.go +++ b/app/server.go @@ -51,7 +51,6 @@ import ( "github.com/mattermost/mattermost-server/v6/services/awsmeter" "github.com/mattermost/mattermost-server/v6/services/cache" "github.com/mattermost/mattermost-server/v6/services/httpservice" - "github.com/mattermost/mattermost-server/v6/services/imageproxy" "github.com/mattermost/mattermost-server/v6/services/remotecluster" "github.com/mattermost/mattermost-server/v6/services/searchengine" "github.com/mattermost/mattermost-server/v6/services/searchengine/bleveengine" @@ -118,6 +117,7 @@ type Server struct { hubs []*Hub hashSeed maphash.Seed + httpService httpservice.HTTPService PushNotificationsHub PushNotificationsHub pushNotificationClient *http.Client // TODO: move this to it's own package @@ -164,8 +164,6 @@ type Server struct { phase2PermissionsMigrationComplete bool - ImageProxy *imageproxy.ImageProxy - Audit *audit.Audit Log *mlog.Logger NotificationsLog *mlog.Logger @@ -267,6 +265,8 @@ func NewServer(options ...Option) (*Server, error) { // This is called after initLogging() to avoid a race condition. mlog.Info("Server is initializing...", mlog.String("go_version", runtime.Version())) + s.httpService = httpservice.MakeHTTPService(s) + // Initialize products for name, initializer := range products { prod, err := initializer(s) @@ -314,9 +314,7 @@ func NewServer(options ...Option) (*Server, error) { s.tracer = tracer } - s.pushNotificationClient = s.Channels().HTTPService().MakeClient(true) - - s.ImageProxy = imageproxy.MakeImageProxy(s, s.HTTPService(), s.Log) + s.pushNotificationClient = s.httpService.MakeClient(true) if err := utils.TranslationsPreInit(); err != nil { return nil, errors.Wrapf(err, "unable to load Mattermost translation files") @@ -1975,7 +1973,7 @@ func (s *Server) TelemetryId() string { } func (s *Server) HTTPService() httpservice.HTTPService { - return s.Channels().HTTPService() + return s.httpService } func (s *Server) SetLog(l *mlog.Logger) {