The Content-Length header is set and sent correctly when using HTTP1.1 (over plain-text HTTP or over HTTPS) both for static files and when our own code sets it on the response. However, when making a request using HTTP2 (over TLS), that header is not sent neither for static files, nor from our code. I can't see a reason for this and would guess that this is a bug in Tomcat. Or am I missing something?
Sending the content-length header is optional in HTTP/2. See section 8.1.2.6 of RFC 7540: "A request or response that includes a payload body can include a content-length header field." The header is not required since HTTP/2 includes sufficient information in the frame headers for a user agent to determine when a resource has been sent in full. What providing the content-length header does do is give the user agent advance notice of how big the resource is. That may be useful information (e.g. large resources cached straight to disk, small ones in memory). I think it makes sense to send the content-length if it has been set or can be determined (essentially do what we do for HTTP1/1). Note that if the content-length header and the actual content-length disagree it will be treated as a protocol error for that stream.
Fixed in: - trunk for 9.0.15 onwards - 8.5.x for 8.5.38 onwards