whatwg / fetch

Fetch Standard
https://fetch.spec.whatwg.org/
Other
2.09k stars 323 forks source link

Allow accept-encoding header with value "identity" #986

Open mitar opened 4 years ago

mitar commented 4 years ago

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.

annevk commented 4 years ago

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.

jimmywarting commented 4 years ago

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

mitar commented 4 years ago

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.

annevk commented 4 years ago

The same-origin policy also applies tor requests.

mitar commented 4 years ago

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

annevk commented 4 years ago

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.

mitar commented 4 years ago

Hm, is this somewhere in the spec?

jimmywarting commented 2 years ago

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 😞