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)
def AddWebProxy(server_manager, options, host, real_dns_lookup, http_archive):
  if options.rules_path:
    with open(options.rules_path) as file_obj:
      allowed_imports = [
          name.strip() for name in options.allowed_rule_imports.split(',')]
      rules = rules_parser.Rules(file_obj, allowed_imports)
    logging.info('Parsed %s rules:\n%s', options.rules_path, rules)
  else:
    rules = rules_parser.Rules()
  injector = script_injector.GetScriptInjector(options.inject_scripts)
  custom_handlers = customhandlers.CustomHandlers(options, http_archive)
  custom_handlers.add_server_manager_handler(server_manager)
  archive_fetch = httpclient.ControllableHttpArchiveFetch(
      http_archive, real_dns_lookup,
      injector,
      options.diff_unknown_requests, options.record,
      use_closest_match=options.use_closest_match,
      scramble_images=options.scramble_images)
  server_manager.AppendRecordCallback(archive_fetch.SetRecordMode)
  server_manager.AppendReplayCallback(archive_fetch.SetReplayMode)
  allow_generate_304 = not options.record
  server_manager.Append(
      httpproxy.HttpProxyServer,
      archive_fetch, custom_handlers, rules,
      host=host, port=options.port, use_delays=options.use_server_delay,
      allow_generate_304=allow_generate_304,
      **options.shaping_http)
  if options.ssl:
    if options.should_generate_certs:
      server_manager.Append(
          httpproxy.HttpsProxyServer, archive_fetch, custom_handlers, rules,
          options.https_root_ca_cert_path, host=host, port=options.ssl_port,
          allow_generate_304=allow_generate_304,
          use_delays=options.use_server_delay, **options.shaping_http)
    else:
      server_manager.Append(
          httpproxy.SingleCertHttpsProxyServer, archive_fetch,
          custom_handlers, rules, options.https_root_ca_cert_path, host=host,
          port=options.ssl_port, use_delays=options.use_server_delay,
          allow_generate_304=allow_generate_304,
          **options.shaping_http)
  if options.http_to_https_port:
    server_manager.Append(
        httpproxy.HttpToHttpsProxyServer,
        archive_fetch, custom_handlers, rules,
        host=host, port=options.http_to_https_port,
        use_delays=options.use_server_delay,
        allow_generate_304=allow_generate_304,
        **options.shaping_http)
Exemple #3
0
def AddWebProxy(server_manager, options, host, real_dns_lookup, http_archive):
    inject_script = script_injector.GetInjectScript(options.inject_scripts)
    custom_handlers = customhandlers.CustomHandlers(options, http_archive)
    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,
        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)
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)