pip.index: fix crash getting Content-Type header

Returned headers may not always have the "Content-Type"
field available.  Avoid KeyError exceptions by using
dict.get() instead of blindly grabbing the header value.

Closes #32
This commit is contained in:
David Aguilar 2013-07-13 16:25:21 -07:00 committed by Donald Stufft
parent 437c8c13a1
commit bafcf59b2e
1 changed files with 3 additions and 2 deletions

View File

@ -685,9 +685,10 @@ class HTMLPage(object):
# Unless we issue a HEAD request on every url we cannot know
# ahead of time for sure if something is HTML or not. However we
# can check after we've downloaded it.
if not headers["Content-Type"].lower().startswith("text/html"):
content_type = headers.get('Content-Type', 'unknown')
if not content_type.lower().startswith("text/html"):
logger.debug('Skipping page %s because of Content-Type: %s' %
(link, headers["Content-Type"]))
(link, content_type))
if cache is not None:
cache.set_is_archive(url)
return None