Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
openSource
spring-cloud-netflix
Commits
59354955
Commit
59354955
authored
Apr 05, 2016
by
Tim te Beek
Committed by
Dave Syer
Apr 05, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set or append to X-Forwarded-For for downstream requests
Fixes gh-352
parent
c0d76735
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
PreDecorationFilter.java
...k/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
+9
-0
PreDecorationFilterTests.java
...ud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
+3
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
View file @
59354955
...
...
@@ -107,6 +107,15 @@ public class PreDecorationFilter extends ZuulFilter {
if
(
StringUtils
.
hasText
(
route
.
getPrefix
()))
{
ctx
.
addZuulRequestHeader
(
"X-Forwarded-Prefix"
,
route
.
getPrefix
());
}
String
xforwardedfor
=
ctx
.
getRequest
().
getHeader
(
"X-Forwarded-For"
);
String
remoteAddr
=
ctx
.
getRequest
().
getRemoteAddr
();
if
(
xforwardedfor
==
null
)
{
xforwardedfor
=
remoteAddr
;
}
else
if
(!
xforwardedfor
.
contains
(
remoteAddr
))
{
// Prevent duplicates
xforwardedfor
+=
", "
+
remoteAddr
;
}
ctx
.
addZuulRequestHeader
(
"X-Forwarded-For"
,
xforwardedfor
);
}
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
View file @
59354955
...
...
@@ -85,6 +85,8 @@ public class PreDecorationFilterTests {
this
.
properties
.
setPrefix
(
"/api"
);
this
.
properties
.
setStripPrefix
(
true
);
this
.
request
.
setRequestURI
(
"/api/foo/1"
);
this
.
request
.
setRemoteAddr
(
"5.6.7.8"
);
this
.
request
.
addHeader
(
"X-Forwarded-For"
,
"1.2.3.4"
);
this
.
routeLocator
.
addRoute
(
new
ZuulRoute
(
"foo"
,
"/foo/**"
,
"foo"
,
null
,
false
,
null
,
null
));
this
.
filter
.
run
();
...
...
@@ -94,6 +96,7 @@ public class PreDecorationFilterTests {
assertEquals
(
"80"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-port"
));
assertEquals
(
"http"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-proto"
));
assertEquals
(
"/api"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-prefix"
));
assertEquals
(
"1.2.3.4, 5.6.7.8"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-for"
));
assertEquals
(
"foo"
,
getHeader
(
ctx
.
getOriginResponseHeaders
(),
"x-zuul-serviceid"
));
}
...
...
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