INT-4242: Don't send body for HEAD and TRACE, too

JIRA: https://jira.spring.io/browse/INT-4242
Fixes spring-projects/spring-integration#2085

According to the RFC7231 (https://tools.ietf.org/html/rfc7231), the `HEAD` is fully similar to `GET` and its body does not have sense.
The `TRACE` method can't have body at all.
The `OPTIONS` may have body, but that is already custom target server logic to parse it properly

* Modify `AbstractHttpRequestExecutingMessageHandler` do not include `payload` as a request body for `GET`, `HEAD` and `TRACE`

Also see https://github.com/spring-projects/spring-integration/wiki/Spring-Integration-4.3-to-5.0-Migration-Guide
This commit is contained in:
Artem Bilan
2017-03-08 13:23:19 -05:00
committed by Gary Russell
parent 6a883281f4
commit 9208fa52d6
2 changed files with 9 additions and 8 deletions

View File

@@ -72,6 +72,9 @@ import org.springframework.web.util.UriComponentsBuilder;
*/
public abstract class AbstractHttpRequestExecutingMessageHandler extends AbstractReplyProducingMessageHandler {
private static final List<HttpMethod> noBodyHttpMethods =
Arrays.asList(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.TRACE);
private final Map<String, Expression> uriVariableExpressions = new HashMap<>();
private volatile StandardEvaluationContext evaluationContext;
@@ -426,7 +429,7 @@ public abstract class AbstractHttpRequestExecutingMessageHandler extends Abstrac
}
private boolean shouldIncludeRequestBody(HttpMethod httpMethod) {
return !HttpMethod.GET.equals(httpMethod);
return !(CollectionUtils.containsInstance(noBodyHttpMethods, httpMethod));
}
private MediaType resolveContentType(String content, Charset charset) {