1
2
3
4
5
6 import urlparse
7
8 from restkit.contrib.wsgi_proxy import HostProxy, ALLOWED_METHODS
9 from webob import Request
10
12 """\
13 WSGI application to proxy a couchdb server.
14
15 Simple usage to proxy a CouchDB server on default url::
16
17 from couchdbkit.wsgi import CouchdbProxy
18 application = CouchdbProxy()
19 """
20
21 - def __init__(self, uri="http://127.0.0.1:5984",
22 allowed_method=ALLOWED_METHODS, **kwargs):
23 self.proxy = HostProxy(uri, allowed_methods=allowed_method,
24 **kwargs)
25
26 - def do_proxy(self, req, environ, start_response):
27 """\
28 return proxy response. Can be overrided to add authentification and
29 such. It's better to override do_proxy method than the __call__
30 """
31 return req.get_response(self.proxy)
32
33 - def __call__(self, environ, start_response):
34 req = Request(environ)
35 if 'RAW_URI' in req.environ:
36
37 u = urlparse.urlparse(req.environ['RAW_URI'])
38 req.environ['PATH_INFO'] = u.path
39
40 resp = self.do_proy(req, environ, start_response)
41 return resp(environ, start_response)
42