diff --git a/pecan/core.py b/pecan/core.py index 8155180..b6c09ff 100644 --- a/pecan/core.py +++ b/pecan/core.py @@ -371,10 +371,15 @@ class Pecan(object): # attempt to guess the content type based on the file extension if not request.pecan['content_type'] and '.' in path.split('/')[-1]: - path, extension = splitext(path) - request.pecan['extension'] = extension + new_path, extension = splitext(path) + # preface with a letter to ensure compat for 2.5 - request.pecan['content_type'] = guess_type('x' + extension)[0] + potential_type = guess_type('x' + extension)[0] + + if potential_type is not None: + path = new_path + request.pecan['extension'] = extension + request.pecan['content_type'] = potential_type controller, remainder = self.route(self.root, path) cfg = _cfg(controller) diff --git a/pecan/tests/test_base.py b/pecan/tests/test_base.py index 13d1c94..ba495b8 100644 --- a/pecan/tests/test_base.py +++ b/pecan/tests/test_base.py @@ -863,7 +863,11 @@ class TestFileTypeExtensions(unittest.TestCase): class RootController(object): @expose(content_type=None) def _default(self, *args): - return request.pecan['extension'] + ext = request.pecan.get('extension') + assert len(args) == 1 + if ext: + assert ext not in args[0] + return ext or '' return TestApp(Pecan(RootController())) @@ -883,7 +887,7 @@ class TestFileTypeExtensions(unittest.TestCase): assert r.body == '' def test_multi_dot_extension(self): - r = self.app_.get('/gradient.js.js') + r = self.app_.get('/gradient.min.js') assert r.status_int == 200 assert r.body == '.js' @@ -907,6 +911,20 @@ class TestFileTypeExtensions(unittest.TestCase): r = app.get('/index.txt', expect_errors=True) assert r.status_int == 404 + def test_unknown_file_extension(self): + class RootController(object): + @expose(content_type=None) + def _default(self, *args): + assert 'example:x.tiny' in args + assert 'extension' not in request.pecan + return 'SOME VALUE' + + app = TestApp(Pecan(RootController())) + + r = app.get('/example:x.tiny') + assert r.status_int == 200 + assert r.body == 'SOME VALUE' + class TestContentTypeByAcceptHeaders(unittest.TestCase):