Exemple #1
0
def AddWebProxy(server_manager, options, host, real_dns_lookup, http_archive,
                cache_misses):
  inject_script = httpclient.GetInjectScript(options.inject_scripts)
  custom_handlers = customhandlers.CustomHandlers(options, http_archive)
  if options.spdy:
    assert not options.record, 'spdy cannot be used with --record.'
    archive_fetch = httpclient.ReplayHttpArchiveFetch(
        http_archive,
        inject_script,
        options.diff_unknown_requests,
        cache_misses=cache_misses,
        use_closest_match=options.use_closest_match)
    server_manager.Append(
        replayspdyserver.ReplaySpdyServer, archive_fetch,
        custom_handlers, host=host, port=options.port,
        certfile=options.certfile)
  else:
    custom_handlers.add_server_manager_handler(server_manager)
    archive_fetch = httpclient.ControllableHttpArchiveFetch(
        http_archive, real_dns_lookup,
        inject_script,
        options.diff_unknown_requests, options.record,
        cache_misses=cache_misses, use_closest_match=options.use_closest_match)
    server_manager.AppendRecordCallback(archive_fetch.SetRecordMode)
    server_manager.AppendReplayCallback(archive_fetch.SetReplayMode)
    server_manager.Append(
        httpproxy.HttpProxyServer,
        archive_fetch, custom_handlers,
        host=host, port=options.port, **options.shaping_http)
    if options.ssl:
      server_manager.Append(
          httpproxy.HttpsProxyServer,
          archive_fetch, custom_handlers, options.certfile,
          host=host, port=options.ssl_port, **options.shaping_http)
Exemple #2
0
 def testFetch(self):
     request = httparchive.ArchivedHttpRequest('GET', 'www.test.com', '/',
                                               None, {})
     response = self.createTestResponse()
     archive = httparchive.HttpArchive()
     archive[request] = response
     fetch = httpclient.ReplayHttpArchiveFetch(archive, None,
                                               self.dummy_injector)
     self.checkTestResponse(fetch(request), archive, request)
    def testInjectedDate(self, os_path, util_exists, util_resource_string):
        os_path.return_value = False
        util_exists.return_value = True
        util_resource_string.return_value = \
            ["""var time_seed={}""".format(script_injector.TIME_SEED_MARKER)]
        request = httparchive.ArchivedHttpRequest('GET', 'www.test.com', '/',
                                                  None, {})
        response = self.createTestResponse()
        archive = httparchive.HttpArchive()
        archive[request] = response

        fetch = httpclient.ReplayHttpArchiveFetch(
            archive, None, script_injector.GetScriptInjector("time_script.js"))
        self.assertEqual(
            ['<script>var time_seed=1479344523000</script><body>test</body>'],
            fetch(request).response_data)
Exemple #4
0
def AddWebProxy(server_manager, options, host, real_dns_lookup, http_archive,
                cache_misses):
    inject_script = script_injector.GetInjectScript(options.inject_scripts)
    custom_handlers = customhandlers.CustomHandlers(options, http_archive)
    if options.spdy:
        assert not options.record, 'spdy cannot be used with --record.'
        archive_fetch = httpclient.ReplayHttpArchiveFetch(
            http_archive,
            real_dns_lookup,
            inject_script,
            options.diff_unknown_requests,
            cache_misses=cache_misses,
            use_closest_match=options.use_closest_match,
            scramble_images=options.scramble_images)
        server_manager.Append(replayspdyserver.ReplaySpdyServer,
                              archive_fetch,
                              custom_handlers,
                              host=host,
                              port=options.port,
                              certfile=options.https_root_ca_cert_path)
    else:
        custom_handlers.add_server_manager_handler(server_manager)
        json_rules = []
        if options.json_rules:
            # TODO(wrightt): re: support comma-separated file names & dirs
            with open(options.json_rules, 'r') as json_file:
                json_rules = json.load(json_file)
            comments = []
            for i, rule in enumerate(json_rules):
                if not isinstance(rule, list):
                    raise ValueError('Rule number %d should be a list' % i)
                if (rule[0] == '_comment') | (rule[0][0] == '#'):
                    comments.append(i)
                else:
                    assert len(rule) in (3, 4)
            for i in comments[::-1]:
                json_rules.pop(i)

        archive_fetch = httpclient.ControllableHttpArchiveFetch(
            http_archive,
            real_dns_lookup,
            inject_script,
            options.diff_unknown_requests,
            options.record,
            json_rules,
            cache_misses=cache_misses,
            use_closest_match=options.use_closest_match,
            scramble_images=options.scramble_images)
        server_manager.AppendRecordCallback(archive_fetch.SetRecordMode)
        server_manager.AppendReplayCallback(archive_fetch.SetReplayMode)
        server_manager.Append(httpproxy.HttpProxyServer,
                              archive_fetch,
                              custom_handlers,
                              host=host,
                              port=options.port,
                              rules=json_rules,
                              use_delays=options.use_server_delay,
                              **options.shaping_http)
        if options.ssl:
            if options.should_generate_certs:
                server_manager.Append(httpproxy.HttpsProxyServer,
                                      archive_fetch,
                                      custom_handlers,
                                      options.https_root_ca_cert_path,
                                      host=host,
                                      port=options.ssl_port,
                                      rules=json_rules,
                                      use_delays=options.use_server_delay,
                                      **options.shaping_http)
            else:
                server_manager.Append(httpproxy.SingleCertHttpsProxyServer,
                                      archive_fetch,
                                      custom_handlers,
                                      options.https_root_ca_cert_path,
                                      host=host,
                                      port=options.ssl_port,
                                      rules=json_rules,
                                      use_delays=options.use_server_delay,
                                      **options.shaping_http)
        if options.http_to_https_port:
            server_manager.Append(httpproxy.HttpToHttpsProxyServer,
                                  archive_fetch,
                                  custom_handlers,
                                  host=host,
                                  port=options.http_to_https_port,
                                  rules=json_rules,
                                  use_delays=options.use_server_delay,
                                  **options.shaping_http)
Exemple #5
0
def AddWebProxy(server_manager, options, host, real_dns_lookup, http_archive,
                cache_misses):
    inject_script = script_injector.GetInjectScript(options.inject_scripts)
    custom_handlers = customhandlers.CustomHandlers(options, http_archive)
    if options.spdy:
        assert not options.record, 'spdy cannot be used with --record.'
        archive_fetch = httpclient.ReplayHttpArchiveFetch(
            http_archive,
            real_dns_lookup,
            inject_script,
            options.diff_unknown_requests,
            cache_misses=cache_misses,
            use_closest_match=options.use_closest_match,
            scramble_images=options.scramble_images)
        server_manager.Append(replayspdyserver.ReplaySpdyServer,
                              archive_fetch,
                              custom_handlers,
                              host=host,
                              port=options.port,
                              certfile=options.https_root_ca_cert_path)
    else:
        custom_handlers.add_server_manager_handler(server_manager)
        archive_fetch = httpclient.ControllableHttpArchiveFetch(
            http_archive,
            real_dns_lookup,
            inject_script,
            options.diff_unknown_requests,
            options.record,
            cache_misses=cache_misses,
            use_closest_match=options.use_closest_match,
            scramble_images=options.scramble_images)
        server_manager.AppendRecordCallback(archive_fetch.SetRecordMode)
        server_manager.AppendReplayCallback(archive_fetch.SetReplayMode)
        server_manager.Append(httpproxy.HttpProxyServer,
                              archive_fetch,
                              custom_handlers,
                              host=host,
                              port=options.port,
                              use_delays=options.use_server_delay,
                              **options.shaping_http)
        if options.ssl:
            if options.should_generate_certs:
                server_manager.Append(httpproxy.HttpsProxyServer,
                                      archive_fetch,
                                      custom_handlers,
                                      options.https_root_ca_cert_path,
                                      host=host,
                                      port=options.ssl_port,
                                      use_delays=options.use_server_delay,
                                      **options.shaping_http)
            else:
                server_manager.Append(httpproxy.SingleCertHttpsProxyServer,
                                      archive_fetch,
                                      custom_handlers,
                                      options.https_root_ca_cert_path,
                                      host=host,
                                      port=options.ssl_port,
                                      use_delays=options.use_server_delay,
                                      **options.shaping_http)
        if options.http_to_https_port:
            server_manager.Append(httpproxy.HttpToHttpsProxyServer,
                                  archive_fetch,
                                  custom_handlers,
                                  host=host,
                                  port=options.http_to_https_port,
                                  use_delays=options.use_server_delay,
                                  **options.shaping_http)