summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-02-19 17:14:39 +0000
committerGerrit Code Review <review@openstack.org>2014-02-19 17:14:39 +0000
commitf5ee2e5bb56f1e67b06ed752087d92a3a66b070c (patch)
tree6c5f3cba48cfccf4507df235b408f03260f9ad44
parente8b2ce56a07fae8c1a83de1457c7e70bd975f41f (diff)
parenta6d5395770fb50f3590ee493cbd03a652a127d20 (diff)
downloadpecan-f5ee2e5bb56f1e67b06ed752087d92a3a66b070c.tar.gz
Merge "Add improved documentation for `pecan.request` and `pecan.response`."
-rw-r--r--docs/source/routing.rst28
1 files changed, 28 insertions, 0 deletions
diff --git a/docs/source/routing.rst b/docs/source/routing.rst
index da8c785..ec79305 100644
--- a/docs/source/routing.rst
+++ b/docs/source/routing.rst
@@ -267,6 +267,34 @@ routing system on top of Pecan, defining a base controller class that defines
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::
+
+ @pecan.expose()
+ def login(self):
+ assert pecan.request.path == '/login'
+ username = pecan.request.POST.get('username')
+ password = pecan.request.POST.get('password')
+
+ pecan.response.status_int = 403
+ pecan.response.body = '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:
+
+* Inspecting components of the URI
+* Determining aspects of the request, such as the user's IP address, or the
+ referer header
+* Setting specific response headers
+* Manually rendering a response body
+
+
Mapping Controller Arguments
----------------------------