Statistics
| Branch: | Tag: | Revision:

root / middleware / __init__.py @ 3758cc42

History | View | Annotate | Download (776 Bytes)

1
# vim: ts=4 sts=4 et ai sw=4 fileencoding=utf-8
2
#
3
# Copyright © 2010 Greek Research and Technology Network
4
#
5

    
6
import re
7

    
8
_strip_url_re = re.compile(r'^https?://[^/]+')
9

    
10
class StripURLMiddleware(object):
11
    """
12
    At least some Cloud Servers API clients tend to use full URLs as request
13
    paths, contrary to all RFCs.
14

15
    This is a) wrong, b) incompatible with Django's urlconf.
16

17
    This middleware attempts to strip such URLs so that the URL dispatcher can
18
    process it normally.
19

20
    It should be inserted as early as possible in MIDDLEWARE_CLASSES
21
    """
22

    
23
    def process_request(self, request):
24
        request.path = re.sub(_strip_url_re, '', request.path)
25
        request.path_info = re.sub(_strip_url_re, '', request.path_info)
26
        print request.path_info