Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
60ffe5af
Unverified
Commit
60ffe5af
authored
Nov 11, 2023
by
Danyal Prout
Committed by
GitHub
Nov 11, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(proxyd): ability to add additional headers to backend requests (#8134)
parent
9a13504b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
11 deletions
+35
-11
backend.go
proxyd/backend.go
+11
-0
config.go
proxyd/config.go
+12
-11
proxyd.go
proxyd/proxyd.go
+12
-0
No files found.
proxyd/backend.go
View file @
60ffe5af
...
@@ -139,6 +139,7 @@ type Backend struct {
...
@@ -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 {
...
@@ -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
...
@@ -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
{
...
...
proxyd/config.go
View file @
60ffe5af
...
@@ -83,17 +83,18 @@ type BackendOptions struct {
...
@@ -83,17 +83,18 @@ type BackendOptions struct {
}
}
type
BackendConfig
struct
{
type
BackendConfig
struct
{
Username
string
`toml:"username"`
Username
string
`toml:"username"`
Password
string
`toml:"password"`
Password
string
`toml:"password"`
RPCURL
string
`toml:"rpc_url"`
RPCURL
string
`toml:"rpc_url"`
WSURL
string
`toml:"ws_url"`
WSURL
string
`toml:"ws_url"`
WSPort
int
`toml:"ws_port"`
WSPort
int
`toml:"ws_port"`
MaxRPS
int
`toml:"max_rps"`
MaxRPS
int
`toml:"max_rps"`
MaxWSConns
int
`toml:"max_ws_conns"`
MaxWSConns
int
`toml:"max_ws_conns"`
CAFile
string
`toml:"ca_file"`
CAFile
string
`toml:"ca_file"`
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"`
...
...
proxyd/proxyd.go
View file @
60ffe5af
...
@@ -130,6 +130,18 @@ func Start(config *Config) (*Server, func(), error) {
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment