X-Git-Url: https://code.kerkeslager.com/?p=bigly;a=blobdiff_plain;f=src%2Fbigly%2Fviews.py;fp=src%2Fbigly%2Fviews.py;h=b037d6bea61176829c5f1fdded38ab31a16bc3da;hp=c74bc28a9aef7fad523c8ae0fd789561a011b91b;hb=e366fe36932d9bb674a50832cc141c19e017df8a;hpb=c9e1b1be5a243dac10e44221db1781f2c470dc1a diff --git a/src/bigly/views.py b/src/bigly/views.py index c74bc28..b037d6b 100644 --- a/src/bigly/views.py +++ b/src/bigly/views.py @@ -31,11 +31,16 @@ def _remove_utm(link): )) def _follow_redirects(link, remove_utm): + redirect_sequence = [] + while True: + redirect_sequence.append(link) + if remove_utm: link = _remove_utm(link) - response = requests.head(link) + # TODO Do this in an async call so it doesn't block the main thread + response = requests.head(link, timeout=10) # TODO Handle timeouts @@ -53,6 +58,10 @@ def _follow_redirects(link, remove_utm): return { 'link': link, 'status': response.status_code, + + # TODO Handle different capitalizations of "Content-Type" + 'content_type': response.headers.get('Content-Type'), + 'redirect_sequence': redirect_sequence, } class IndexView(TemplateView):