Skip to content

Commit 4146df1

Browse files
karlcowMike Taylor
authored and
Mike Taylor
committed
#451 rewrite_links with parsing and formatting
1 parent d703074 commit 4146df1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

webcompat/helpers.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ def rewrite_links(link_header):
194194
</api/issues?per_page=50&page=2>; rel="next",
195195
</api/issues?per_page=50&page=4>; rel="last" etc.
196196
'''
197-
links = link_header.split(',')
198-
new_links = []
199-
for link in links:
200-
api_path, endpoint_path = link.rsplit('/', 1)
201-
if api_path.strip().startswith('<https://api.github.com/repositories'):
202-
new_links.append(endpoint_path.replace('issues?', '</api/issues?'))
203-
if api_path.strip().startswith('<https://api.github.com/search'):
204-
new_links.append(endpoint_path.replace('issues?', '</api/issues/search?'))
205-
return ', '.join(new_links)
197+
header_link_data = parse_link_header(link_header)
198+
for data in header_link_data:
199+
uri = data['link']
200+
api_path, endpoint_path = uri.rsplit('/', 1)
201+
if api_path.strip().startswith('https://api.github.com/repositories'):
202+
data['link'] = endpoint_path.replace('issues?', '/api/issues?')
203+
if api_path.strip().startswith('https://api.github.com/search'):
204+
data['link'] = endpoint_path.replace('issues?', '/api/issues/search?')
205+
return format_link_header(header_link_data)
206206

207207

208208
def sanitize_link(link_header):

0 commit comments

Comments
 (0)