From d2e3afceb738af20aeb8e41f9aad12150cf1e8a7 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Sun, 4 Dec 2011 13:39:42 +0100 Subject: Better download connection handling: Detect server error earlier, fallback to single connection if possible --- module/network/HTTPRequest.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'module/network/HTTPRequest.py') diff --git a/module/network/HTTPRequest.py b/module/network/HTTPRequest.py index bd8cdd72e..e58fd114e 100644 --- a/module/network/HTTPRequest.py +++ b/module/network/HTTPRequest.py @@ -30,6 +30,7 @@ from module.plugins.Plugin import Abort def myquote(url): return quote(url, safe="%/:=&?~#+!$,;'@()*[]") +bad_headers = range(400, 404) + range(405, 418) + range(500, 506) class BadHeader(Exception): def __init__(self, code, content=""): @@ -211,11 +212,15 @@ class HTTPRequest(): def verifyHeader(self): """ raise an exceptions on bad headers """ code = int(self.c.getinfo(pycurl.RESPONSE_CODE)) - if code in range(400, 404) or code in range(405, 418) or code in range(500, 506): + if code in bad_headers: #404 will NOT raise an exception raise BadHeader(code, self.getResponse()) return code + def checkHeader(self): + """ check if header indicates failure""" + return int(self.c.getinfo(pycurl.RESPONSE_CODE)) not in bad_headers + def getResponse(self): """ retrieve response from string io """ if self.rep is None: return "" -- cgit v1.2.3