Changeset 5146
- Timestamp:
- 08/14/08 11:20:34 (5 months ago)
- Files:
-
- trunk/tg/controllers.py (modified) (2 diffs)
- trunk/tg/decorators.py (modified) (1 diff)
- trunk/tg/tests/test_tg_controller_dispatch.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/tg/controllers.py
r5108 r5146 29 29 30 30 log = logging.getLogger(__name__) 31 32 # If someone goes @expose(content_type=CUSTOM_CONTENT_TYPE) then we won't override pylons.request.content_type 33 CUSTOM_CONTENT_TYPE = 'CUSTOM/LEAVE' 31 34 32 35 def _configured_engines(): … … 207 210 controller.decoration.lookup_template_engine(pylons.request) 208 211 209 # Always set content type210 pylons.response.headers['Content-Type'] = content_type212 if content_type != CUSTOM_CONTENT_TYPE: 213 pylons.response.headers['Content-Type'] = content_type 211 214 # Save these objeccts as locals from the SOP to avoid expensive lookups 212 215 req = pylons.request._current_obj() trunk/tg/decorators.py
r5053 r5146 71 71 engine, template, exclude_names = self.engines[content_type] 72 72 73 if 'charset' not in content_type: 73 if 'charset' not in content_type and ( 74 content_type.startswith('text') or content_type == 'application/json'): 74 75 content_type = '%s; charset=utf-8' % content_type 75 76 trunk/tg/tests/test_tg_controller_dispatch.py
r5126 r5146 2 2 3 3 import tg, pylons 4 from tg.controllers import TGController 4 from tg.controllers import TGController, CUSTOM_CONTENT_TYPE 5 5 from tg.decorators import expose, validate 6 6 from routes import Mapper … … 123 123 return dict(got_json=True) 124 124 125 @expose(content_type=CUSTOM_CONTENT_TYPE) 126 def custom_content_type(self): 127 pylons.response.headers['content-type'] = 'image/png' 128 return 'PNG' 129 130 125 131 class TestTGController(TestWSGIController): 126 132 def __init__(self, *args, **kargs): … … 214 220 assert '{"got_json' in resp.body 215 221 222 def test_custom_content_type(self): 223 resp = self.app.get('/custom_content_type') 224 self.assertEqual('image/png', dict(resp.headers)['content-type']) 225 assert resp.body == 'PNG' 226