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
d62c788c
Commit
d62c788c
authored
May 14, 2018
by
Mário Buratto
Committed by
Ryan Baxter
May 14, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed content length handling issues. (#2894) (#2920)
* Fixed content length handling issues. (#2894) * Added test setup and cleanup for RequestContext. (#2894)
parent
21ff95e9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
3 deletions
+39
-3
SimpleHostRoutingFilter.java
...d/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
+39
-3
SimpleHostRoutingFilterTests.java
...flix/zuul/filters/route/SimpleHostRoutingFilterTests.java
+0
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilter.java
View file @
d62c788c
...
...
@@ -35,6 +35,7 @@ import org.apache.http.Header;
import
org.apache.http.HttpHost
;
import
org.apache.http.HttpRequest
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.config.CookieSpecs
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
...
...
@@ -56,6 +57,7 @@ import org.springframework.cloud.netflix.zuul.filters.ZuulProperties;
import
org.springframework.cloud.netflix.zuul.filters.ZuulProperties.Host
;
import
org.springframework.cloud.netflix.zuul.util.ZuulRuntimeException
;
import
org.springframework.context.event.EventListener
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.StringUtils
;
...
...
@@ -91,6 +93,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
private
HttpClientConnectionManager
connectionManager
;
private
CloseableHttpClient
httpClient
;
private
boolean
customHttpClient
=
false
;
private
boolean
useServlet31
=
true
;
@EventListener
public
void
onPropertyChange
(
EnvironmentChangeEvent
event
)
{
...
...
@@ -125,6 +128,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
.
isForceOriginalQueryStringEncoding
();
this
.
connectionManagerFactory
=
connectionManagerFactory
;
this
.
httpClientFactory
=
httpClientFactory
;
checkServletVersion
();
}
public
SimpleHostRoutingFilter
(
ProxyRequestHelper
helper
,
ZuulProperties
properties
,
...
...
@@ -136,6 +140,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
.
isForceOriginalQueryStringEncoding
();
this
.
httpClient
=
httpClient
;
this
.
customHttpClient
=
true
;
checkServletVersion
();
}
@PostConstruct
...
...
@@ -191,7 +196,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
.
buildZuulRequestQueryParams
(
request
);
String
verb
=
getVerb
(
request
);
InputStream
requestEntity
=
getRequestBody
(
request
);
if
(
request
.
getContentLength
(
)
<
0
)
{
if
(
getContentLength
(
request
)
<
0
)
{
context
.
setChunkedRequestBody
();
}
...
...
@@ -209,6 +214,21 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
return
null
;
}
protected
void
checkServletVersion
()
{
// To support Servlet API 3.1 we need to check if getContentLengthLong exists
// Spring 5 minimum support is 3.0, so this stays
try
{
HttpServletRequest
.
class
.
getMethod
(
"getContentLengthLong"
);
useServlet31
=
true
;
}
catch
(
NoSuchMethodException
e
)
{
useServlet31
=
false
;
}
}
protected
void
setUseServlet31
(
boolean
useServlet31
)
{
this
.
useServlet31
=
useServlet31
;
}
protected
HttpClientConnectionManager
getConnectionManager
()
{
return
connectionManager
;
}
...
...
@@ -232,7 +252,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
URL
host
=
RequestContext
.
getCurrentContext
().
getRouteHost
();
HttpHost
httpHost
=
getHttpHost
(
host
);
uri
=
StringUtils
.
cleanPath
((
host
.
getPath
()
+
uri
).
replaceAll
(
"/{2,}"
,
"/"
));
int
contentLength
=
request
.
getContentLength
(
);
long
contentLength
=
getContentLength
(
request
);
ContentType
contentType
=
null
;
...
...
@@ -376,4 +396,19 @@ public class SimpleHostRoutingFilter extends ZuulFilter {
boolean
isSslHostnameValidationEnabled
()
{
return
this
.
sslHostnameValidationEnabled
;
}
}
// Get the header value as a long in order to more correctly proxy very large requests
protected
long
getContentLength
(
HttpServletRequest
request
)
{
if
(
useServlet31
){
return
request
.
getContentLengthLong
();
}
String
contentLengthHeader
=
request
.
getHeader
(
HttpHeaders
.
CONTENT_LENGTH
);
if
(
contentLengthHeader
!=
null
)
{
try
{
return
Long
.
parseLong
(
contentLengthHeader
);
}
catch
(
NumberFormatException
e
){}
}
return
request
.
getContentLength
();
}
}
\ No newline at end of file
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/zuul/filters/route/SimpleHostRoutingFilterTests.java
View file @
d62c788c
This diff is collapsed.
Click to expand it.
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