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
53649f60
Unverified
Commit
53649f60
authored
Jan 30, 2017
by
Stefan Bley
Committed by
Spencer Gibb
Feb 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate adding X-ForwardedProto header
Add X-Forwarded-Proto header in Zuul PreDecorationFilter even with X-Forwarded-Host header being absent
parent
601e2204
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
1 deletion
+36
-1
PreDecorationFilter.java
...k/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
+2
-0
PreDecorationFilterTests.java
...ud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
+34
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
View file @
53649f60
...
...
@@ -184,6 +184,8 @@ public class PreDecorationFilter extends ZuulFilter {
}
else
{
port
=
request
.
getHeader
(
"X-Forwarded-Port"
)
+
","
+
port
;
}
}
if
(
hasHeader
(
request
,
"X-Forwarded-Proto"
))
{
proto
=
request
.
getHeader
(
"X-Forwarded-Proto"
)
+
","
+
proto
;
}
ctx
.
addZuulRequestHeader
(
"X-Forwarded-Host"
,
host
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
View file @
53649f60
...
...
@@ -104,7 +104,7 @@ public class PreDecorationFilterTests {
}
@Test
public
void
xForwardedHostA
ppends
()
throws
Exception
{
public
void
xForwardedHostA
ndProtoAppend
()
throws
Exception
{
this
.
properties
.
setPrefix
(
"/api"
);
this
.
request
.
setRequestURI
(
"/api/foo/1"
);
this
.
request
.
setRemoteAddr
(
"5.6.7.8"
);
...
...
@@ -121,6 +121,39 @@ public class PreDecorationFilterTests {
}
@Test
public
void
xForwardedHostOnlyAppends
()
throws
Exception
{
this
.
properties
.
setPrefix
(
"/api"
);
this
.
request
.
setRequestURI
(
"/api/foo/1"
);
this
.
request
.
setRemoteAddr
(
"5.6.7.8"
);
this
.
request
.
setServerPort
(
8080
);
this
.
request
.
addHeader
(
"X-Forwarded-Host"
,
"example.com"
);
this
.
routeLocator
.
addRoute
(
new
ZuulRoute
(
"foo"
,
"/foo/**"
,
"foo"
,
null
,
false
,
null
,
null
));
this
.
filter
.
run
();
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
assertEquals
(
"example.com,localhost:8080"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-host"
));
assertEquals
(
"8080"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-port"
));
assertEquals
(
"http"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-proto"
));
}
@Test
public
void
xForwardedProtoOnlyAppends
()
throws
Exception
{
this
.
properties
.
setPrefix
(
"/api"
);
this
.
request
.
setRequestURI
(
"/api/foo/1"
);
this
.
request
.
setRemoteAddr
(
"5.6.7.8"
);
this
.
request
.
setServerPort
(
8080
);
this
.
request
.
addHeader
(
"X-Forwarded-Proto"
,
"https"
);
this
.
routeLocator
.
addRoute
(
new
ZuulRoute
(
"foo"
,
"/foo/**"
,
"foo"
,
null
,
false
,
null
,
null
));
this
.
filter
.
run
();
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
assertEquals
(
"localhost:8080"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-host"
));
assertEquals
(
"8080"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-port"
));
assertEquals
(
"https,http"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-proto"
));
}
@Test
public
void
hostHeaderSet
()
throws
Exception
{
this
.
properties
.
setPrefix
(
"/api"
);
this
.
properties
.
setAddHostHeader
(
true
);
...
...
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