]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
simple_httpclient: after 303 redirect, turn all methods into GET 2918/head
authorPierce Lopez <pierce.lopez@gmail.com>
Tue, 22 Sep 2020 18:00:21 +0000 (14:00 -0400)
committerPierce Lopez <pierce.lopez@gmail.com>
Fri, 25 Sep 2020 18:11:13 +0000 (14:11 -0400)
not just POST (but still not HEAD)

following the behavior of libcurl > 7.70

tornado/simple_httpclient.py

index 67bbe2a02ec31fc4f1f0622b2354953da4fd483f..c977aeefdee6ec58561b7b099f190043fa98b37a 100644 (file)
@@ -634,11 +634,12 @@ class _HTTPConnection(httputil.HTTPMessageDelegate):
             # redirect, the request method should be preserved.
             # However, browsers implemented this by changing the
             # method to GET, and the behavior stuck. 303 redirects
-            # always specified this POST-to-GET behavior (arguably 303
-            # redirects should change *all* requests to GET, but
-            # libcurl only does this for POST so we follow their
-            # example).
-            if self.code in (301, 302, 303) and self.request.method == "POST":
+            # always specified this POST-to-GET behavior, arguably
+            # for *all* methods, but libcurl < 7.70 only does this
+            # for POST, while libcurl >= 7.70 does it for other methods.
+            if (self.code == 303 and self.request.method != "HEAD") or (
+                self.code in (301, 302) and self.request.method == "POST"
+            ):
                 new_request.method = "GET"
                 new_request.body = None
                 for h in [