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
22248dd9
Unverified
Commit
22248dd9
authored
Jan 12, 2017
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1591 from tranhungt/gzip_decompression
* gzip_decompression: Disables httpclient auto decompression of encoded data
parents
b27ba043
6dfc7a81
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
0 deletions
+94
-0
SimpleHostRoutingFilter.java
...d/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
+1
-0
SimpleHostRoutingFilterTests.java
...flix/zuul/filters/route/SimpleHostRoutingFilterTests.java
+93
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
View file @
22248dd9
...
...
@@ -245,6 +245,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
httpClientBuilder
.
setSSLHostnameVerifier
(
NoopHostnameVerifier
.
INSTANCE
);
}
return
httpClientBuilder
.
setConnectionManager
(
newConnectionManager
())
.
disableContentCompression
()
.
useSystemProperties
().
setDefaultRequestConfig
(
requestConfig
)
.
setRetryHandler
(
new
DefaultHttpRequestRetryHandler
(
0
,
false
))
.
setRedirectStrategy
(
new
RedirectStrategy
()
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilterTests.java
View file @
22248dd9
...
...
@@ -17,36 +17,68 @@
package
org
.
springframework
.
cloud
.
netflix
.
zuul
.
filters
.
route
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.nio.charset.Charset
;
import
java.util.Arrays
;
import
java.util.zip.GZIPOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.http.HttpEntityEnclosingRequest
;
import
org.apache.http.HttpHost
;
import
org.apache.http.HttpRequest
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.entity.InputStreamEntity
;
import
org.apache.http.impl.conn.PoolingHttpClientConnectionManager
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.context.embedded.LocalServerPort
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper
;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.mock.web.MockHttpServletRequest
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.StreamUtils
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
springframework
.
boot
.
test
.
context
.
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
;
import
static
org
.
springframework
.
boot
.
test
.
util
.
EnvironmentTestUtils
.
addEnvironment
;
import
static
org
.
springframework
.
util
.
StreamUtils
.
copyToByteArray
;
import
static
org
.
springframework
.
util
.
StreamUtils
.
copyToString
;
/**
* @author Andreas Kluth
* @author Spencer Gibb
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
SampleApplication
.
class
,
webEnvironment
=
RANDOM_PORT
,
properties
=
"server.contextPath: /app"
)
@DirtiesContext
public
class
SimpleHostRoutingFilterTests
{
private
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
();
@LocalServerPort
private
int
port
;
@After
public
void
clear
()
{
if
(
this
.
context
!=
null
)
{
...
...
@@ -99,6 +131,32 @@ public class SimpleHostRoutingFilterTests {
assertTrue
(
httpEntityEnclosingRequest
.
getEntity
()
!=
null
);
}
@Test
public
void
httpClientDoesNotDecompressEncodedData
()
throws
Exception
{
setupContext
();
InputStreamEntity
inputStreamEntity
=
new
InputStreamEntity
(
new
ByteArrayInputStream
(
new
byte
[]{
1
}));
HttpRequest
httpRequest
=
getFilter
().
buildHttpRequest
(
"GET"
,
"/app/compressed/get/1"
,
inputStreamEntity
,
new
LinkedMultiValueMap
<
String
,
String
>(),
new
LinkedMultiValueMap
<
String
,
String
>(),
new
MockHttpServletRequest
());
CloseableHttpResponse
response
=
getFilter
().
newClient
().
execute
(
new
HttpHost
(
"localhost"
,
this
.
port
),
httpRequest
);
assertEquals
(
200
,
response
.
getStatusLine
().
getStatusCode
());
byte
[]
responseBytes
=
copyToByteArray
(
response
.
getEntity
().
getContent
());
assertTrue
(
Arrays
.
equals
(
GZIPCompression
.
compress
(
"Get 1"
),
responseBytes
));
}
@Test
public
void
httpClientPreservesUnencodedData
()
throws
Exception
{
setupContext
();
InputStreamEntity
inputStreamEntity
=
new
InputStreamEntity
(
new
ByteArrayInputStream
(
new
byte
[]{
1
}));
HttpRequest
httpRequest
=
getFilter
().
buildHttpRequest
(
"GET"
,
"/app/get/1"
,
inputStreamEntity
,
new
LinkedMultiValueMap
<
String
,
String
>(),
new
LinkedMultiValueMap
<
String
,
String
>(),
new
MockHttpServletRequest
());
CloseableHttpResponse
response
=
getFilter
().
newClient
().
execute
(
new
HttpHost
(
"localhost"
,
this
.
port
),
httpRequest
);
assertEquals
(
200
,
response
.
getStatusLine
().
getStatusCode
());
String
responseString
=
copyToString
(
response
.
getEntity
().
getContent
(),
Charset
.
forName
(
"UTF-8"
));
assertTrue
(
"Get 1"
.
equals
(
responseString
));
}
private
void
setupContext
()
{
this
.
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
...
...
@@ -118,3 +176,38 @@ public class SimpleHostRoutingFilterTests {
}
}
}
@Configuration
@EnableAutoConfiguration
@RestController
class
SampleApplication
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SampleApplication
.
class
,
args
);
}
@RequestMapping
(
value
=
"/compressed/get/{id}"
,
method
=
RequestMethod
.
GET
)
public
byte
[]
getCompressed
(
@PathVariable
String
id
,
HttpServletResponse
response
)
throws
IOException
{
response
.
setHeader
(
"content-encoding"
,
"gzip"
);
return
GZIPCompression
.
compress
(
"Get "
+
id
);
}
@RequestMapping
(
value
=
"/get/{id}"
,
method
=
RequestMethod
.
GET
)
public
String
getString
(
@PathVariable
String
id
,
HttpServletResponse
response
)
throws
IOException
{
return
"Get "
+
id
;
}
}
class
GZIPCompression
{
public
static
byte
[]
compress
(
final
String
str
)
throws
IOException
{
if
((
str
==
null
)
||
(
str
.
length
()
==
0
))
{
return
null
;
}
ByteArrayOutputStream
obj
=
new
ByteArrayOutputStream
();
GZIPOutputStream
gzip
=
new
GZIPOutputStream
(
obj
);
gzip
.
write
(
str
.
getBytes
(
"UTF-8"
));
gzip
.
close
();
return
obj
.
toByteArray
();
}
}
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