diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-11-04 20:40:09 +0100 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-11-04 20:40:09 +0100 |
commit | 138c28777f8a09fd88c4002a00c87e8bd0c7be74 (patch) | |
tree | 5d8aea3a8dbc65276dc04722e62375ce6dc61b6a /module/network | |
parent | BasePlugin: attempt to fix #266 (diff) | |
download | pyload-138c28777f8a09fd88c4002a00c87e8bd0c7be74.tar.xz |
closed #418
Diffstat (limited to 'module/network')
-rw-r--r-- | module/network/Browser.py | 22 | ||||
-rw-r--r-- | module/network/HTTPChunk.py | 2 | ||||
-rw-r--r-- | module/network/HTTPRequest.py | 10 | ||||
-rw-r--r-- | module/network/RequestFactory.py | 6 |
4 files changed, 32 insertions, 8 deletions
diff --git a/module/network/Browser.py b/module/network/Browser.py index 822e2ed6d..23cf7666b 100644 --- a/module/network/Browser.py +++ b/module/network/Browser.py @@ -8,7 +8,6 @@ from HTTPDownload import HTTPDownload class Browser(object): - __slots__ = ("log", "options", "bucket", "cj", "_size", "http", "dl") def __init__(self, bucket=None, options={}): @@ -20,9 +19,14 @@ class Browser(object): self.cj = None # needs to be setted later self._size = 0 - self.http = HTTPRequest(self.cj, options) + self.renewHTTPRequest() self.dl = None + + def renewHTTPRequest(self): + if hasattr(self, "http"): self.http.close() + self.http = HTTPRequest(self.cj, self.options) + def setLastURL(self, val): self.http.lastURL = val @@ -80,7 +84,7 @@ class Browser(object): """ this can also download ftp """ self._size = 0 self.dl = HTTPDownload(url, filename, get, post, self.lastEffectiveURL if ref else None, - self.cj if cookies else None, self.bucket, self.options, progressNotify, disposition) + self.cj if cookies else None, self.bucket, self.options, progressNotify, disposition) name = self.dl.download(chunks, resume) self._size = self.dl.size @@ -96,6 +100,18 @@ class Browser(object): """ add a header to the request """ self.http.putHeader(name, value) + def addAuth(self, pwd): + """Adds user and pw for http auth + + :param pwd: string, user:password + """ + self.options["auth"] = pwd + self.renewHTTPRequest() #we need a new request + + def removeAuth(self): + if "auth" in self.options: del self.options["auth"] + self.renewHTTPRequest() + def clearHeaders(self): self.http.clearHeaders() diff --git a/module/network/HTTPChunk.py b/module/network/HTTPChunk.py index 680b982d3..69eedb19c 100644 --- a/module/network/HTTPChunk.py +++ b/module/network/HTTPChunk.py @@ -137,7 +137,7 @@ class HTTPChunk(HTTPRequest): self.fp = None #file handle self.initHandle() - self.setInterface(self.p.options["interface"], self.p.options["proxies"], self.p.options["ipv6"]) + self.setInterface(self.p.options) self.BOMChecked = False # check and remove byte order mark diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index ffe5d1873..6672a58e6 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -55,7 +55,7 @@ class HTTPRequest(): self.headers = [] #temporary request header self.initHandle() - self.setInterface(options["interface"], options["proxies"], options["ipv6"]) + self.setInterface(options) self.c.setopt(pycurl.WRITEFUNCTION, self.write) self.c.setopt(pycurl.HEADERFUNCTION, self.writeHeader) @@ -89,7 +89,10 @@ class HTTPRequest(): "Keep-Alive: 300", "Expect:"]) - def setInterface(self, interface, proxy, ipv6=False): + def setInterface(self, options): + + interface, proxy, ipv6 = options["interface"], options["proxies"], options["ipv6"] + if interface and interface.lower() != "none": self.c.setopt(pycurl.INTERFACE, str(interface)) @@ -112,6 +115,9 @@ class HTTPRequest(): else: self.c.setopt(pycurl.IPRESOLVE, pycurl.IPRESOLVE_V4) + if "auth" in options: + self.c.setopt(pycurl.USERPWD, str(options["auth"])) + def addCookies(self): """ put cookies from curl handle to cj """ if self.cj: diff --git a/module/network/RequestFactory.py b/module/network/RequestFactory.py index 774249a70..5b1528281 100644 --- a/module/network/RequestFactory.py +++ b/module/network/RequestFactory.py @@ -54,9 +54,11 @@ class RequestFactory(): self.lock.release() return req - def getHTTPRequest(self): + def getHTTPRequest(self, **kwargs): """ returns a http request, dont forget to close it ! """ - return HTTPRequest(CookieJar(None), self.getOptions()) + options = self.getOptions() + options.update(kwargs) # submit kwargs as additional options + return HTTPRequest(CookieJar(None), options) def getURL(self, *args, **kwargs): """ see HTTPRequest for argument list """ |