TEST_P(DownstreamProtocolIntegrationTest, FaultyFilterWithConnect) {
  // TODO(danzh) re-enable after adding http3 option "allow_connect".
  EXCLUDE_DOWNSTREAM_HTTP3;
  if (upstreamProtocol() == FakeHttpConnection::Type::HTTP3) {
    // For QUIC, even through the headers are not sent upstream, the stream will
    // be created. Use the autonomous upstream and allow incomplete streams.
    autonomous_allow_incomplete_streams_ = true;
    autonomous_upstream_ = true;
  }
  // Faulty filter that removed host in a CONNECT request.
  config_helper_.addConfigModifier(
      [&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
              hcm) -> void { ConfigHelper::setConnectConfig(hcm, false, false); });
  config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
    // Clone the whole listener.
    auto static_resources = bootstrap.mutable_static_resources();
    auto* old_listener = static_resources->mutable_listeners(0);
    auto* cloned_listener = static_resources->add_listeners();
    cloned_listener->CopyFrom(*old_listener);
    old_listener->set_name("http_forward");
  });
  useAccessLog("%RESPONSE_CODE_DETAILS%");
  config_helper_.addFilter("{ name: invalid-header-filter, typed_config: { \"@type\": "
                           "type.googleapis.com/google.protobuf.Empty } }");
  initialize();
  codec_client_ = makeHttpConnection(lookupPort("http"));

  // Missing host for CONNECT
  auto headers = Http::TestRequestHeaderMapImpl{
      {":method", "CONNECT"}, {":scheme", "http"}, {":authority", "www.host.com:80"}};

  auto response = (downstream_protocol_ == Http::CodecClient::Type::HTTP1)
                      ? std::move((codec_client_->startRequest(headers)).second)
                      : codec_client_->makeHeaderOnlyRequest(headers);

  ASSERT_TRUE(response->waitForEndStream());
  EXPECT_TRUE(response->complete());
  EXPECT_EQ("503", response->headers().getStatusValue());
  EXPECT_THAT(waitForAccessLog(access_log_name_), HasSubstr("missing_required_header"));
}
TEST_P(DownstreamProtocolIntegrationTest, FaultyFilterWithConnect) {
   
  EXCLUDE_DOWNSTREAM_HTTP3;
  if (upstreamProtocol() == FakeHttpConnection::Type::HTTP3) {
     
     
    autonomous_allow_incomplete_streams_ = true;
    autonomous_upstream_ = true;
  }
   
  config_helper_.addConfigModifier(
      [&](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager&
              hcm) -> void { ConfigHelper::setConnectConfig(hcm, false, false); });
  config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
     
    auto static_resources = bootstrap.mutable_static_resources();
    auto* old_listener = static_resources->mutable_listeners(0);
    auto* cloned_listener = static_resources->add_listeners();
    cloned_listener->CopyFrom(*old_listener);
    old_listener->set_name("http_forward");
  });
  useAccessLog("%RESPONSE_CODE_DETAILS%");
  config_helper_.addFilter("{ name: invalid-header-filter, typed_config: { \"@type\": "
                           "type.googleapis.com/google.protobuf.Empty } }");
  initialize();
  codec_client_ = makeHttpConnection(lookupPort("http"));

   
  auto headers = Http::TestRequestHeaderMapImpl{
      {":method", "CONNECT"}, {":scheme", "http"}, {":authority", "www.host.com:80"}};

  auto response = (downstream_protocol_ == Http::CodecClient::Type::HTTP1)
                      ? std::move((codec_client_->startRequest(headers)).second)
                      : codec_client_->makeHeaderOnlyRequest(headers);

  ASSERT_TRUE(response->waitForEndStream());
  EXPECT_TRUE(response->complete());
  EXPECT_EQ("503", response->headers().getStatusValue());
  EXPECT_THAT(waitForAccessLog(access_log_name_), HasSubstr("missing_required_header"));
}