mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-22 11:41:38 +00:00
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
This commit is contained in:
parent
dc3338d1f2
commit
17c92ad10e
@ -16,6 +16,7 @@ package basecomponent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -94,7 +95,16 @@ 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),
|
||||||
|
})}
|
||||||
|
}
|
||||||
|
|
||||||
httpmux := mux.NewRouter()
|
httpmux := mux.NewRouter()
|
||||||
|
|
||||||
return &BaseDendrite{
|
return &BaseDendrite{
|
||||||
componentName: componentName,
|
componentName: componentName,
|
||||||
EnableHTTPAPIs: enableHTTPAPIs,
|
EnableHTTPAPIs: enableHTTPAPIs,
|
||||||
@ -103,7 +113,7 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, enableHTTPAPIs
|
|||||||
ImmutableCache: cache,
|
ImmutableCache: cache,
|
||||||
PublicAPIMux: httpmux.PathPrefix(httpapis.PublicPathPrefix).Subrouter().UseEncodedPath(),
|
PublicAPIMux: httpmux.PathPrefix(httpapis.PublicPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
InternalAPIMux: httpmux.PathPrefix(httpapis.InternalPathPrefix).Subrouter().UseEncodedPath(),
|
InternalAPIMux: httpmux.PathPrefix(httpapis.InternalPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
httpClient: &http.Client{Timeout: HTTPClientTimeout},
|
httpClient: &client,
|
||||||
KafkaConsumer: kafkaConsumer,
|
KafkaConsumer: kafkaConsumer,
|
||||||
KafkaProducer: kafkaProducer,
|
KafkaProducer: kafkaProducer,
|
||||||
}
|
}
|
||||||
|
@ -268,6 +268,16 @@ 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"`
|
||||||
|
|
||||||
|
// 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.
|
// Any information derived from the configuration options for later use.
|
||||||
Derived struct {
|
Derived struct {
|
||||||
Registration struct {
|
Registration struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user