diff --git a/scrapy/trunk/scrapy/core/downloader/responsetypes/__init__.py b/scrapy/trunk/scrapy/core/downloader/responsetypes/__init__.py index 89a39fe8b..32550ad3f 100644 --- a/scrapy/trunk/scrapy/core/downloader/responsetypes/__init__.py +++ b/scrapy/trunk/scrapy/core/downloader/responsetypes/__init__.py @@ -31,7 +31,10 @@ class ResponseTypes(object): def from_mimetype(self, mimetype): """Return the most appropiate Response class for the given mimetype""" - return self.classes.get(mimetype, self.classes.get(mimetype.split('/')[0], Response)) + if mimetype is not None: + return self.classes.get(mimetype, self.classes.get(mimetype.split('/')[0], Response)) + else: + return Response def from_content_type(self, content_type): """Return the most appropiate Response class from an HTTP Content-Type diff --git a/scrapy/trunk/scrapy/tests/test_responsetypes.py b/scrapy/trunk/scrapy/tests/test_responsetypes.py index 5a7fd66e8..76c4e7822 100644 --- a/scrapy/trunk/scrapy/tests/test_responsetypes.py +++ b/scrapy/trunk/scrapy/tests/test_responsetypes.py @@ -65,6 +65,9 @@ class ResponseTypesTest(unittest.TestCase): ({'url': 'http://www.example.com/data.csv'}, TextResponse), # headers takes precedence over url ({'headers': Headers({'Content-Type': ['text/html; charset=utf-8']}), 'url': 'http://www.example.com/item/'}, HtmlResponse), + ({'headers': Headers({'Content-Disposition': ['attachment; filename="data.xml.gz"']}), 'url': 'http://www.example.com/page/'}, Response), + + ] for source, cls in mappings: retcls = responsetypes.from_args(**source)