diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-06-25 21:25:49 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-06-25 21:25:49 +0000 |
commit | 9017d113cdd9cddb53894fbba67227e94755a509 (patch) | |
tree | 60a4ff6883f2bb7a0428d86fcb51ac14a49797eb /docs | |
parent | 3ab38a675086426aca086dbd66bfde667ecb6ade (diff) | |
parent | 21f70bbba74ab940b3bf24bfb4cc859fe8926492 (diff) | |
download | pecan-9017d113cdd9cddb53894fbba67227e94755a509.tar.gz |
Merge "Add support for specifying custom request and response implementations."
Diffstat (limited to 'docs')
-rw-r--r-- | docs/source/routing.rst | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/docs/source/routing.rst b/docs/source/routing.rst index be8e987..68a46ba 100644 --- a/docs/source/routing.rst +++ b/docs/source/routing.rst @@ -272,8 +272,8 @@ Interacting with the Request and Response Object 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:`webob.request.BaseRequest` -and :class:`webob.response.Response`, respectively, and can be interacted with +``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() @@ -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 ---------------------------- |