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
283c0f76
Commit
283c0f76
authored
Jun 22, 2015
by
Brandon Atkinson
Committed by
Spencer Gibb
Jun 23, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix unescaped paths in SimpleHostRoutingFilter.
Move common code so RibbonRoutingFilter can use the same code. Fixes gh-407
parent
0b925e5a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
10 deletions
+34
-10
ProxyRequestHelper.java
...mework/cloud/netflix/zuul/filters/ProxyRequestHelper.java
+18
-0
RibbonCommand.java
...ework/cloud/netflix/zuul/filters/route/RibbonCommand.java
+1
-1
RibbonRoutingFilter.java
...cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
+2
-4
SimpleHostRoutingFilter.java
...d/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
+1
-4
SampleZuulProxyApplicationTests.java
...k/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
+12
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelper.java
View file @
283c0f76
...
@@ -29,6 +29,7 @@ import java.util.Set;
...
@@ -29,6 +29,7 @@ import java.util.Set;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
lombok.extern.apachecommons.CommonsLog
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.LinkedMultiValueMap
;
...
@@ -37,10 +38,13 @@ import org.springframework.util.StringUtils;
...
@@ -37,10 +38,13 @@ import org.springframework.util.StringUtils;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.util.HTTPRequestUtils
;
import
com.netflix.zuul.util.HTTPRequestUtils
;
import
org.springframework.web.util.UriUtils
;
import
org.springframework.web.util.WebUtils
;
/**
/**
* @author Dave Syer
* @author Dave Syer
*/
*/
@CommonsLog
public
class
ProxyRequestHelper
{
public
class
ProxyRequestHelper
{
/**
/**
...
@@ -57,6 +61,20 @@ public class ProxyRequestHelper {
...
@@ -57,6 +61,20 @@ public class ProxyRequestHelper {
this
.
traces
=
traces
;
this
.
traces
=
traces
;
}
}
public
String
buildZuulRequestURI
(
HttpServletRequest
request
)
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
String
uri
=
request
.
getRequestURI
();
String
contextURI
=
(
String
)
context
.
get
(
"requestURI"
);
if
(
contextURI
!=
null
)
{
try
{
uri
=
UriUtils
.
encodePath
(
contextURI
,
WebUtils
.
DEFAULT_CHARACTER_ENCODING
);
}
catch
(
Exception
e
)
{
log
.
debug
(
"unable to encode uri path from context, falling back to uri from request"
,
e
);
}
}
return
uri
;
}
public
MultiValueMap
<
String
,
String
>
buildZuulRequestQueryParams
(
public
MultiValueMap
<
String
,
String
>
buildZuulRequestQueryParams
(
HttpServletRequest
request
)
{
HttpServletRequest
request
)
{
Map
<
String
,
List
<
String
>>
map
=
HTTPRequestUtils
.
getInstance
().
getQueryParams
();
Map
<
String
,
List
<
String
>>
map
=
HTTPRequestUtils
.
getInstance
().
getQueryParams
();
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonCommand.java
View file @
283c0f76
...
@@ -80,7 +80,7 @@ public class RibbonCommand extends HystrixCommand<HttpResponse> {
...
@@ -80,7 +80,7 @@ public class RibbonCommand extends HystrixCommand<HttpResponse> {
super
(
getSetter
(
commandKey
));
super
(
getSetter
(
commandKey
));
this
.
restClient
=
restClient
;
this
.
restClient
=
restClient
;
this
.
verb
=
verb
;
this
.
verb
=
verb
;
this
.
uri
=
(
StringUtils
.
hasText
(
uri
))?
UriComponentsBuilder
.
fromUriString
(
uri
).
build
().
toUri
()
:
new
URI
(
uri
);
this
.
uri
=
new
URI
(
uri
);
this
.
retryable
=
retryable
;
this
.
retryable
=
retryable
;
this
.
headers
=
headers
;
this
.
headers
=
headers
;
this
.
params
=
params
;
this
.
params
=
params
;
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/RibbonRoutingFilter.java
View file @
283c0f76
...
@@ -95,10 +95,8 @@ public class RibbonRoutingFilter extends ZuulFilter {
...
@@ -95,10 +95,8 @@ public class RibbonRoutingFilter extends ZuulFilter {
RestClient
restClient
=
this
.
clientFactory
.
getClient
(
serviceId
,
RestClient
.
class
);
RestClient
restClient
=
this
.
clientFactory
.
getClient
(
serviceId
,
RestClient
.
class
);
String
uri
=
request
.
getRequestURI
();
String
uri
=
this
.
helper
.
buildZuulRequestURI
(
request
);
if
(
context
.
get
(
"requestURI"
)
!=
null
)
{
uri
=
(
String
)
context
.
get
(
"requestURI"
);
}
// remove double slashes
// remove double slashes
uri
=
uri
.
replace
(
"//"
,
"/"
);
uri
=
uri
.
replace
(
"//"
,
"/"
);
String
service
=
(
String
)
context
.
get
(
"serviceId"
);
String
service
=
(
String
)
context
.
get
(
"serviceId"
);
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
View file @
283c0f76
...
@@ -168,10 +168,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
...
@@ -168,10 +168,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
InputStream
requestEntity
=
getRequestBody
(
request
);
InputStream
requestEntity
=
getRequestBody
(
request
);
HttpClient
httpclient
=
CLIENT
.
get
();
HttpClient
httpclient
=
CLIENT
.
get
();
String
uri
=
request
.
getRequestURI
();
String
uri
=
this
.
helper
.
buildZuulRequestURI
(
request
);
if
(
context
.
get
(
"requestURI"
)
!=
null
)
{
uri
=
(
String
)
context
.
get
(
"requestURI"
);
}
try
{
try
{
HttpResponse
response
=
forward
(
httpclient
,
verb
,
uri
,
request
,
headers
,
HttpResponse
response
=
forward
(
httpclient
,
verb
,
uri
,
request
,
headers
,
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/SampleZuulProxyApplicationTests.java
View file @
283c0f76
...
@@ -134,7 +134,7 @@ public class SampleZuulProxyApplicationTests {
...
@@ -134,7 +134,7 @@ public class SampleZuulProxyApplicationTests {
}
}
@Test
@Test
public
void
routeWithSpace
()
{
public
void
r
ibbonR
outeWithSpace
()
{
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/simple/spa ce"
,
"http://localhost:"
+
this
.
port
+
"/simple/spa ce"
,
HttpMethod
.
GET
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
);
HttpMethod
.
GET
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
);
...
@@ -142,6 +142,17 @@ public class SampleZuulProxyApplicationTests {
...
@@ -142,6 +142,17 @@ public class SampleZuulProxyApplicationTests {
assertEquals
(
"Hello space"
,
result
.
getBody
());
assertEquals
(
"Hello space"
,
result
.
getBody
());
}
}
@Test
public
void
simpleHostRouteWithSpace
()
{
routes
.
addRoute
(
"/self/**"
,
"http://localhost:"
+
this
.
port
);
this
.
endpoint
.
reset
();
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
this
.
port
+
"/self/spa ce"
,
HttpMethod
.
GET
,
new
HttpEntity
<>((
Void
)
null
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Hello space"
,
result
.
getBody
());
}
}
}
// Don't use @SpringBootApplication because we don't want to component scan
// Don't use @SpringBootApplication because we don't want to component scan
...
...
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