Skip to content

"HTTP server returned compressed partial data. That should not happen. CheerpJ cannot run." #221

Description

@eliasen

When a CheerpJ application tries to access a text file from the server, it returns the error in the console "HTTP server returned compressed partial data. That should not happen. CheerpJ cannot run."

This error message and "defensive" message are found in cheerpOS.js with the following code:

else if(resp.headers.get("Content-Encoding") !== null)
{
	// Be defensive against broken servers that mix up compression and partial content,
	// that is forbidden since it's ambiguous if the partial content is over the compressed
	// or uncompressed data
	ddlOnError(downloader, "HTTP server returned compressed partial data. That should not happen. CheerpJ cannot run.", /*fatal*/true);
}

The comment, error message and "defensive" check are incorrect in several ways:

  1. You requested partial content by sending the HTTP header Range: bytes=0-131071. If you didn't want partial content, or don't know how to handle it correctly, simply don't send this header!
  2. You requested compressed content by sending the HTTP header Accept-Encoding: gzip, deflate, br, zstd, identity . If you didn't want compressed content, don't send this header! It is not acceptable for users to turn off compression on their webservers to work around this bug.
  3. Compression and partial content is in no way ambiguous nor forbidden by RFC 9110. Compression is done first. Then the bytes returned for a Range are respective to the compressed content. It is not ambiguous. The comment, defensive check, and error is written with an incorrect understanding of HTTP.
  4. The server actually told you that it sent the complete file. According to RFC 9110, you must check the returned HTTP headers Content-Range: bytes 0-20693/20694. This told you that the compressed response contains the entire file you requested (you requested 131072 bytes) and the error message/check is totally wrong in disregarding it. You should have understood that the file was returned in its entirety and continued processing it. Section 15.3.7 of RFC 9110 says "A client MUST inspect a 206 response's Content-Type and Content-Range field(s) to determine what parts are enclosed and whether additional requests are needed."
  5. "That should not happen" is incorrect. It should happen (because you explicitly requested it.)
  6. Servers that understand and follow HTTP correctly are not "broken."

The fix is easy: if you don't know how to handle byte ranges correctly, just request the whole file! It will be easier and faster and less abusive to servers than requesting multiple byte ranges in mutliple requests.

This bug makes CheerpJ unable to even download a text file from a server if the server (reasonably) has compression turned on. Even if the server correctly returned you the entire file!

Please see:
RFC 9110

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions