Example #1
0
    def test_it_propagates_matching_query_params_to_redirect_location(
            self, client_get, upstream_status, upstream_location):
        def upstream_app(environ, start_response):
            start_response(upstream_status, [("Location", upstream_location)])
            return []

        request_url = "/example.com/old-path?q=foobar&via.open_sidebar=1"

        resp = client_get(request_url, ConfigExtractor(upstream_app))

        assert resp.status == upstream_status
        assert (resp.headers.get("Location") ==
                "https://example.com/moved?via.open_sidebar=1")
Example #2
0
    def test_it_returns_response_unmodified_if_upstream_returns_non_3xx_status(
            self, client_get, upstream_status, upstream_headers):
        upstream_body = "Content from upstream"

        def upstream_app(environ, start_response):
            start_response(upstream_status, upstream_headers)
            return upstream_body

        request_url = "/example.com/a_path?q=foobar&via.open_sidebar=1"

        resp = client_get(request_url, ConfigExtractor(upstream_app))

        assert resp.data == upstream_body
        assert resp.status == upstream_status
        assert resp.headers.items() == upstream_headers
Example #3
0
    template_params = environ.get("pywb.template_params", {})
    template_params["h_embed_url"] = embed_url
    environ["pywb.template_params"] = template_params

    return pywb.apps.wayback.application(environ, start_response)


application = RequestHeaderSanitiser(app)
application = ResponseHeaderSanitiser(application)
application = Blocker(
    application,
    checkmate_host=os.environ["CHECKMATE_URL"],
    api_key=os.environ["CHECKMATE_API_KEY"],
)
application = UserAgentDecorator(application, "Hypothesis-Via")
application = ConfigExtractor(application)
application = wsgi.DispatcherMiddleware(
    application,
    {
        "/favicon.ico": static.Cling("static/favicon.ico"),
        "/robots.txt": static.Cling("static/robots.txt"),
        "/static": static.Cling("static/"),
        "/static/__pywb": static.Cling(resource_filename("pywb", "static/")),
        "/static/__shared/viewer/web/viewer.html": redirect_old_viewer,
        "/h": redirect_strip_matched_path,
        "/_status": status_endpoint,
    },
)
application = newrelic.agent.WSGIApplicationWrapper(application, name="proxy")
Example #4
0
 def app(self):
     return ConfigExtractor(upstream_app)