diff --git a/internal/basecomponent/base.go b/internal/basecomponent/base.go index e9a375a70..8b26b8422 100644 --- a/internal/basecomponent/base.go +++ b/internal/basecomponent/base.go @@ -20,6 +20,7 @@ import ( "net/http" "net/url" "time" + "fmt" "golang.org/x/crypto/ed25519" @@ -95,6 +96,14 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, enableHTTPAPIs logrus.WithError(err).Warnf("Failed to create cache") } + client := http.Client{Timeout: HTTPClientTimeout} + if cfg.Proxy != nil { + client.Transport = &http.Transport{Proxy: http.ProxyURL(&url.URL { + Scheme: cfg.Proxy.Protocol, + Host: fmt.Sprintf("%s:%d", cfg.Proxy.Host, cfg.Proxy.Port), + })} + } + return &BaseDendrite{ componentName: componentName, EnableHTTPAPIs: enableHTTPAPIs, @@ -102,7 +111,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, enableHTTPAPIs Cfg: cfg, ImmutableCache: cache, APIMux: mux.NewRouter().UseEncodedPath(), - httpClient: &http.Client{Timeout: HTTPClientTimeout}, + httpClient: &client, KafkaConsumer: kafkaConsumer, KafkaProducer: kafkaProducer, } diff --git a/internal/config/config.go b/internal/config/config.go index e1e96f9d5..32de41cc5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -264,6 +264,12 @@ type Dendrite struct { // The config for logging informations. Each hook will be added to logrus. Logging []LogrusHook `yaml:"logging"` + Proxy *struct { + Protocol string `yaml:"protocol"` + Host string `yaml:"host"` + Port uint16 `yaml:"port"` + } `yaml:"proxy"` + // Any information derived from the configuration options for later use. Derived struct { Registration struct {