1
from twisted.web2 import responsecode
4
__all__ = ['addLocation']
6
def addLocation(request, location):
8
Add a C{location} header to the response if the response status is
10
@param request: L{IRequest} the request being processed
11
@param location: the URI to use in the C{location} header
13
def locationFilter(request, response):
14
if (response.code == responsecode.CREATED):
16
# Check to see whether we have an absolute URI or not.
17
# If not, have the request turn it into an absolute URI.
19
(scheme, host, path, params, querystring, fragment) = urlparse.urlparse(location)
22
uri = request.unparseURL(path=location)
26
response.headers.setHeader("location", uri)
30
request.addResponseFilter(locationFilter)