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
a2e1836e
Unverified
Commit
a2e1836e
authored
Feb 01, 2017
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1656 from sbley/master
* pull1656: Separate adding X-ForwardedProto header
parents
601e2204
53649f60
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 @
a2e1836e
...
@@ -184,6 +184,8 @@ public class PreDecorationFilter extends ZuulFilter {
...
@@ -184,6 +184,8 @@ public class PreDecorationFilter extends ZuulFilter {
}
else
{
}
else
{
port
=
request
.
getHeader
(
"X-Forwarded-Port"
)
+
","
+
port
;
port
=
request
.
getHeader
(
"X-Forwarded-Port"
)
+
","
+
port
;
}
}
}
if
(
hasHeader
(
request
,
"X-Forwarded-Proto"
))
{
proto
=
request
.
getHeader
(
"X-Forwarded-Proto"
)
+
","
+
proto
;
proto
=
request
.
getHeader
(
"X-Forwarded-Proto"
)
+
","
+
proto
;
}
}
ctx
.
addZuulRequestHeader
(
"X-Forwarded-Host"
,
host
);
ctx
.
addZuulRequestHeader
(
"X-Forwarded-Host"
,
host
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
View file @
a2e1836e
...
@@ -104,7 +104,7 @@ public class PreDecorationFilterTests {
...
@@ -104,7 +104,7 @@ public class PreDecorationFilterTests {
}
}
@Test
@Test
public
void
xForwardedHostA
ppends
()
throws
Exception
{
public
void
xForwardedHostA
ndProtoAppend
()
throws
Exception
{
this
.
properties
.
setPrefix
(
"/api"
);
this
.
properties
.
setPrefix
(
"/api"
);
this
.
request
.
setRequestURI
(
"/api/foo/1"
);
this
.
request
.
setRequestURI
(
"/api/foo/1"
);
this
.
request
.
setRemoteAddr
(
"5.6.7.8"
);
this
.
request
.
setRemoteAddr
(
"5.6.7.8"
);
...
@@ -121,6 +121,39 @@ public class PreDecorationFilterTests {
...
@@ -121,6 +121,39 @@ public class PreDecorationFilterTests {
}
}
@Test
@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
{
public
void
hostHeaderSet
()
throws
Exception
{
this
.
properties
.
setPrefix
(
"/api"
);
this
.
properties
.
setPrefix
(
"/api"
);
this
.
properties
.
setAddHostHeader
(
true
);
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