adds support for defining an proxy for the http client within the config

This commit is contained in:
Aiden McClelland 2020-05-21 18:05:04 -06:00
parent f223da2f35
commit d0533c45b4
No known key found for this signature in database
GPG key ID: 45C49185E315A11D
2 changed files with 16 additions and 1 deletions

View file

@ -20,6 +20,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
"fmt"
"golang.org/x/crypto/ed25519" "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") 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{ return &BaseDendrite{
componentName: componentName, componentName: componentName,
EnableHTTPAPIs: enableHTTPAPIs, EnableHTTPAPIs: enableHTTPAPIs,
@ -102,7 +111,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, enableHTTPAPIs
Cfg: cfg, Cfg: cfg,
ImmutableCache: cache, ImmutableCache: cache,
APIMux: mux.NewRouter().UseEncodedPath(), APIMux: mux.NewRouter().UseEncodedPath(),
httpClient: &http.Client{Timeout: HTTPClientTimeout}, httpClient: &client,
KafkaConsumer: kafkaConsumer, KafkaConsumer: kafkaConsumer,
KafkaProducer: kafkaProducer, KafkaProducer: kafkaProducer,
} }

View file

@ -264,6 +264,12 @@ type Dendrite struct {
// The config for logging informations. Each hook will be added to logrus. // The config for logging informations. Each hook will be added to logrus.
Logging []LogrusHook `yaml:"logging"` 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. // Any information derived from the configuration options for later use.
Derived struct { Derived struct {
Registration struct { Registration struct {