feat(proxyd): ability to add additional headers to backend requests (#8134)
This commit is contained in:
parent
798878e455
commit
7175c46a00
@ -139,6 +139,7 @@ type Backend struct {
|
|||||||
wsURL string
|
wsURL string
|
||||||
authUsername string
|
authUsername string
|
||||||
authPassword string
|
authPassword string
|
||||||
|
headers map[string]string
|
||||||
client *LimitedHTTPClient
|
client *LimitedHTTPClient
|
||||||
dialer *websocket.Dialer
|
dialer *websocket.Dialer
|
||||||
maxRetries int
|
maxRetries int
|
||||||
@ -170,6 +171,12 @@ func WithBasicAuth(username, password string) BackendOpt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithHeaders(headers map[string]string) BackendOpt {
|
||||||
|
return func(b *Backend) {
|
||||||
|
b.headers = headers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func WithTimeout(timeout time.Duration) BackendOpt {
|
func WithTimeout(timeout time.Duration) BackendOpt {
|
||||||
return func(b *Backend) {
|
return func(b *Backend) {
|
||||||
b.client.Timeout = timeout
|
b.client.Timeout = timeout
|
||||||
@ -535,6 +542,10 @@ func (b *Backend) doForward(ctx context.Context, rpcReqs []*RPCReq, isBatch bool
|
|||||||
httpReq.Header.Set("content-type", "application/json")
|
httpReq.Header.Set("content-type", "application/json")
|
||||||
httpReq.Header.Set("X-Forwarded-For", xForwardedFor)
|
httpReq.Header.Set("X-Forwarded-For", xForwardedFor)
|
||||||
|
|
||||||
|
for name, value := range b.headers {
|
||||||
|
httpReq.Header.Set(name, value)
|
||||||
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
httpRes, err := b.client.DoLimited(httpReq)
|
httpRes, err := b.client.DoLimited(httpReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -94,6 +94,7 @@ type BackendConfig struct {
|
|||||||
ClientCertFile string `toml:"client_cert_file"`
|
ClientCertFile string `toml:"client_cert_file"`
|
||||||
ClientKeyFile string `toml:"client_key_file"`
|
ClientKeyFile string `toml:"client_key_file"`
|
||||||
StripTrailingXFF bool `toml:"strip_trailing_xff"`
|
StripTrailingXFF bool `toml:"strip_trailing_xff"`
|
||||||
|
Headers map[string]string `toml:"headers"`
|
||||||
|
|
||||||
ConsensusSkipPeerCountCheck bool `toml:"consensus_skip_peer_count"`
|
ConsensusSkipPeerCountCheck bool `toml:"consensus_skip_peer_count"`
|
||||||
ConsensusForcedCandidate bool `toml:"consensus_forced_candidate"`
|
ConsensusForcedCandidate bool `toml:"consensus_forced_candidate"`
|
||||||
|
@ -130,6 +130,18 @@ func Start(config *Config) (*Server, func(), error) {
|
|||||||
}
|
}
|
||||||
opts = append(opts, WithBasicAuth(cfg.Username, passwordVal))
|
opts = append(opts, WithBasicAuth(cfg.Username, passwordVal))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
headers := map[string]string{}
|
||||||
|
for headerName, headerValue := range cfg.Headers {
|
||||||
|
headerValue, err := ReadFromEnvOrConfig(headerValue)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
headers[headerName] = headerValue
|
||||||
|
}
|
||||||
|
opts = append(opts, WithHeaders(headers))
|
||||||
|
|
||||||
tlsConfig, err := configureBackendTLS(cfg)
|
tlsConfig, err := configureBackendTLS(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user