def _wsgi_get(self, path_info, **kwargs): if path_info.startswith('/'): if 'app' in kwargs: app = kwargs.pop('app') elif self.app is not no_default: app = self.app else: raise ValueError('There is no app available') else: if HostProxy is not no_default: app = HostProxy(path_info) path_info = '/' else: raise ImportError('restkit is not installed') environ = kwargs.pop('environ').copy() environ.update(kwargs) # unsuported (came from Deliverance) for key in [ 'HTTP_ACCEPT_ENCODING', 'HTTP_IF_MATCH', 'HTTP_IF_UNMODIFIED_SINCE', 'HTTP_RANGE', 'HTTP_IF_RANGE' ]: if key in environ: del environ[key] req = Request.blank(path_info) req.environ.update(environ) resp = req.get_response(app) status = resp.status.split() ctype = resp.content_type.split(';')[0] if status[0] not in '45' and ctype == 'text/html': body = resp.body else: body = [] result = self.__class__( body, parent=self._parent, app=self.app, # always return self.app response=resp) return result
# This file is part of restkit released under the MIT license. # See the NOTICE for more information. from six.moves.urllib import parse as urlparse from webob import Request from restkit.contrib.wsgi_proxy import HostProxy import restkit from restkit.conn import Connection from socketpool import ConnectionPool restkit.set_logging("debug") pool = ConnectionPool(factory=Connection, max_size=10, backend="thread") proxy = HostProxy("http://127.0.0.1:5984", pool=pool) def application(environ, start_response): req = Request(environ) if 'RAW_URI' in req.environ: # gunicorn so we use real path non encoded u = urlparse.urlparse(req.environ['RAW_URI']) req.environ['PATH_INFO'] = u.path # do smth like adding oauth headers .. resp = req.get_response(proxy) # rewrite response # do auth ... return resp(environ, start_response)
def __init__(self, uri="http://127.0.0.1:5984", allowed_method=ALLOWED_METHODS, **kwargs): self.proxy = HostProxy(uri, allowed_methods=allowed_method, **kwargs)