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/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,
}

View file

@ -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 {