From e9a71dfd96bb42791ff97a5e6da5b0c8aa4a606e Mon Sep 17 00:00:00 2001 From: Klee Dienes Date: Mon, 31 Oct 2011 01:41:11 +0000 Subject: Properly process MIME encoding. --- CONTRIBUTORS.txt | 2 ++ pyramid/static.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index a368fb4d2..648f67c72 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -148,3 +148,5 @@ Contributors - Shane Hathaway, 2011/07/22 - Manuel Hermann, 2011/07/11 + +- Klee Dienes, 2011/10/30 diff --git a/pyramid/static.py b/pyramid/static.py index 50a8b918b..2a9abbd8f 100644 --- a/pyramid/static.py +++ b/pyramid/static.py @@ -43,10 +43,11 @@ class _FileResponse(Response): def __init__(self, path, cache_max_age): super(_FileResponse, self).__init__(conditional_response=True) self.last_modified = getmtime(path) - content_type = mimetypes.guess_type(path, strict=False)[0] + content_type, content_encoding = mimetypes.guess_type(path, strict=False) if content_type is None: content_type = 'application/octet-stream' self.content_type = content_type + self.content_encoding = content_encoding content_length = getsize(path) self.app_iter = _FileIter(open(path, 'rb'), content_length) # assignment of content_length must come after assignment of app_iter -- cgit v1.2.3 From 0e5441806857e3c1ef59d1b2075d6e4238587804 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 18 Nov 2011 05:48:30 -0500 Subject: add tests for content encoding feature --- pyramid/static.py | 3 +- pyramid/tests/fixtures/static/arcs.svg.tgz | 73 ++++++++++++++++++++++++++++++ pyramid/tests/test_static.py | 18 ++++++++ 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 pyramid/tests/fixtures/static/arcs.svg.tgz diff --git a/pyramid/static.py b/pyramid/static.py index 2a9abbd8f..ba4ac0fa1 100644 --- a/pyramid/static.py +++ b/pyramid/static.py @@ -43,7 +43,8 @@ class _FileResponse(Response): def __init__(self, path, cache_max_age): super(_FileResponse, self).__init__(conditional_response=True) self.last_modified = getmtime(path) - content_type, content_encoding = mimetypes.guess_type(path, strict=False) + content_type, content_encoding = mimetypes.guess_type(path, + strict=False) if content_type is None: content_type = 'application/octet-stream' self.content_type = content_type diff --git a/pyramid/tests/fixtures/static/arcs.svg.tgz b/pyramid/tests/fixtures/static/arcs.svg.tgz new file mode 100644 index 000000000..376c42ac8 --- /dev/null +++ b/pyramid/tests/fixtures/static/arcs.svg.tgz @@ -0,0 +1,73 @@ + + + + + + + + diff --git a/pyramid/tests/test_static.py b/pyramid/tests/test_static.py index a04a47397..bd2c2adef 100644 --- a/pyramid/tests/test_static.py +++ b/pyramid/tests/test_static.py @@ -160,6 +160,24 @@ class Test_static_view_use_subpath_False(unittest.TestCase): response = inst(context, request) self.assertEqual(response.status, '404 Not Found') + def test_resource_with_content_encoding(self): + inst = self._makeOne('pyramid.tests:fixtures/static') + request = self._makeRequest({'PATH_INFO':'/arcs.svg.tgz'}) + context = DummyContext() + response = inst(context, request) + self.assertEqual(response.status, '200 OK') + self.assertEqual(response.content_type, 'application/x-tar') + self.assertEqual(response.content_encoding, 'gzip') + + def test_resource_no_content_encoding(self): + inst = self._makeOne('pyramid.tests:fixtures/static') + request = self._makeRequest({'PATH_INFO':'/index.html'}) + context = DummyContext() + response = inst(context, request) + self.assertEqual(response.status, '200 OK') + self.assertEqual(response.content_type, 'text/html') + self.assertEqual(response.content_encoding, None) + class Test_static_view_use_subpath_True(unittest.TestCase): def _getTargetClass(self): from pyramid.static import static_view -- cgit v1.2.3