~landscape/zope3/ztk-1.1.3

« back to all changes in this revision

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

  • Committer: Andreas Hasenack
  • Date: 2009-07-20 17:49:16 UTC
  • Revision ID: andreas@canonical.com-20090720174916-g2tn6qmietz2hn0u
Revert twisted removal, it breaks several dozen tests [trivial]

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)