When a string is sent in the response body, GET request has only Content-Length whereas HEAD request has both Transfer-Encoding and Content-Length.
Expected Behavior
Should remove Transfer-Encoding header for HEAD request too, as it is being done for GET request.
Actual Behavior
Both Transfer-Encoding and Content-Length are being sent.
Worth noting
https://tools.ietf.org/html/rfc7230#section-3.3.2
A sender MUST NOT send a Content-Length header field in any message
that contains a Transfer-Encoding header field.
Steps to Reproduce
@GetMapping("/message")
public ResponseEntity<String> getMessage() {
return ResponseEntity.ok("foo");
}
curl -v -X GET http://localhost:8080/message
Note: Unnecessary use of -X or --request, GET is already inferred.
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /message HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 3
<
* Connection #0 to host localhost left intact
foo* Closing connection 0
curl -v -X HEAD http://localhost:8080/message
Warning: Setting custom HTTP method to HEAD with -X/--request may not work the
Warning: way you want. Consider using -I/--head instead.
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> HEAD /message HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< transfer-encoding: chunked
< Content-Type: text/plain;charset=UTF-8
< Content-Length: 3
<
Possible Solution
|
if (!HttpMethod.HEAD.equals(method())) { |
has a condition to remove transfer-encoding only if it is not a HEAD request.
Your Environment
Environment:
spring-boot: 2.2.6.RELEASE
Using spring-boot-starter-webflux with Netty.
When a string is sent in the response body,
GETrequest has onlyContent-LengthwhereasHEADrequest has bothTransfer-EncodingandContent-Length.Expected Behavior
Should remove
Transfer-Encodingheader for HEAD request too, as it is being done forGETrequest.Actual Behavior
Both
Transfer-EncodingandContent-Lengthare being sent.Worth noting
https://tools.ietf.org/html/rfc7230#section-3.3.2
Steps to Reproduce
Possible Solution
reactor-netty/src/main/java/reactor/netty/http/server/HttpServerOperations.java
Line 161 in abd6ac4
has a condition to remove transfer-encoding only if it is not a HEAD request.
Your Environment
Environment:
spring-boot: 2.2.6.RELEASE
Using spring-boot-starter-webflux with Netty.