Reputation: 372
I'm attempting to send a file while it's being created (which takes many seconds) to a user. I can estimate the size it will be to the nearest kilobyte.
If I create the header and add an extra kilobyte to my estimate (to compensate for minor error) the browser thinks the download failed.
I know I can leave the length off completely but don't think the user experience is as nice.
Upvotes: 0
Views: 474
Reputation: 16688
The RFC 7230 (https://www.rfc-editor.org/rfc/rfc7230#section-3.3.2) specifies:
If the sender closes the connection or the recipient times out before the indicated number of octets are received, the recipient MUST consider the message to be incomplete and close the connection.
This means that the content-length header cannot be bigger than the actual content.
There's nothing about making the content-length header smaller than the download, but I think we would both agree that that would not be a good idea.
So the content-length header, surprise - surprise, should reflect the real size of the download.
There's almost always a way to get the real size of the download, are you sure that's impossible in your case?
You cannot add padding to the download to make its size exactly the size mentioned in the header?
Since you don't tell us anything about the download itself I cannot really be more helpful.
Upvotes: 1