TEST_F(ConnectionManagerUtilityTest, ExternalAddressExternalRequestUseRemote) {
  connection_.stream_info_.downstream_address_provider_->setRemoteAddress(
      std::make_shared<Network::Address::Ipv4Instance>("50.0.0.1"));
  ON_CALL(config_, useRemoteAddress()).WillByDefault(Return(true));
  route_config_.internal_only_headers_.push_back(LowerCaseString("custom_header"));
  TestRequestHeaderMapImpl headers{{"x-envoy-decorator-operation", "foo"},
                                   {"x-envoy-downstream-service-cluster", "foo"},
                                   {"x-envoy-hedge-on-per-try-timeout", "foo"},
                                   {"x-envoy-retriable-status-codes", "123,456"},
                                   {"x-envoy-retry-on", "foo"},
                                   {"x-envoy-retry-grpc-on", "foo"},
                                   {"x-envoy-max-retries", "foo"},
                                   {"x-envoy-upstream-alt-stat-name", "foo"},
                                   {"x-envoy-upstream-rq-timeout-alt-response", "204"},
                                   {"x-envoy-upstream-rq-timeout-ms", "foo"},
                                   {"x-envoy-expected-rq-timeout-ms", "10"},
                                   {"x-envoy-ip-tags", "bar"},
                                   {"x-envoy-original-url", "my_url"},
                                   {"custom_header", "foo"}};

  EXPECT_EQ((MutateRequestRet{"50.0.0.1:0", false, Tracing::Reason::NotTraceable}),
            callMutateRequestHeaders(headers, Protocol::Http2));
  EXPECT_EQ("50.0.0.1", headers.get_("x-envoy-external-address"));
  EXPECT_FALSE(headers.has("x-envoy-decorator-operation"));
  EXPECT_FALSE(headers.has("x-envoy-downstream-service-cluster"));
  EXPECT_FALSE(headers.has("x-envoy-hedge-on-per-try-timeout"));
  EXPECT_FALSE(headers.has("x-envoy-retriable-status-codes"));
  EXPECT_FALSE(headers.has("x-envoy-retry-on"));
  EXPECT_FALSE(headers.has("x-envoy-retry-grpc-on"));
  EXPECT_FALSE(headers.has("x-envoy-max-retries"));
  EXPECT_FALSE(headers.has("x-envoy-upstream-alt-stat-name"));
  EXPECT_FALSE(headers.has("x-envoy-upstream-rq-timeout-alt-response"));
  EXPECT_FALSE(headers.has("x-envoy-upstream-rq-timeout-ms"));
  EXPECT_FALSE(headers.has("x-envoy-expected-rq-timeout-ms"));
  EXPECT_FALSE(headers.has("x-envoy-ip-tags"));
  EXPECT_FALSE(headers.has("x-envoy-original-url"));
  EXPECT_FALSE(headers.has("custom_header"));
}
TEST_F(ConnectionManagerUtilityTest, ExternalAddressExternalRequestUseRemote) {
  connection_.stream_info_.downstream_address_provider_->setRemoteAddress(
      std::make_shared<Network::Address::Ipv4Instance>("50.0.0.1"));
  ON_CALL(config_, useRemoteAddress()).WillByDefault(Return(true));
  route_config_.internal_only_headers_.push_back(LowerCaseString("custom_header"));
  TestRequestHeaderMapImpl headers{{"x-envoy-decorator-operation", "foo"},
                                   {"x-envoy-downstream-service-cluster", "foo"},
                                   {"x-envoy-hedge-on-per-try-timeout", "foo"},
                                   {"x-envoy-retriable-status-codes", "123,456"},
                                   {"x-envoy-retry-on", "foo"},
                                   {"x-envoy-retry-grpc-on", "foo"},
                                   {"x-envoy-max-retries", "foo"},
                                   {"x-envoy-upstream-alt-stat-name", "foo"},
                                   {"x-envoy-upstream-rq-timeout-alt-response", "204"},
                                   {"x-envoy-upstream-rq-timeout-ms", "foo"},
                                   {"x-envoy-expected-rq-timeout-ms", "10"},
                                   {"x-envoy-ip-tags", "bar"},
                                   {"x-envoy-original-url", "my_url"},
                                   {"custom_header", "foo"}};

  EXPECT_EQ((MutateRequestRet{"50.0.0.1:0", false, Tracing::Reason::NotTraceable}),
            callMutateRequestHeaders(headers, Protocol::Http2));
  EXPECT_EQ("50.0.0.1", headers.get_("x-envoy-external-address"));
  EXPECT_FALSE(headers.has("x-envoy-decorator-operation"));
  EXPECT_FALSE(headers.has("x-envoy-downstream-service-cluster"));
  EXPECT_FALSE(headers.has("x-envoy-hedge-on-per-try-timeout"));
  EXPECT_FALSE(headers.has("x-envoy-retriable-status-codes"));
  EXPECT_FALSE(headers.has("x-envoy-retry-on"));
  EXPECT_FALSE(headers.has("x-envoy-retry-grpc-on"));
  EXPECT_FALSE(headers.has("x-envoy-max-retries"));
  EXPECT_FALSE(headers.has("x-envoy-upstream-alt-stat-name"));
  EXPECT_FALSE(headers.has("x-envoy-upstream-rq-timeout-alt-response"));
  EXPECT_FALSE(headers.has("x-envoy-upstream-rq-timeout-ms"));
  EXPECT_FALSE(headers.has("x-envoy-expected-rq-timeout-ms"));
  EXPECT_FALSE(headers.has("x-envoy-ip-tags"));
  EXPECT_FALSE(headers.has("x-envoy-original-url"));
  EXPECT_FALSE(headers.has("custom_header"));
}