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
d412df58
Commit
d412df58
authored
Apr 10, 2017
by
Ryan Baxter
Committed by
GitHub
Apr 10, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1808 from gonzalad/1807
Add X-Forwarded-Port header in Zuul
parents
cca37443
31f5a2bb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
13 deletions
+62
-13
PreDecorationFilter.java
...k/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
+12
-12
PreDecorationFilterTests.java
...ud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
+50
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilter.java
View file @
d412df58
...
...
@@ -198,21 +198,21 @@ public class PreDecorationFilter extends ZuulFilter {
String
proto
=
request
.
getScheme
();
if
(
hasHeader
(
request
,
X_FORWARDED_HOST_HEADER
))
{
host
=
request
.
getHeader
(
X_FORWARDED_HOST_HEADER
)
+
","
+
host
;
if
(!
hasHeader
(
request
,
X_FORWARDED_PORT_HEADER
))
{
if
(
hasHeader
(
request
,
X_FORWARDED_PROTO_HEADER
))
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
previous
:
StringUtils
.
commaDelimitedListToStringArray
(
request
.
getHeader
(
X_FORWARDED_PROTO_HEADER
)))
{
if
(
builder
.
length
()>
0
)
{
builder
.
append
(
","
);
}
builder
.
append
(
HTTPS_SCHEME
.
equals
(
previous
)
?
HTTPS_PORT
:
HTTP_PORT
);
}
if
(!
hasHeader
(
request
,
X_FORWARDED_PORT_HEADER
))
{
if
(
hasHeader
(
request
,
X_FORWARDED_PROTO_HEADER
))
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
previous
:
StringUtils
.
commaDelimitedListToStringArray
(
request
.
getHeader
(
X_FORWARDED_PROTO_HEADER
)))
{
if
(
builder
.
length
()>
0
)
{
builder
.
append
(
","
);
}
builder
.
append
(
","
).
append
(
port
);
port
=
builder
.
toString
();
builder
.
append
(
HTTPS_SCHEME
.
equals
(
previous
)
?
HTTPS_PORT
:
HTTP_PORT
);
}
}
else
{
port
=
request
.
getHeader
(
X_FORWARDED_PORT_HEADER
)
+
","
+
port
;
builder
.
append
(
","
).
append
(
port
);
port
=
builder
.
toString
()
;
}
}
else
{
port
=
request
.
getHeader
(
X_FORWARDED_PORT_HEADER
)
+
","
+
port
;
}
if
(
hasHeader
(
request
,
X_FORWARDED_PROTO_HEADER
))
{
proto
=
request
.
getHeader
(
X_FORWARDED_PROTO_HEADER
)
+
","
+
proto
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/pre/PreDecorationFilterTests.java
View file @
d412df58
...
...
@@ -152,7 +152,56 @@ public class PreDecorationFilterTests {
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
(
"443,8080"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-port"
));
assertEquals
(
"https,http"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-proto"
));
}
@Test
public
void
xForwardedProtoHttpOnlyAppends
()
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"
,
"http"
);
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
(
"80,8080"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-port"
));
assertEquals
(
"http,http"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-proto"
));
}
@Test
public
void
xForwardedPortOnlyAppends
()
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-Port"
,
"456"
);
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
(
"456,8080"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-port"
));
assertEquals
(
"http"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-proto"
));
}
@Test
public
void
xForwardedPortAndProtoAppends
()
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
.
request
.
addHeader
(
"X-Forwarded-Port"
,
"456"
);
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
(
"456,8080"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-port"
));
assertEquals
(
"https,http"
,
ctx
.
getZuulRequestHeaders
().
get
(
"x-forwarded-proto"
));
}
...
...
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