aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorAiden McClelland <3732071+dr-bonez@users.noreply.github.com>2020-06-02 14:02:24 -0600
committerGitHub <noreply@github.com>2020-06-02 21:02:24 +0100
commit17c92ad10e7c1c6e17eed62d91fbc130866fdf91 (patch)
treec3b2254f83e071b00695b3d212755419977f1f3e /internal
parentdc3338d1f299555148cbf406c5b2bd823f3ca038 (diff)
Adds support for adding a proxy to the HTTP Client from the config (#1055)
* adds support for defining an proxy for the http client within the config * alphabetize imports * goimports * comments
Diffstat (limited to 'internal')
-rw-r--r--internal/basecomponent/base.go12
-rw-r--r--internal/config/config.go10
2 files changed, 21 insertions, 1 deletions
diff --git a/internal/basecomponent/base.go b/internal/basecomponent/base.go
index a4832372..0fc95e82 100644
--- a/internal/basecomponent/base.go
+++ b/internal/basecomponent/base.go
@@ -16,6 +16,7 @@ package basecomponent
import (
"database/sql"
+ "fmt"
"io"
"net/http"
"net/url"
@@ -94,7 +95,16 @@ 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),
+ })}
+ }
+
httpmux := mux.NewRouter()
+
return &BaseDendrite{
componentName: componentName,
EnableHTTPAPIs: enableHTTPAPIs,
@@ -103,7 +113,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, enableHTTPAPIs
ImmutableCache: cache,
PublicAPIMux: httpmux.PathPrefix(httpapis.PublicPathPrefix).Subrouter().UseEncodedPath(),
InternalAPIMux: httpmux.PathPrefix(httpapis.InternalPathPrefix).Subrouter().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 a20cc0ea..59799585 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -268,6 +268,16 @@ type Dendrite struct {
// The config for logging informations. Each hook will be added to logrus.
Logging []LogrusHook `yaml:"logging"`
+ // The config for setting a proxy to use for server->server requests
+ Proxy *struct {
+ // The protocol for the proxy (http / https / socks5)
+ Protocol string `yaml:"protocol"`
+ // The host where the proxy is listening
+ Host string `yaml:"host"`
+ // The port on which the proxy is listening
+ Port uint16 `yaml:"port"`
+ } `yaml:"proxy"`
+
// Any information derived from the configuration options for later use.
Derived struct {
Registration struct {