Repository navigation
Response.links does not split rel="next prev" into two relations and only finds a lowercase rel parameter #3888
Unanswered
Finjineersdev
asked this question in
Potential Issue
Replies: 1 comment
|
For context, this shape comes from requests: def rel_links(response: httpx.Response) -> dict[str, dict[str, str]]:
out: dict[str, dict[str, str]] = {}
for link in response.links.values():
params = {k.strip().lower(): v for k, v in link.items()}
for rel in params.get("rel", "").lower().split():
out.setdefault(rel, params)
return outOn httpx 0.28.1 it gives |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Response.linkskeys each link by itsrelvalue as one string, and it only recognises a parameter written exactly asrel. RFC 8288 handles both cases differently:rel. Section 3.3: "The rel parameter can, however, contain multiple link relation types. When this occurs, it establishes multiple links that share the same context, target, and target attributes." The ABNF isrelation-type *( 1*SP relation-type ). Withrel="next prev", httpx returns one entry under the key"next prev", solinks.get("next")andlinks.get("prev")are bothNone.REL="next"orRel=next, httpx stores the parameter under"REL"/"Rel", finds norel, and keys the link by its URL.Output with httpx 0.29.0 (same on
masterat e347fb5):Expected:
links.get("next")returns the link in all three cases, and for the first onelinks.get("prev")returns it too.Where:
_parse_header_links()inhttpx/_models.pykeeps parameter names as written (link[key.strip(replace_chars)] = ...), andResponse.linksbuilds the dict with(link.get("rel") or link.get("url")): link. Lowercasing the parameter name in the parser, and adding one dict entry per space-separated (lowercased) relation type inResponse.links, would cover both cases.This is the same parser as in #3814 (a valueless parameter or a quoted value containing
=dropsrel), but a different input: these headers have no such parameter, and thesplit("=", 1)/continuechange proposed there does not change the output above.Versions: httpx 0.29.0 (PyPI) and
mastere347fb5, Python 3.13.15, macOS.All reactions