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
92667851
Commit
92667851
authored
Dec 21, 2014
by
Julien Roy
Committed by
Dave Syer
Jan 01, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Zuul proxy POST on content-type with charset
Fixes gh-113
parent
9c416bf6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
3 deletions
+25
-3
FormBodyWrapperFilter.java
...cloud/netflix/zuul/filters/pre/FormBodyWrapperFilter.java
+13
-3
FormZuulProxyApplicationTests.java
...ork/cloud/netflix/zuul/FormZuulProxyApplicationTests.java
+12
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/pre/FormBodyWrapperFilter.java
View file @
92667851
...
...
@@ -8,6 +8,7 @@ import javax.servlet.ServletInputStream;
import
javax.servlet.http.HttpServletRequest
;
import
org.apache.commons.io.Charsets
;
import
org.springframework.http.InvalidMediaTypeException
;
import
org.springframework.http.MediaType
;
import
org.springframework.util.Assert
;
import
org.springframework.util.ReflectionUtils
;
...
...
@@ -45,10 +46,19 @@ public class FormBodyWrapperFilter extends ZuulFilter {
public
boolean
shouldFilter
()
{
RequestContext
ctx
=
RequestContext
.
getCurrentContext
();
HttpServletRequest
request
=
ctx
.
getRequest
();
if
(
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
.
equals
(
request
.
getContentType
()))
{
return
true
;
String
contentType
=
request
.
getContentType
();
//Don't use this filter on GET method
if
(
contentType
==
null
)
{
return
false
;
}
//Only use this filter for MediaType : application/x-www-form-urlencoded
try
{
return
MediaType
.
APPLICATION_FORM_URLENCODED
.
includes
(
MediaType
.
valueOf
(
contentType
));
}
catch
(
InvalidMediaTypeException
imte
)
{
return
false
;
}
return
false
;
}
@Override
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/FormZuulProxyApplicationTests.java
View file @
92667851
...
...
@@ -68,6 +68,18 @@ public class FormZuulProxyApplicationTests {
assertEquals
(
"Posted! {foo=[bar]}"
,
result
.
getBody
());
}
@Test
public
void
postWithUTF8Form
()
{
MultiValueMap
<
String
,
String
>
form
=
new
LinkedMultiValueMap
<
String
,
String
>();
form
.
set
(
"foo"
,
"bar"
);
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
valueOf
(
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
+
"; charset=UTF-8"
));
ResponseEntity
<
String
>
result
=
new
TestRestTemplate
().
exchange
(
"http://localhost:"
+
port
+
"/simple"
,
HttpMethod
.
POST
,
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
form
,
headers
),
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
result
.
getStatusCode
());
assertEquals
(
"Posted! {foo=[bar]}"
,
result
.
getBody
());
}
}
//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