<td>{{ status }}</td>
{% endif %}
</tr>
+ <tr>
+ <td>Content Type:</td>
+ <td>{{ content_type }}</td>
+ </tr>
<tr>
<td>Link:</td>
<td><a href='{{ link }}'>{{ link }}</a></td>
</tr>
+ <tr>
+ <td>Redirects:</td>
+ <td>
+ <ol>
+ {% for r in redirect_sequence %}
+ <li>
+ {% comment "Add something that communicates when utm parameters were removed." %}
+ {% endcomment %}
+ <a href='{{ r }}'>
+ {{ r }}
+ </a>
+ </li>
+ {% endfor %}
+ </ol>
+ </td>
+ </tr>
</table>
{% endblock %}
))
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
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):