httphttp2http-1.1http-status-code-304http-status-code-204

TypeError: Network request failed for 204 (No Content) and 304 (Not Modified) call over HTTP2 (ERR_HTTP2_PROTOCOL_ERROR in Chrome)


We have switched from HTTP1.1 to HTTP2 protocol and have noticed that some requests fail. When a server responds with 204 or 304 we get the following error:

TypeError: Network request failed

Chrome additionally shows it with the following error on network tab: ERR_HTTP2_PROTOCOL_ERROR


Solution

  • After some research we have found what the issue was. HTTP2 protocol is stricter in it's syntax that HTTP1.1 is. E.g. it does not allow body for 204 or 304 responses. It is logical that these responses should not contain body, but HTTP1.1 did not require to fail these "strange" responses while HTTP2 requires that a client does not accept such a response.

    We have additionally found out that even though we did not have body or content-length header, we did have a content-type header which the browser does not accept either while the logic for HTTP1.1 was just ignoring this header.

    I did not find much information about this on the Internet at all. The closest I got was the HTTP2 RFC, and even it was a bit vague on details. It does not state directly that a 304 response that has a content-type header should be rejected, but I assume that's how browsers have implemented it in reality.

    TLDR:

    204 and 304 responses cannot contain body, content-length or content-type header. Such responses will be treated as a network error by the browser (and probably other clients as well).

    P.S. It is likely that there are similar restrictions for other response codes

    P.P.S. Kudos to Morten Cools who has done original research on the topic