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
9c017cba
Commit
9c017cba
authored
Jan 07, 2022
by
inphi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add proxyd ip to xff
parent
16e27bdf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
backend.go
go/proxyd/backend.go
+14
-1
proxyd.go
go/proxyd/proxyd.go
+1
-0
No files found.
go/proxyd/backend.go
View file @
9c017cba
...
...
@@ -87,6 +87,7 @@ type Backend struct {
maxWSConns
int
outOfServiceInterval
time
.
Duration
stripTrailingXFF
bool
proxydIP
string
}
type
BackendOpt
func
(
b
*
Backend
)
...
...
@@ -149,6 +150,12 @@ func WithStrippedTrailingXFF() BackendOpt {
}
}
func
WithProxydIP
(
ip
string
)
BackendOpt
{
return
func
(
b
*
Backend
)
{
b
.
proxydIP
=
ip
}
}
func
NewBackend
(
name
string
,
rpcURL
string
,
...
...
@@ -172,6 +179,10 @@ func NewBackend(
opt
(
backend
)
}
if
!
backend
.
stripTrailingXFF
&&
backend
.
proxydIP
==
""
{
log
.
Warn
(
"proxied requests' XFF header will not contain the proxyd ip address"
)
}
return
backend
}
...
...
@@ -327,10 +338,12 @@ func (b *Backend) doForward(ctx context.Context, rpcReq *RPCReq) (*RPCRes, error
xForwardedFor
:=
GetXForwardedFor
(
ctx
)
if
b
.
stripTrailingXFF
{
ipList
:=
strings
.
Split
(
xForwardedFor
,
","
)
ipList
:=
strings
.
Split
(
xForwardedFor
,
",
"
)
if
len
(
ipList
)
>
0
{
xForwardedFor
=
ipList
[
0
]
}
}
else
if
b
.
proxydIP
!=
""
{
xForwardedFor
=
fmt
.
Sprintf
(
"%s, %s"
,
xForwardedFor
,
b
.
proxydIP
)
}
httpReq
.
Header
.
Set
(
"content-type"
,
"application/json"
)
...
...
go/proxyd/proxyd.go
View file @
9c017cba
...
...
@@ -99,6 +99,7 @@ func Start(config *Config) error {
if
cfg
.
StripTrailingXFF
{
opts
=
append
(
opts
,
WithStrippedTrailingXFF
())
}
opts
=
append
(
opts
,
WithProxydIP
(
os
.
Getenv
(
"PROXYD_IP"
)))
back
:=
NewBackend
(
name
,
rpcURL
,
wsURL
,
lim
,
opts
...
)
backendNames
=
append
(
backendNames
,
name
)
backendsByName
[
name
]
=
back
...
...
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