diff options
Diffstat (limited to 'docs/source/routing.rst')
-rw-r--r-- | docs/source/routing.rst | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/docs/source/routing.rst b/docs/source/routing.rst index ec79305..68a46ba 100644 --- a/docs/source/routing.rst +++ b/docs/source/routing.rst @@ -270,11 +270,11 @@ a :func:`_route` method will enable you to have total control. Interacting with the Request and Response Object ------------------------------------------------ -For every HTTP request, Pecan maintains a thread-local reference to the request -and response object, ``pecan.request`` and ``pecan.response``. These are -instances of :class:`webob.request.BaseRequest` and -:class:`webob.response.Response`, respectively, and can be interacted with from -within Pecan controller code:: +For every HTTP request, Pecan maintains a :ref:`thread-local reference +<contextlocals>` to the request and response object, ``pecan.request`` and +``pecan.response``. These are instances of :class:`pecan.Request` +and :class:`pecan.Response`, respectively, and can be interacted with +from within Pecan controller code:: @pecan.expose() def login(self): @@ -282,8 +282,8 @@ within Pecan controller code:: username = pecan.request.POST.get('username') password = pecan.request.POST.get('password') - pecan.response.status_int = 403 - pecan.response.body = 'Bad Login!' + pecan.response.status = 403 + pecan.response.text = 'Bad Login!' While Pecan abstracts away much of the need to interact with these objects directly, there may be situations where you want to access them, such as: @@ -295,6 +295,34 @@ directly, there may be situations where you want to access them, such as: * Manually rendering a response body +Extending Pecan's Request and Response Object +--------------------------------------------- + +The request and response implementations provided by WebOb are powerful, but +at times, it may be useful to extend application-specific behavior onto your +request and response (such as specialized parsing of request headers or +customized response body serialization). To do so, define custom classes that +inherit from ``pecan.Request`` and ``pecan.Response``, respectively:: + + class MyRequest(pecan.Request): + pass + + class MyResponse(pecan.Response): + pass + +and modify your application configuration to use them:: + + from myproject import MyRequest, MyResponse + + app = { + 'root' : 'project.controllers.root.RootController', + 'modules' : ['project'], + 'static_root' : '%(confdir)s/public', + 'template_path' : '%(confdir)s/project/templates', + 'request_cls': MyRequest, + 'response_cls': MyResponse + } + Mapping Controller Arguments ---------------------------- |