Skip to content

Commit

Permalink
webcompat#451 rewrite_links with parsing and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
karlcow committed Feb 4, 2015
1 parent a8bb96f commit 932065f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions webcompat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ def rewrite_links(link_header):
</api/issues?per_page=50&page=2>; rel="next",
</api/issues?per_page=50&page=4>; rel="last" etc.
'''
links = link_header.split(',')
new_links = []
for link in links:
api_path, endpoint_path = link.rsplit('/', 1)
if api_path.strip().startswith('<https://api.github.com/repositories'):
new_links.append(endpoint_path.replace('issues?', '</api/issues?'))
if api_path.strip().startswith('<https://api.github.com/search'):
new_links.append(endpoint_path.replace('issues?', '</api/issues/search?'))
return ', '.join(new_links)
header_link_data = parse_link_header(link_header)
for data in header_link_data:
uri = data['link']
api_path, endpoint_path = uri.rsplit('/', 1)
if api_path.strip().startswith('https://api.github.com/repositories'):
data['link'] = endpoint_path.replace('issues?', '/api/issues?')
if api_path.strip().startswith('https://api.github.com/search'):
data['link'] = endpoint_path.replace('issues?', '/api/issues/search?')
return format_link_header(header_link_data)


def sanitize_link(link_header):
Expand Down

0 comments on commit 932065f

Please sign in to comment.