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
a00fd2c3
Commit
a00fd2c3
authored
Dec 18, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #663 from jettro/master
* pull663: Case insensitive Content-Encoding check
parents
a61c18c6
f707e5f0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
25 deletions
+85
-25
ProxyRequestHelper.java
...mework/cloud/netflix/zuul/filters/ProxyRequestHelper.java
+21
-11
SendResponseFilter.java
...k/cloud/netflix/zuul/filters/post/SendResponseFilter.java
+9
-4
ProxyRequestHelperTests.java
...k/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java
+55
-10
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelper.java
View file @
a00fd2c3
...
...
@@ -43,6 +43,9 @@ import com.netflix.zuul.util.HTTPRequestUtils;
import
lombok.extern.apachecommons.CommonsLog
;
import
static
org
.
springframework
.
http
.
HttpHeaders
.
CONTENT_ENCODING
;
import
static
org
.
springframework
.
http
.
HttpHeaders
.
CONTENT_LENGTH
;
/**
* @author Dave Syer
*/
...
...
@@ -55,8 +58,6 @@ public class ProxyRequestHelper {
*/
public
static
final
String
IGNORED_HEADERS
=
"ignoredHeaders"
;
public
static
final
String
CONTENT_ENCODING
=
"Content-Encoding"
;
private
TraceRepository
traces
;
public
void
setTraces
(
TraceRepository
traces
)
{
...
...
@@ -124,13 +125,21 @@ public class ProxyRequestHelper {
public
void
setResponse
(
int
status
,
InputStream
entity
,
MultiValueMap
<
String
,
String
>
headers
)
throws
IOException
{
RequestContext
context
=
RequestContext
.
getCurrentContext
();
RequestContext
.
getCurrentContext
()
.
setResponseStatusCode
(
status
);
context
.
setResponseStatusCode
(
status
);
if
(
entity
!=
null
)
{
RequestContext
.
getCurrentContext
().
setResponseDataStream
(
entity
);
context
.
setResponseDataStream
(
entity
);
}
HttpHeaders
httpHeaders
=
new
HttpHeaders
();
for
(
Entry
<
String
,
List
<
String
>>
header
:
headers
.
entrySet
())
{
List
<
String
>
values
=
header
.
getValue
();
for
(
String
value
:
values
)
{
httpHeaders
.
add
(
header
.
getKey
(),
value
);
}
}
boolean
isOriginResponseGzipped
=
false
;
if
(
headers
.
containsKey
(
CONTENT_ENCODING
))
{
Collection
<
String
>
collection
=
h
eaders
.
get
(
CONTENT_ENCODING
);
if
(
h
ttpH
eaders
.
containsKey
(
CONTENT_ENCODING
))
{
List
<
String
>
collection
=
httpH
eaders
.
get
(
CONTENT_ENCODING
);
for
(
String
header
:
collection
)
{
if
(
HTTPRequestUtils
.
getInstance
().
isGzipped
(
header
))
{
isOriginResponseGzipped
=
true
;
...
...
@@ -139,16 +148,16 @@ public class ProxyRequestHelper {
}
}
context
.
setResponseGZipped
(
isOriginResponseGzipped
);
for
(
Entry
<
String
,
List
<
String
>>
header
:
headers
.
entrySet
())
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
String
name
=
header
.
getKey
();
for
(
String
value
:
header
.
getValue
())
{
c
tx
.
addOriginResponseHeader
(
name
,
value
);
if
(
name
.
equalsIgnoreCase
(
"content-length"
))
{
c
tx
.
setOriginContentLength
(
value
);
c
ontext
.
addOriginResponseHeader
(
name
,
value
);
if
(
name
.
equalsIgnoreCase
(
CONTENT_LENGTH
))
{
c
ontext
.
setOriginContentLength
(
value
);
}
if
(
isIncludedHeader
(
name
))
{
c
tx
.
addZuulResponseHeader
(
name
,
value
);
c
ontext
.
addZuulResponseHeader
(
name
,
value
);
}
}
}
...
...
@@ -267,3 +276,4 @@ public class ProxyRequestHelper {
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/post/SendResponseFilter.java
View file @
a00fd2c3
...
...
@@ -22,7 +22,6 @@ import java.io.InputStream;
import
java.io.OutputStream
;
import
java.util.List
;
import
java.util.zip.GZIPInputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.util.ReflectionUtils
;
...
...
@@ -35,10 +34,14 @@ import com.netflix.zuul.ZuulFilter;
import
com.netflix.zuul.constants.ZuulConstants
;
import
com.netflix.zuul.constants.ZuulHeaders
;
import
com.netflix.zuul.context.RequestContext
;
import
com.netflix.zuul.util.HTTPRequestUtils
;
import
lombok.extern.apachecommons.CommonsLog
;
/**
* @author Spencer Gibb
*/
@CommonsLog
public
class
SendResponseFilter
extends
ZuulFilter
{
private
static
DynamicBooleanProperty
INCLUDE_DEBUG_HEADER
=
DynamicPropertyFactory
...
...
@@ -101,7 +104,9 @@ public class SendResponseFilter extends ZuulFilter {
boolean
isGzipRequested
=
false
;
final
String
requestEncoding
=
context
.
getRequest
().
getHeader
(
ZuulHeaders
.
ACCEPT_ENCODING
);
if
(
requestEncoding
!=
null
&&
requestEncoding
.
equals
(
"gzip"
))
{
if
(
requestEncoding
!=
null
&&
HTTPRequestUtils
.
getInstance
().
isGzipped
(
requestEncoding
))
{
isGzipRequested
=
true
;
}
is
=
context
.
getResponseDataStream
();
...
...
@@ -117,8 +122,8 @@ public class SendResponseFilter extends ZuulFilter {
inputStream
=
new
GZIPInputStream
(
is
);
}
catch
(
java
.
util
.
zip
.
ZipException
ex
)
{
System
.
out
.
println
(
"gzip expected but not "
+
"received assuming unencoded response"
log
.
debug
(
"gzip expected but not "
+
"received assuming unencoded response
"
+
RequestContext
.
getCurrentContext
().
getRequest
()
.
getRequestURL
().
toString
());
inputStream
=
is
;
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/ProxyRequestHelperTests.java
View file @
a00fd2c3
...
...
@@ -16,15 +16,7 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
import
java.io.IOException
;
import
java.util.List
;
import
org.junit.Before
;
...
...
@@ -33,12 +25,24 @@ import org.mockito.Mock;
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.mock.web.MockHttpServletRequest
;
import
org.springframework.mock.web.MockHttpServletResponse
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
com.netflix.zuul.context.RequestContext
;
import
static
org
.
hamcrest
.
Matchers
.
contains
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
hamcrest
.
Matchers
.
hasSize
;
import
static
org
.
hamcrest
.
Matchers
.
is
;
import
static
org
.
hamcrest
.
Matchers
.
notNullValue
;
import
static
org
.
hamcrest
.
Matchers
.
nullValue
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
/**
* @author Spencer Gibb
*/
...
...
@@ -71,7 +75,7 @@ public class ProxyRequestHelperTests {
new
LinkedMultiValueMap
<
String
,
String
>(),
request
.
getInputStream
());
Trace
actual
=
this
.
traceRepository
.
findAll
().
get
(
0
);
System
.
err
.
println
(
actual
.
getInfo
());
assertThat
((
String
)
actual
.
getInfo
().
get
(
"body"
),
equalTo
(
"{}"
));
assertThat
((
String
)
actual
.
getInfo
().
get
(
"body"
),
equalTo
(
"{}"
));
}
...
...
@@ -112,4 +116,45 @@ public class ProxyRequestHelperTests {
assertThat
(
acceptEncodings
,
contains
(
"gzip"
));
}
@Test
public
void
setResponseLowercase
()
throws
IOException
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"POST"
,
"/"
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
RequestContext
context
=
RequestContext
.
getCurrentContext
();
context
.
setRequest
(
request
);
context
.
setResponse
(
response
);
ProxyRequestHelper
helper
=
new
ProxyRequestHelper
();
MultiValueMap
<
String
,
String
>
headers
=
new
HttpHeaders
();
headers
.
add
(
HttpHeaders
.
CONTENT_ENCODING
.
toLowerCase
(),
"gzip"
);
helper
.
setResponse
(
200
,
request
.
getInputStream
(),
headers
);
assertTrue
(
context
.
getResponseGZipped
());
}
@Test
public
void
setResponseUppercase
()
throws
IOException
{
MockHttpServletRequest
request
=
new
MockHttpServletRequest
(
"POST"
,
"/"
);
MockHttpServletResponse
response
=
new
MockHttpServletResponse
();
RequestContext
context
=
RequestContext
.
getCurrentContext
();
context
.
setRequest
(
request
);
context
.
setResponse
(
response
);
ProxyRequestHelper
helper
=
new
ProxyRequestHelper
();
MultiValueMap
<
String
,
String
>
headers
=
new
HttpHeaders
();
headers
.
add
(
HttpHeaders
.
CONTENT_ENCODING
,
"gzip"
);
helper
.
setResponse
(
200
,
request
.
getInputStream
(),
headers
);
assertTrue
(
context
.
getResponseGZipped
());
}
}
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