fetch icon indicating copy to clipboard operation
fetch copied to clipboard

Allow accept-encoding header with value "identity"

Open mitar opened this issue 4 years ago • 8 comments

Currently, if I want to display a progress bar of how much data has been downloaded, I have to check content-length header to get the amount of all data so that I can correctly display the progress bar as I stream chunks of data into a JavaScript array. But the issue is that if server is using content-encoding set to gzip, then content-length tells how large is compressed data, not uncompressed. But what I am getting in chunks in uncompressed. So there should be a way for me to get how large is uncompressed data.

One way to achieve this is to do HEAD request with accept-encoding header set to identity. This would force the server to tell me the real size of the payload. But the issue is that currently accept-encoding header is not allowed to be set for fetch requests. I would ask that an exception is made for identity.

mitar avatar Dec 28 '19 20:12 mitar

As this would add quite a bit of complexity and also has novel same-origin policy implications I'm afraid this needs a stronger use case or demonstration of being a very widespread problem.

annevk avatar Jan 02 '20 15:01 annevk

I guess what you really would want is in #607 (aka FetchObserver)

jimmywarting avatar Jun 25 '20 15:06 jimmywarting

also has novel same-origin policy implications

Why? There is no change here, if you can access response and content-length before, you could also now.

I guess what you really would want is in #607 (aka FetchObserver)

Interesting. That could also work, but it looks to me like even more work to get it in.

mitar avatar Jun 25 '20 16:06 mitar

The same-origin policy also applies tor requests.

annevk avatar Jun 25 '20 16:06 annevk

Yes, so? Can you elaborate a bit please what are "novel same-origin policy implications" you mean?

mitar avatar Jun 25 '20 16:06 mitar

I looked at this again and you can already do this. If you set a Range header the fetch algorithm will add this automatically as far as I can tell.

annevk avatar Jun 25 '20 17:06 annevk

Hm, is this somewhere in the spec?

mitar avatar Jun 25 '20 17:06 mitar

hmm, wanted to set the value to "identity" so i could get the final totalDownload for use in backgroundFetch.totalDownload, unfortunately it's also CORS, so not much control over that 😞

jimmywarting avatar Mar 06 '22 21:03 jimmywarting