def make_proxy(*global_conf, **local_conf): href = local_conf.get('href') secret_file = local_conf.get('secret_file') string_keys = lister(local_conf.get('string_keys')) unicode_keys = lister(local_conf.get('unicode_keys')) json_keys = lister(local_conf.get('json_keys')) pickle_keys = lister(local_conf.get('pickle_keys')) application = WSGIProxyApp( href, secret_file=secret_file, string_keys=string_keys, unicode_keys=unicode_keys, json_keys=json_keys, pickle_keys=pickle_keys, ) application.href = href application.target = local_conf.get('target', '/') application.use_x_headers = local_conf.get( 'use_x_headers', 'False').lower() == 'true' app = wrapper(application) # login info & metadata app.login_method = local_conf.get('login_method') app.login_url = local_conf.get('login_url') or href app.title = local_conf.get('title') or 'No title' app.link_url = local_conf.get('link_url', None) return app
def setup(): global TESTCONFIG global TESTAPP ## Tests can alter decl. THis resets everything reload(decl) # using nose-testconfig we obtain the config dict passed in through the # nosetests command line from testconfig import config ## now "convert" to app-style dict TESTCONFIG = convert_config(config) initdb(TESTCONFIG) cj = cookielib.CookieJar() ### Are we running by generating HTTP to fire at webserver ### or are we testing wsgi calls? if 'HTTPPROXY' in config.keys(): app = WSGIProxyApp(config['HTTPPROXY']) app.debug = True TESTAPP = TestApp(app, extra_environ={ 'REMOTE_ADDR': '1.2.3.4'}, cookiejar=cj) set_constants(config['HTTPPROXY'], TESTAPP) else: app = make_app(TESTCONFIG) app.debug = True sessioncache.set_config(config) TESTAPP = TestApp(app.wsgi_app, cookiejar=cj) set_constants("", TESTAPP)
def build_app(root): if root.startswith('http'): app = TestApp(WSGIProxyApp(root), extra_environ={"REMOTE_ADDR": root}) else: app = TestApp(CatchErrors(resolve_name(root))) return app
def __init__(self, scopes, client_secrets_file=FLAGS.secrets, oauth2_creds_file=FLAGS.creds, run_grant=FLAGS.prompt): self.client_secrets_file = client_secrets_file self.oauth2_creds_file = oauth2_creds_file self.oauth_client = httplib2.Http( disable_ssl_certificate_validation=FLAGS.anycert) self.open_clientsecrets(scopes) self.credentials = self.storage.get() if not self.credentials: if run_grant: self.credentials = oauth2client.tools.run( self.flow, self.storage, self.oauth_client) else: logging.error( "Please obtain the Oauth2 permission grant from the user by re-running this tool with option TODO." ) raise Exception("Missing oauth2 credentials in %s" % (self.oauth2_creds_file, )) if FLAGS.destination: self.proxy_destination = FLAGS.destination else: # take path part off, because requests will include it parts = urlparse.urlparse(self.secrets_data["server_base_uri"]) scheme, netloc, path, params, query, fragment = parts self.proxy_destination = urlparse.urlunparse( (scheme, netloc, "", params, query, fragment)) logging.info("Proxying to " + self.proxy_destination) self.proxy = WSGIProxyApp(self.proxy_destination)
def setUp(self): super(FunctionalTestCase, self).setUp() # Test against a live server if instructed so by the environment. # Otherwise, test against an in-process WSGI application. test_remote = os.environ.get("MOZSVC_TEST_REMOTE") if not test_remote: self.distant = False self.host_url = "http://localhost:5000" # This call implicity commits the configurator. application = self.config.make_wsgi_app() else: self.distant = True self.host_url = test_remote application = WSGIProxyApp(test_remote) # Explicitly commit so that calling code can introspect the config. self.config.commit() host_url = urlparse.urlparse(self.host_url) self.app = TestApp(application, extra_environ={ "HTTP_HOST": host_url.netloc, "wsgi.url_scheme": host_url.scheme or "http", "SERVER_NAME": host_url.hostname, "REMOTE_ADDR": "127.0.0.1", "SCRIPT_NAME": host_url.path, })
def proxy_to_camera(camera): proxy_app = WSGIProxyApp("http://" + camera.ip) def wrapped_proxy_app(environ, start_response): start_response = wrap_start_response(camera, environ, start_response) return proxy_app(environ, start_response) return wrapped_proxy_app
def forward_request(self, req): """ Forward the request using wsgi_proxy to real Swift backend """ if 'REMOTE_ADDR' not in req.environ: req.environ['REMOTE_ADDR'] = '127.0.0.1' if 'wsgi.url_scheme' not in req.environ: req.environ['wsgi.url_scheme'] = 'http' return req.get_response( WSGIProxyApp(href=self._app.forward_to))
def make_app( global_conf, href=None, secret_file=None): from wsgiproxy.app import WSGIProxyApp if href is None: raise ValueError( "You must give an href value") if secret_file is None and 'secret_file' in global_conf: secret_file = global_conf['secret_file'] return WSGIProxyApp(href=href, secret_file=secret_file)
def setup(): global TESTCONFIG global TESTAPP # using nose-testconfig we obtain the config dict passed in through the # nosetests command line from testconfig import config ## now "convert" to app-style dict TESTCONFIG = convert_config(config) if 'HTTPPROXY' in config.keys(): app = WSGIProxyApp(config['HTTPPROXY']) TESTAPP = TestApp(app, extra_environ={'REMOTE_ADDR': '1.2.3.4'}) else: app = make_app(TESTCONFIG) app.debug = True TESTAPP = TestApp(app.wsgi_app) print "Running setup" print "cookies", TESTAPP.cookies
def setup(): global TESTCONFIG global TESTAPP # using nose-testconfig we obtain the config dict passed in through the # nosetests command line from testconfig import config ## now "convert" to app-style dict TESTCONFIG = convert_config(config) # cleardown(TESTCONFIG) # initdb(TESTCONFIG) if 'HTTPPROXY' in config.keys(): app = WSGIProxyApp(config['HTTPPROXY']) TESTAPP = TestApp(app, extra_environ={'REMOTE_ADDR': '1.2.3.4'}) else: # cleardown(TESTCONFIG) # use this in setup - via a renaming? app = make_app(TESTCONFIG) app.debug = True TESTAPP = TestApp(app.wsgi_app)
def main(): args = get_args() configure_logger(logger, args.loglevel, args.logoutput) cache = None if args.cache: import pylibmc logger.info('Using the cache at %s' % args.cache) logger.info('The timeout value is set to %ss' % args.cache_timeout) cache = pylibmc.Client([args.cache]) statsd = None if args.statsd: import statsd logger.info('sending informations to statsd at %s' % args.statsd) statsd_host, statsd_port = args.statsd.split(':', 1) statsd = statsd.StatsClient(statsd_host, int(statsd_port), args.statsd_namespace) if args.excluded_paths and not cache: logger.info('--excluded-paths ignored; since no cache is being used') elif args.excluded_paths: args.excluded_paths = args.excluded_paths.split(',') logger.info('paths that will not be cached:' % args.excluded_paths) host, port = args.local.split(':') port = int(port) if not args.distant.startswith('http://'): args.distant = 'http://%s' % args.distant logger.info('Starting httpcache proxy. Listening on %s, proxying to %s, ' 'using the %s backend' % (args.local, args.distant, args.backend)) proxy = WSGIProxyApp(args.distant) app = CacheRequests(proxy, cache=cache, statsd=statsd, cache_timeout=args.cache_timeout, excluded_paths=args.excluded_paths, logger=logger) httpd = make_server(app, host, port=port, backend=args.backend) try: httpd.serve_forever() except KeyboardInterrupt: sys.exit(0) finally: logger.info('Exiting, bye!')
def create_proxy(host): proxy_app = WSGIProxyApp(host) def wrap_start_response(start_response): def wrapped_start_response(status, headers_out): # Remove "hop-by-hop" headers headers_out = [(k, v) for (k, v) in headers_out if k not in FILTER_HEADERS] return start_response(status, headers_out) return wrapped_start_response def wrapped_proxy_app(environ, start_response): start_response = wrap_start_response(start_response) return proxy_app(environ, start_response) return wrapped_proxy_app
def test_create(self): app = WSGIProxyApp(href='http://example.com/testform')
# Remove "hop-by-hop" headers (as defined by RFC2613, Section 13) # since they are not allowed by the WSGI standard. FILTER_HEADERS = [ 'Connection', 'Keep-Alive', 'Proxy-Authenticate', 'Proxy-Authorization', 'TE', 'Trailers', 'Transfer-Encoding', 'Upgrade', ] root = bottle.Bottle() proxy_app = WSGIProxyApp("http://localhost/") def wrap_start_response(start_response): def wrapped_start_response(status, headers_out): # Remove "hop-by-hop" headers headers_out = [(k, v) for (k, v) in headers_out if k not in FILTER_HEADERS] return start_response(status, headers_out) return wrapped_start_response def wrapped_proxy_app(environ, start_response): start_response = wrap_start_response(start_response) return proxy_app(environ, start_response)