Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test parse_header_links via public api #3061

Merged
merged 4 commits into from
Jan 16, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions httpx/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,13 @@ def links(self) -> typing.Dict[typing.Optional[str], typing.Dict[str, str]]:
Returns the parsed header links of the response, if any
"""
header = self.headers.get("link")
ldict = {}
if header:
links = parse_header_links(header)
for link in links:
key = link.get("rel") or link.get("url")
ldict[key] = link
return ldict
if header is None:
return {}

return {
(link.get("rel") or link.get("url")): link
for link in parse_header_links(header)
}

@property
def num_bytes_downloaded(self) -> int:
Expand Down
9 changes: 7 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
get_ca_bundle_from_env,
get_environment_proxies,
is_https_redirect,
parse_header_links,
same_origin,
)

Expand Down Expand Up @@ -80,7 +79,13 @@ def test_guess_by_bom(encoding, expected):
),
)
def test_parse_header_links(value, expected):
assert parse_header_links(value) == expected
all_links = httpx.Response(200, headers={"link": value}).links.values()
assert all(link in all_links for link in expected)


def test_parse_header_links_no_link():
all_links = httpx.Response(200).links
assert all_links == {}


def test_logging_request(server, caplog):
Expand Down