4 ms·
> The only downside is that it’s conceptually more complicated, and requires some understanding of underlying components (zip files, http responses, streams).
by masklinn 15y ago
> The only downside is that it’s conceptually more complicated, and requires some understanding of underlying components (zip files, http responses, streams).
There's at least one more downside: the user loses all indication of progress as the Content-Length is unknown when the headers are sent
- nevinera 15y agoYou can do a solid best-guess estimate, especially if those images are already in compressed formats.
- RogerE 15y agoYou can guess, but browsers are quite picky about this header --- guess any amount too low and the download is truncated. Guess too high, and the browser will wait for an amount of time just to be sure the server isn't going to send more data.
- stephank 15y agoI wonder if this would actually be useful to support in HTTP? (An `Estimated-Content-Length` header or similar, only valid with `Connection: close`.)
- FooBarWidget 15y agoIt would be better to include progress estimation information as a chunked encoding extension. This allows much better progress reporting.
- j_s 15y agoNote that it is possible to "always guess long" and pad out with null bytes... this usually works (many file format parsers aren't too picky). However, this is more of a practical work-around than a recommended solution!
- dmmalam 15y agoNice catch, We are working on it! dumply knows the exact size of each image as it is saved in the DB on upload, and all the zip byte headers are fixed, so the zip file size should be deterministic and calculable even before the first byte is sent. Remember we don't compress the already compressed images. If you didn't know the file sizes, for example you had raw unknown input streams, or had compressible data, you can still guesstimate the content-length so the user got some progress bar, even if it wasn't 100% accurate.
- pooriaazimi 15y agoWouldn't guestimation cause problems (on user's end)? I don't know, but how browsers/curl/wget/crawlers/... react if you tell them Content-Length is 1000 bytes, and then send them 900 bytes and close the connection? or overshot and send 1100? I have a feeling that they wouldn't like it, or at least it varies between fetcher library implementations.
- masklinn 15y agoRogerE states above that under-estimating does lead to resource truncation, and over-estimating leads to the browser waiting until timeout/connection break in case there's more data to be fetched. But yeah, it's probably indeterminate behavior.
- tiles 15y agoThe IEInternals blog covers each browser's behavior for underrunning the purported Content-Length of a download: http://blogs.msdn.com/b/ieinternals/archive/2011/03/09/browsers-accommodate-incorrect-http-content-length-and-sites-depressingly-depend-on-it.aspx http://blogs.msdn.com/b/ieinternals/archive/2011/03/09/brows... Looks like using browser sniffing, you can deliver an exaggerated Content-Length to everyone but Opera and browsers will deal with it gracefully. Pretty neat. (Obviously not desirable for violating the HTTP spec, but the UX gains might be worth it.)
- pornel 15y agoYou're not always dealing with the client that is specified in the UA string. Clients can use proxies, including transparent proxies. For example major mobile operators pipe HTTP connections through a proxy that recompresses images. In that case you see e.g. Safari's or Opera's UA string, but you're actually dealing with proxy's HTTP behavior.