~landscape/zope3/newer-from-ztk

« back to all changes in this revision

Viewing changes to src/twisted/web2/filter/location.py

  • Committer: Thomas Hervé
  • Date: 2009-07-08 13:52:04 UTC
  • Revision ID: thomas@canonical.com-20090708135204-df5eesrthifpylf8
Remove twisted copy

Show diffs side-by-side

added added

removed removed

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