Add something that shows the redirect sequence
authorDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 14 Jan 2022 18:43:20 +0000 (13:43 -0500)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Fri, 14 Jan 2022 18:43:20 +0000 (13:43 -0500)
src/bigly/templates/bigly/link_info.html
src/bigly/views.py

index 4eb7d1f..7bce71d 100644 (file)
       <td>{{ status }}</td>
     {% endif %}
   </tr>
       <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>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 %}
 </table>
 {% endblock %}
index c74bc28..b037d6b 100644 (file)
@@ -31,11 +31,16 @@ def _remove_utm(link):
     ))
 
 def _follow_redirects(link, remove_utm):
     ))
 
 def _follow_redirects(link, remove_utm):
+    redirect_sequence = []
+
     while True:
     while True:
+        redirect_sequence.append(link)
+
         if remove_utm:
             link = _remove_utm(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
 
 
         # TODO Handle timeouts
 
@@ -53,6 +58,10 @@ def _follow_redirects(link, remove_utm):
             return {
                 'link': link,
                 'status': response.status_code,
             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):
             }
 
 class IndexView(TemplateView):