Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Enhancements

Fixes

- Return empty results for HTTP reads ending at offset zero without sending an invalid range request.

- Correct the configuration directory variable and explain JSON parsing of environment overrides (#2324)

- Update contributor linting and formatting instructions for Ruff and pre-commit (#2325)
Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ async def _cat_file(self, url, start=None, end=None, **kwargs):
logger.debug(url)

if start is not None or end is not None:
if start == end:
if start == end or (start is None and end == 0):
return b""
headers = kw.pop("headers", {}).copy()

Expand Down
2 changes: 1 addition & 1 deletion fsspec/implementations/http_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def cat_file(self, url, start=None, end=None, **kwargs):
logger.debug(url)

if start is not None or end is not None:
if start == end:
if start == end or (start is None and end == 0):
return b""
headers = kw.pop("headers", {}).copy()

Expand Down
8 changes: 8 additions & 0 deletions fsspec/implementations/tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,14 @@ def test_cat_file_range(server):
assert h.cat(urla, end=-10) == data[:-10]


@pytest.mark.parametrize("start,end", [(None, 0), (0, 0), (1, 1), (-1, -1)])
def test_cat_file_empty_range_does_not_make_request(server, reset_faults, start, end):
h = fsspec.filesystem("http", skip_instance_cache=True)

assert h.cat_file(server.realfile, start=start, end=end) == b""
assert HTTPTestHandler.get_counts.get("/index/realfile", 0) == 0


def test_cat_file_range_numpy(server):
np = pytest.importorskip("numpy")
h = fsspec.filesystem("http", headers={"give_length": "true", "head_ok": "true"})
Expand Down
20 changes: 19 additions & 1 deletion fsspec/implementations/tests/test_http_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
import pytest

import fsspec.utils
from fsspec.tests.conftest import data, requests, reset_files, server, win # noqa: F401
from fsspec.tests.conftest import ( # noqa: F401
HTTPTestHandler,
data,
requests,
reset_faults,
reset_files,
server,
win,
)


@pytest.fixture()
Expand Down Expand Up @@ -417,6 +425,16 @@ def test_cat_file_range(server, sync):
assert h.cat(urla, end=-10) == data[:-10]


@pytest.mark.parametrize("start,end", [(None, 0), (0, 0), (1, 1), (-1, -1)])
def test_cat_file_empty_range_does_not_make_request(
server, sync, reset_faults, start, end
):
h = fsspec.filesystem("http", skip_instance_cache=True)

assert h.cat_file(server.realfile, start=start, end=end) == b""
assert HTTPTestHandler.get_counts.get("/index/realfile", 0) == 0


def test_mcat_cache(server, sync):
urla = server.address + "/index/realfile"
urlb = server.address + "/index/otherfile"
Expand Down
Loading