Skip to content

Commit

Permalink
fix requests auto decode file (#8701)
Browse files Browse the repository at this point in the history
Co-authored-by: Randy Döring <[email protected]>
  • Loading branch information
codeskyblue and radoering authored Dec 20, 2023
1 parent 5ddc81c commit 3d7b75c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/poetry/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ def __init__(
self._dest = dest

get = requests.get if not session else session.get
headers = {"Accept-Encoding": "Identity"}

self._response = get(url, stream=True, timeout=REQUESTS_TIMEOUT)
self._response = get(
url, stream=True, headers=headers, timeout=REQUESTS_TIMEOUT
)
self._response.raise_for_status()

@cached_property
Expand Down
20 changes: 20 additions & 0 deletions tests/utils/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

from poetry.core.utils.helpers import parse_requires

from poetry.utils.helpers import download_file
from poetry.utils.helpers import get_file_hash


if TYPE_CHECKING:
from pathlib import Path

from httpretty import httpretty

from tests.types import FixtureDirGetter


Expand Down Expand Up @@ -119,3 +124,18 @@ def test_guaranteed_hash(
) -> None:
file_path = fixture_dir("distributions") / "demo-0.1.0.tar.gz"
assert get_file_hash(file_path, hash_name) == expected


def test_download_file(
http: type[httpretty], fixture_dir: FixtureDirGetter, tmp_path: Path
) -> None:
file_path = fixture_dir("distributions") / "demo-0.1.0.tar.gz"
url = "https://foo.com/demo-0.1.0.tar.gz"
http.register_uri(http.GET, url, body=file_path.read_bytes())
dest = tmp_path / "demo-0.1.0.tar.gz"

download_file(url, dest)

expect_sha_256 = "9fa123ad707a5c6c944743bf3e11a0e80d86cb518d3cf25320866ca3ef43e2ad"
assert get_file_hash(dest) == expect_sha_256
assert http.last_request().headers["Accept-Encoding"] == "Identity"

0 comments on commit 3d7b75c

Please sign in to comment.