Skip to content

The response has a duplicate "Content-Length" header when get by range header #26330

@lmtoo

Description

@lmtoo

When I use Undertow as server , and make a range request, the response will have two "Content-Length" header.

request

GET /inspection/api/v1/binary/1568 HTTP/1.1
Host: inspection.lubansoft.net:58888
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Accept: /
Accept-Encoding: identity
Accept-Language: zh-CN,zh;q=0.9
Range: bytes=0-65535

response

HTTP/1.1 206 Partial Content
Expires: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
X-XSS-Protection: 1; mode=block
Pragma: no-cache
Content-Disposition: form-data; name="attachment"; filename*=UTF-8''%E8%AF%84%E5%AE%9A%E8%A1%A810.3.2%20%E6%98%8E%E6%B4%9E%E6%B5%87%E7%AD%91%E5%88%86%E9%A1%B9%E5%B7%A5%E7%A8%8B%E8%B4%A8%E9%87%8F%E6%A3%80%E9%AA%8C%E8%AF%84%E5%AE%9A%E8%A1%A8%28SG%29.pdf
Accept-Ranges: bytes
Date: Mon, 21 Dec 2020 13:02:45 GMT
Connection: keep-alive
Content-Language: zh-CN
X-Frame-Options: SAMEORIGIN
ETag: "10"
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers
Last-Modified: Mon, 21 Dec 2020 06:02:31 GMT
Content-Range: bytes 196608-212611/212612
X-Content-Type-Options: nosniff
Content-Length: 212612
Content-Length: 16004
Content-Type: application/pdf

in response header, Content-Length has two values , and chrome will have net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH error

org.springframework.web.servlet.resource.ResourceHttpRequestHandler actually writes the content-length twice. Once, with the entire content-length and then later on, if a partial-content response, with the range length.

Tomcat handles this just fine accepting the last content-length set as the authoritative content-length and writes it back to the client.

Undertow seems to assume all headers are multi-value and writes both content-length headers back to the client.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions