mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-20 13:23:22 -06:00
adds support for defining an proxy for the http client within the config
This commit is contained in:
parent
f223da2f35
commit
d0533c45b4
|
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue