Skip to content

Transfer-Encoding & Content-Length headers are being sent in response headers. #1153

@kaladhar-mummadi

Description

@kaladhar-mummadi

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

  • Controller code
@GetMapping("/message")
public ResponseEntity<String> getMessage() {
    return  ResponseEntity.ok("foo");
}
  • Result of GET API
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
  • Result of HEAD API
 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


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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions