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
88396411
Commit
88396411
authored
Jan 21, 2017
by
Jin Zhang
Committed by
Spencer Gibb
Jan 20, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve efficiency of SendResponseFilter#addResponseHeaders() (#1622)
parent
42931f93
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
13 deletions
+41
-13
SendResponseFilter.java
...k/cloud/netflix/zuul/filters/post/SendResponseFilter.java
+11
-13
SendResponseFilterTests.java
...ud/netflix/zuul/filters/post/SendResponseFilterTests.java
+30
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilter.java
View file @
88396411
...
...
@@ -199,30 +199,28 @@ public class SendResponseFilter extends ZuulFilter {
private
void
addResponseHeaders
()
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
HttpServletResponse
servletResponse
=
context
.
getResponse
();
List
<
Pair
<
String
,
String
>>
zuulResponseHeaders
=
context
.
getZuulResponseHeaders
();
@SuppressWarnings
(
"unchecked"
)
List
<
String
>
rd
=
(
List
<
String
>)
RequestContext
.
getCurrentContext
()
.
get
(
"routingDebug"
);
if
(
rd
!=
null
)
{
StringBuilder
debugHeader
=
new
StringBuilder
();
for
(
String
it
:
rd
)
{
debugHeader
.
append
(
"[[["
+
it
+
"]]]"
);
}
if
(
INCLUDE_DEBUG_HEADER
.
get
())
{
if
(
INCLUDE_DEBUG_HEADER
.
get
())
{
@SuppressWarnings
(
"unchecked"
)
List
<
String
>
rd
=
(
List
<
String
>)
context
.
get
(
"routingDebug"
);
if
(
rd
!=
null
)
{
StringBuilder
debugHeader
=
new
StringBuilder
();
for
(
String
it
:
rd
)
{
debugHeader
.
append
(
"[[["
+
it
+
"]]]"
);
}
servletResponse
.
addHeader
(
"X-Zuul-Debug-Header"
,
debugHeader
.
toString
());
}
}
List
<
Pair
<
String
,
String
>>
zuulResponseHeaders
=
context
.
getZuulResponseHeaders
();
if
(
zuulResponseHeaders
!=
null
)
{
for
(
Pair
<
String
,
String
>
it
:
zuulResponseHeaders
)
{
servletResponse
.
addHeader
(
it
.
first
(),
it
.
second
());
}
}
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
Long
contentLength
=
ctx
.
getOriginContentLength
();
// Only inserts Content-Length if origin provides it and origin response is not
// gzipped
if
(
SET_CONTENT_LENGTH
.
get
())
{
if
(
contentLength
!=
null
&&
!
ctx
.
getResponseGZipped
())
{
Long
contentLength
=
context
.
getOriginContentLength
();
if
(
contentLength
!=
null
&&
!
context
.
getResponseGZipped
())
{
if
(
useServlet31
)
{
servletResponse
.
setContentLengthLong
(
contentLength
);
}
else
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilterTests.java
View file @
88396411
...
...
@@ -19,6 +19,9 @@ package org.springframework.cloud.netflix.zuul.filters.post;
import
java.io.ByteArrayInputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
com.netflix.config.ConfigurationManager
;
import
com.netflix.zuul.constants.ZuulConstants
;
import
com.netflix.zuul.context.Debug
;
import
com.netflix.zuul.context.RequestContext
;
import
org.junit.After
;
...
...
@@ -64,6 +67,33 @@ public class SendResponseFilterTests {
runFilter
(
characterEncoding
,
content
,
true
);
}
@Test
public
void
runWithDebugHeader
()
throws
Exception
{
ConfigurationManager
.
getConfigInstance
().
setProperty
(
ZuulConstants
.
ZUUL_INCLUDE_DEBUG_HEADER
,
true
);
SendResponseFilter
filter
=
createFilter
(
"hello"
,
null
,
new
MockHttpServletResponse
(),
false
);
Debug
.
addRoutingDebug
(
"test"
);
filter
.
run
();
String
debugHeader
=
RequestContext
.
getCurrentContext
().
getResponse
()
.
getHeader
(
"X-Zuul-Debug-Header"
);
assertThat
(
"wrong debug header"
,
debugHeader
,
equalTo
(
"[[[test]]]"
));
}
@Test
public
void
runWithOriginContentLength
()
throws
Exception
{
ConfigurationManager
.
getConfigInstance
().
setProperty
(
ZuulConstants
.
ZUUL_SET_CONTENT_LENGTH
,
true
);
SendResponseFilter
filter
=
createFilter
(
"hello"
,
null
,
new
MockHttpServletResponse
(),
false
);
RequestContext
.
getCurrentContext
().
setOriginContentLength
(
6L
);
// for test
RequestContext
.
getCurrentContext
().
setResponseGZipped
(
false
);
filter
.
run
();
String
contentLength
=
RequestContext
.
getCurrentContext
().
getResponse
()
.
getHeader
(
"Content-Length"
);
assertThat
(
"wrong origin content length"
,
contentLength
,
equalTo
(
"6"
));
}
private
void
runFilter
(
String
characterEncoding
,
String
content
,
boolean
streamContent
)
throws
Exception
{
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
SendResponseFilter
filter
=
createFilter
(
content
,
characterEncoding
,
response
,
streamContent
);
...
...
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