Skip to content

Commit

Permalink
Verify Content-Encoding when querying Content-Length
Browse files Browse the repository at this point in the history
  • Loading branch information
nkemnitz committed Jul 29, 2023
1 parent 166f462 commit b204fa7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fsspec/implementations/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ async def _ls_real(self, url, detail=True, **kwargs):
return list(sorted(out))

async def _ls(self, url, detail=True, **kwargs):

if self.use_listings_cache and url in self.dircache:
out = self.dircache[url]
else:
Expand Down Expand Up @@ -841,7 +840,10 @@ async def _file_info(url, session, size_policy="head", **kwargs):
# or 'Accept-Ranges': 'none' (not 'bytes')
# to mean streaming only, no random access => return None
if "Content-Length" in r.headers:
info["size"] = int(r.headers["Content-Length"])
# Some servers may choose to ignore Accept-Encoding and return
# compressed content, in which case the returned size is unreliable.
if r.headers.get("Content-Encoding", "identity") == "identity":
info["size"] = int(r.headers["Content-Length"])
elif "Content-Range" in r.headers:
info["size"] = int(r.headers["Content-Range"].split("/")[1])

Expand Down

0 comments on commit b204fa7

Please sign in to comment.