Hi,

Zuul's SimpleHostRoutingFilter drops the request entity if the HTTP is not one of POST, PUT, PATCH, DELETE (e.g., GET). However, for products such as Elasticsearch, GET with a body is used to answer search requests (see https://www.elastic.co/guide/en/elasticsearch/guide/current/_empty_search.html). Is the switch statement on the HTTP verb in SimpleHostRoutingFilter.buildHttpRequest() really neeeded? We could always add the entity to the http request regardless of the verb as so:

BasicHttpEntityEnclosingRequest entityRequest = new BasicHttpEntityEnclosingRequest(verb, uriWithQueryString);
httpRequest = entityRequest;
entityRequest.setEntity(entity);

Additionally, by default Tomcat drops the body if the Content-Type is application/x-www-form-urlencoded and the HTTP method is not POST. This behavior could be changed through org.apache.catalina.connector.Connector.setParseBodyMethods() and a TomcatConnectorCustomizer.

Best, Gary

Comment From: lowzj

Similar issue caused by FormBodyWrapperFilter, if a request satisfies these conditions: * request method type is not POST(tomcat, jetty), PUT(only jetty) * content-type is: application/x-www-form-urlencoded * has request body

then the request body will be dropped. It was caused by the method RequestContentDataExtractor#extract(HttpServletRequest) in FormBodyWrapperFilter#buildContentData(). It will call Request#getParameterMap() to get query parameters and content parameters(request body). By default, it will not parse the request body to content parameters if the form request's method type is not POST/PUT(only jetty).

Comment From: ryanjbaxter

Feel free to submit a PR with some proposed changes.

Comment From: dsyer

The PR was closed without comment. Was that intentional?

Comment From: GJL

@dsyer Yes, it was intentional but I should probably comment. I conducted some tests locally after creating the PR and noticed that BasicHttpEntityEnclosingRequest attempts to chunk the body even if the incoming GET request had no body (see example below).

curl -XGET localhost:8899/test/foo
GET /test/foo HTTP/1.1
user-agent: curl/7.51.0
...
Transfer-Encoding: chunked
Host: localhost:8899
Connection: Keep-Alive

0

Note the header Transfer-Encoding: chunked and the 0 in the body.

For POST, PUT, PATCH, DELETE the behavior did not change, i.e., aPOST request without a body would have been chunked by SimpleHostRoutingFilter as well.

I closed my PR because GET with a chunked empty body might not be accepted by some servers. Fixing this issue probably requires careful consideration of RFC 2616, Section 4.4.

Comment From: spencergibb

This module has entered maintenance mode. This means that the Spring Cloud team will no longer be adding new features to the module. We will fix blocker bugs and security issues, and we will also consider and review small pull requests from the community.

Comment From: kklachkou

Guys, in scope of the maintenance mode are you going to fix missing body in GET or you don't consider this behavior as a bug? Can you consider applying @GJL PR with additional changes addressing RFC 2616, Section 4.4. ?