Package couchdbkit :: Package wsgi :: Module proxy
[hide private]
[frames] | no frames]

Source Code for Module couchdbkit.wsgi.proxy

 1  # -*- coding: utf-8 - 
 2  # 
 3  # This file is part of couchdbkit released under the MIT license.  
 4  # See the NOTICE for more information. 
 5   
 6  import urlparse 
 7   
 8  from restkit.contrib.wsgi_proxy import HostProxy, ALLOWED_METHODS 
 9  from webob import Request 
10   
11 -class CouchdbProxy(object):
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 # gunicorn so we can use real path non encoded 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