correct the http redirect behaviour (closes #7)

netiawifi
Laura Liberda 2020-09-16 11:03:44 +00:00
parent 187dc26d02
commit e1968d1082
1 changed files with 9 additions and 4 deletions

View File

@ -14,7 +14,8 @@ class BaseFxcker:
def FXCKER_KEY(self):
return self.__class__.__name__[:-6]
def request(self, method, url, resource=None, **kwargs):
def request(self, method, url, resource=None,
follow_redirects=True, **kwargs):
kwargs["cookies"] = self.cookie_jar
if not kwargs.get("headers"):
kwargs["headers"] = {}
@ -26,7 +27,11 @@ class BaseFxcker:
resource if resource is not None
else (str(method) + " " + str(url)))
req = requests.request(method, url, **kwargs)
if req.headers.get("Location"):
return self.request(method, req.headers.get("Location"),
resource=resource, **kwargs)
if follow_redirects is True and req.headers.get("Location"):
kwargs["data"] = None
kwargs["headers"]["Referer"] = url
return self.request("GET", req.headers.get("Location"),
resource=resource,
follow_redirects=follow_redirects,
**kwargs)
return req