Skip to content

Commit

Permalink
Merge pull request #801 from rhyselsmore/develop
Browse files Browse the repository at this point in the history
Added in a link handler as per issue #711
  • Loading branch information
Kenneth Reitz committed Aug 20, 2012
2 parents 49a7947 + f3159ed commit a320336
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,3 +518,36 @@ def default_user_agent():
'%s/%s' % (_implementation, _implementation_version),
'%s/%s' % (platform.system(), platform.release()),
])

def parse_header_links(value):
"""Return a dict of parsed link headers proxies.
i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"
"""

links = []

replace_chars = " '\""

for val in value.split(","):
try:
url, params = val.split(";", 1)
except ValueError:
url, params = val, ''

link = {}

link["url"] = url.strip("<> '\"")

for param in params.split(";"):
try:
key,value = param.split("=")
except ValueError:
break

link[key.strip(replace_chars)] = value.strip(replace_chars)

links.append(link)

return links

0 comments on commit a320336

Please sign in to comment.