tools/web: allow empty Content-Type

This commit is contained in:
nemunaire 2014-12-16 00:46:07 +01:00
parent dd285b67d1
commit 0b06261d18

View File

@ -102,23 +102,24 @@ def getURLContent(url, timeout=15):
size = int(res.getheader("Content-Length", 200000)) size = int(res.getheader("Content-Length", 200000))
cntype = res.getheader("Content-Type") cntype = res.getheader("Content-Type")
if size > 200000 or (cntype[:4] != "text" and cntype[:4] != "appl"): if size > 200000 or (cntype is not None and cntype[:4] != "text" and cntype[:4] != "appl"):
return None return None
data = res.read(size) data = res.read(size)
# Decode content # Decode content
charset = "utf-8" charset = "utf-8"
lcharset = res.getheader("Content-Type").split(";") if cntype is not None:
if len(lcharset) > 1: lcharset = res.getheader("Content-Type").split(";")
for c in charset: if len(lcharset) > 1:
ch = c.split("=") for c in charset:
if ch[0].strip().lower() == "charset" and len(ch) > 1: ch = c.split("=")
cha = ch[1].split(".") if ch[0].strip().lower() == "charset" and len(ch) > 1:
if len(cha) > 1: cha = ch[1].split(".")
charset = cha[1] if len(cha) > 1:
else: charset = cha[1]
charset = cha[0] else:
charset = cha[0]
except http.client.BadStatusLine: except http.client.BadStatusLine:
raise IRCException("Invalid HTTP response") raise IRCException("Invalid HTTP response")
finally: finally: