From a590adbf123452cc51dc187d72d8dc79c04a7be2 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 9 Nov 2014 03:13:25 +0100 Subject: [HTTPRequest] Improve load method --- module/network/HTTPRequest.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'module/network/HTTPRequest.py') diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index d6fcae7d6..df952a690 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -181,7 +181,7 @@ class HTTPRequest(): self.getCookies() - def load(self, url, get={}, post={}, referer=True, cookies=True, just_header=False, multipart=False, decode=False): + def load(self, url, get={}, post={}, referer=True, cookies=True, just_header=False, multipart=False, decode=False, follow_location=True, save_cookies=True): """ load and returns a given page """ self.setRequestContext(url, get, post, referer, cookies, multipart) @@ -190,24 +190,27 @@ class HTTPRequest(): self.c.setopt(pycurl.HTTPHEADER, self.headers) - if just_header: + if not follow_location: self.c.setopt(pycurl.FOLLOWLOCATION, 0) + + if just_header: self.c.setopt(pycurl.NOBODY, 1) - self.c.perform() - rep = self.header + self.c.perform() + rep = self.header if just_header else self.getResponse() + + if not follow_location: self.c.setopt(pycurl.FOLLOWLOCATION, 1) - self.c.setopt(pycurl.NOBODY, 0) - else: - self.c.perform() - rep = self.getResponse() + if just_header: + self.c.setopt(pycurl.NOBODY, 0) self.c.setopt(pycurl.POSTFIELDS, "") self.lastEffectiveURL = self.c.getinfo(pycurl.EFFECTIVE_URL) self.code = self.verifyHeader() - self.addCookies() + if save_cookies: + self.addCookies() if decode: rep = self.decodeResponse(rep) -- cgit v1.2.3