MCPcopy
hub / github.com/encode/httpx / _parse_header_links

Function _parse_header_links

httpx/_models.py:93–127  ·  view source on GitHub ↗

Returns a list of parsed link headers, for more info see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link The generic syntax of those is: Link: < uri-reference >; param1=value1; param2="value2" So for instance: Link; '<http:/.../front.jpeg>; type="image/jpeg",

(value: str)

Source from the content-addressed store, hash-verified

91
92
93def _parse_header_links(value: str) -> list[dict[str, str]]:
94 """
95 Returns a list of parsed link headers, for more info see:
96 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
97 The generic syntax of those is:
98 Link: < uri-reference >; param1=value1; param2="value2"
99 So for instance:
100 Link; '<http:/.../front.jpeg>; type="image/jpeg",<http://.../back.jpeg>;'
101 would return
102 [
103 {"url": "http:/.../front.jpeg", "type": "image/jpeg"},
104 {"url": "http://.../back.jpeg"},
105 ]
106 :param value: HTTP Link entity-header field
107 :return: list of parsed link headers
108 """
109 links: list[dict[str, str]] = []
110 replace_chars = " '\""
111 value = value.strip(replace_chars)
112 if not value:
113 return links
114 for val in re.split(", *<", value):
115 try:
116 url, params = val.split(";", 1)
117 except ValueError:
118 url, params = val, ""
119 link = {"url": url.strip("<> '\"")}
120 for param in params.split(";"):
121 try:
122 key, value = param.split("=")
123 except ValueError:
124 break
125 link[key.strip(replace_chars)] = value.strip(replace_chars)
126 links.append(link)
127 return links
128
129
130def _obfuscate_sensitive_headers(

Callers 1

linksMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected