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
b8cbf4e6
Commit
b8cbf4e6
authored
Mar 01, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't debug body if zuul servlet or if disabled.
fixes gh-857
parent
28081620
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
5 deletions
+95
-5
ZuulProxyConfiguration.java
...gframework/cloud/netflix/zuul/ZuulProxyConfiguration.java
+1
-0
ProxyRequestHelper.java
...mework/cloud/netflix/zuul/filters/ProxyRequestHelper.java
+12
-5
ZuulProperties.java
...gframework/cloud/netflix/zuul/filters/ZuulProperties.java
+2
-0
ProxyRequestHelperTests.java
...k/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java
+80
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/ZuulProxyConfiguration.java
View file @
b8cbf4e6
...
...
@@ -112,6 +112,7 @@ public class ZuulProxyConfiguration extends ZuulConfiguration {
helper
.
setTraces
(
this
.
traces
);
}
helper
.
setIgnoredHeaders
(
this
.
zuulProperties
.
getIgnoredHeaders
());
helper
.
setTraceRequestBody
(
this
.
zuulProperties
.
isTraceRequestBody
());
return
helper
;
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelper.java
View file @
b8cbf4e6
...
...
@@ -34,6 +34,7 @@ import java.util.Set;
import
javax.servlet.http.HttpServletRequest
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.cloud.netflix.zuul.util.RequestUtils
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
...
...
@@ -69,6 +70,8 @@ public class ProxyRequestHelper {
private
Set
<
String
>
whitelistHosts
=
new
LinkedHashSet
<>();
private
boolean
traceRequestBody
=
true
;
public
void
setWhitelistHosts
(
Set
<
String
>
whitelistHosts
)
{
this
.
whitelistHosts
.
addAll
(
whitelistHosts
);
}
...
...
@@ -85,6 +88,10 @@ public class ProxyRequestHelper {
this
.
traces
=
traces
;
}
public
void
setTraceRequestBody
(
boolean
traceRequestBody
)
{
this
.
traceRequestBody
=
traceRequestBody
;
}
public
String
buildZuulRequestURI
(
HttpServletRequest
request
)
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
String
uri
=
request
.
getRequestURI
();
...
...
@@ -225,7 +232,7 @@ public class ProxyRequestHelper {
public
Map
<
String
,
Object
>
debug
(
String
verb
,
String
uri
,
MultiValueMap
<
String
,
String
>
headers
,
MultiValueMap
<
String
,
String
>
params
,
InputStream
requestEntity
)
throws
IOException
{
Map
<
String
,
Object
>
info
=
new
LinkedHashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
info
=
new
LinkedHashMap
<>();
if
(
this
.
traces
!=
null
)
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
info
.
put
(
"method"
,
verb
);
...
...
@@ -233,8 +240,8 @@ public class ProxyRequestHelper {
info
.
put
(
"query"
,
getQueryString
(
params
));
info
.
put
(
"remote"
,
true
);
info
.
put
(
"proxy"
,
context
.
get
(
"proxy"
));
Map
<
String
,
Object
>
trace
=
new
LinkedHashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
input
=
new
LinkedHashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
trace
=
new
LinkedHashMap
<>();
Map
<
String
,
Object
>
input
=
new
LinkedHashMap
<>();
trace
.
put
(
"request"
,
input
);
info
.
put
(
"headers"
,
trace
);
for
(
Entry
<
String
,
List
<
String
>>
entry
:
headers
.
entrySet
())
{
...
...
@@ -258,9 +265,9 @@ public class ProxyRequestHelper {
return
info
;
}
private
boolean
shouldDebugBody
(
RequestContext
ctx
)
{
/* for tests */
boolean
shouldDebugBody
(
RequestContext
ctx
)
{
HttpServletRequest
request
=
ctx
.
getRequest
();
if
(
ctx
.
isChunkedRequestBody
())
{
if
(
!
this
.
traceRequestBody
||
ctx
.
isChunkedRequestBody
()
||
RequestUtils
.
isZuulServletRequest
())
{
return
false
;
}
if
(
request
==
null
||
request
.
getContentType
()
==
null
)
{
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ZuulProperties.java
View file @
b8cbf4e6
...
...
@@ -72,6 +72,8 @@ public class ZuulProperties {
private
Host
host
=
new
Host
();
private
boolean
traceRequestBody
=
true
;
public
Set
<
String
>
getIgnoredHeaders
()
{
Set
<
String
>
ignoredHeaders
=
new
LinkedHashSet
<>(
this
.
ignoredHeaders
);
if
(
ClassUtils
.
isPresent
(
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java
View file @
b8cbf4e6
...
...
@@ -26,6 +26,7 @@ import org.springframework.boot.actuate.trace.InMemoryTraceRepository;
import
org.springframework.boot.actuate.trace.Trace
;
import
org.springframework.boot.actuate.trace.TraceRepository
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.util.LinkedMultiValueMap
;
...
...
@@ -86,6 +87,85 @@ public class ProxyRequestHelperTests {
}
@Test
public
void
shouldDebugBodyDisabled
()
throws
Exception
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
ProxyRequestHelper
helper
=
new
ProxyRequestHelper
();
helper
.
setTraceRequestBody
(
false
);
assertThat
(
"shouldDebugBody wrong"
,
helper
.
shouldDebugBody
(
context
),
is
(
false
));
}
@Test
public
void
shouldDebugBodyChunked
()
throws
Exception
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"POST"
,
"/"
);
RequestContext
context
=
RequestContext
.
getCurrentContext
();
context
.
setChunkedRequestBody
();
context
.
setRequest
(
request
);
ProxyRequestHelper
helper
=
new
ProxyRequestHelper
();
assertThat
(
"shouldDebugBody wrong"
,
helper
.
shouldDebugBody
(
context
),
is
(
false
));
}
@Test
public
void
shouldDebugBodyServlet
()
throws
Exception
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"POST"
,
"/"
);
RequestContext
context
=
RequestContext
.
getCurrentContext
();
context
.
setZuulEngineRan
();
context
.
setRequest
(
request
);
ProxyRequestHelper
helper
=
new
ProxyRequestHelper
();
assertThat
(
"shouldDebugBody wrong"
,
helper
.
shouldDebugBody
(
context
),
is
(
false
));
}
@Test
public
void
shouldDebugBodyNullContentType
()
throws
Exception
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"POST"
,
"/"
);
request
.
setContentType
(
null
);
RequestContext
context
=
RequestContext
.
getCurrentContext
();
context
.
setRequest
(
request
);
ProxyRequestHelper
helper
=
new
ProxyRequestHelper
();
assertThat
(
"shouldDebugBody wrong"
,
helper
.
shouldDebugBody
(
context
),
is
(
true
));
}
@Test
public
void
shouldDebugBodyNullRequest
()
throws
Exception
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
ProxyRequestHelper
helper
=
new
ProxyRequestHelper
();
assertThat
(
"shouldDebugBody wrong"
,
helper
.
shouldDebugBody
(
context
),
is
(
true
));
}
@Test
public
void
shouldDebugBodyNotMultitypeContentType
()
throws
Exception
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"POST"
,
"/"
);
request
.
setContentType
(
MediaType
.
APPLICATION_JSON_VALUE
);
RequestContext
context
=
RequestContext
.
getCurrentContext
();
context
.
setRequest
(
request
);
ProxyRequestHelper
helper
=
new
ProxyRequestHelper
();
assertThat
(
"shouldDebugBody wrong"
,
helper
.
shouldDebugBody
(
context
),
is
(
true
));
}
@Test
public
void
shouldDebugBodyMultitypeContentType
()
throws
Exception
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"POST"
,
"/"
);
request
.
setContentType
(
MediaType
.
MULTIPART_FORM_DATA_VALUE
);
RequestContext
context
=
RequestContext
.
getCurrentContext
();
context
.
setRequest
(
request
);
ProxyRequestHelper
helper
=
new
ProxyRequestHelper
();
assertThat
(
"shouldDebugBody wrong"
,
helper
.
shouldDebugBody
(
context
),
is
(
false
));
}
@Test
public
void
buildZuulRequestHeadersWork
()
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"GET"
,
"/"
);
request
.
addHeader
(
"singleName"
,
"singleValue"
);
...
...
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