TEST_F(HttpHealthCheckerImplTest, SuccessServiceCheckWithAdditionalHeaders) {
  const Http::LowerCaseString header_ok("x-envoy-ok");
  const Http::LowerCaseString header_cool("x-envoy-cool");
  const Http::LowerCaseString header_awesome("x-envoy-awesome");
  const Http::LowerCaseString upstream_metadata("x-upstream-metadata");
  const Http::LowerCaseString protocol("x-protocol");
  const Http::LowerCaseString downstream_remote_address("x-downstream-remote-address");
  const Http::LowerCaseString downstream_remote_address_without_port(
      "x-downstream-remote-address-without-port");
  const Http::LowerCaseString downstream_local_address("x-downstream-local-address");
  const Http::LowerCaseString downstream_local_address_without_port(
      "x-downstream-local-address-without-port");
  const Http::LowerCaseString start_time("x-start-time");

  const std::string value_ok = "ok";
  const std::string value_cool = "cool";
  const std::string value_awesome = "awesome";

  const std::string value_user_agent = "CoolEnvoy/HC";
  const std::string value_upstream_metadata = "value";
  const std::string value_protocol = "HTTP/1.1";
  const std::string value_downstream_remote_address = "127.0.0.1:0";
  const std::string value_downstream_remote_address_without_port = "127.0.0.1";
  const std::string value_downstream_local_address = "127.0.0.1:0";
  const std::string value_downstream_local_address_without_port = "127.0.0.1";

  setupServiceValidationWithAdditionalHeaders();
  // Requires non-empty `service_name` in config.
  EXPECT_CALL(runtime_.snapshot_, featureEnabled("health_check.verify_cluster", 100))
      .WillOnce(Return(true));

  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Unchanged));
  auto metadata = TestUtility::parseYaml<envoy::config::core::v3::Metadata>(
      R"EOF(
        filter_metadata:
          namespace:
            key: value
      )EOF");

  cluster_->prioritySet().getMockHostSet(0)->hosts_ = {
      makeTestHost(cluster_->info_, "tcp://127.0.0.1:80", metadata, simTime())};
  cluster_->info_->stats().upstream_cx_total_.inc();
  expectSessionCreate();
  expectStreamCreate(0);
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _));
  EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, true))
      .WillRepeatedly(Invoke([&](const Http::RequestHeaderMap& headers, bool) -> Http::Status {
        EXPECT_EQ(headers.get(header_ok)[0]->value().getStringView(), value_ok);
        EXPECT_EQ(headers.get(header_cool)[0]->value().getStringView(), value_cool);
        EXPECT_EQ(headers.get(header_awesome)[0]->value().getStringView(), value_awesome);

        EXPECT_EQ(headers.getUserAgentValue(), value_user_agent);
        EXPECT_EQ(headers.get(upstream_metadata)[0]->value().getStringView(),
                  value_upstream_metadata);

        EXPECT_EQ(headers.get(protocol)[0]->value().getStringView(), value_protocol);
        EXPECT_EQ(headers.get(downstream_remote_address)[0]->value().getStringView(),
                  value_downstream_remote_address);
        EXPECT_EQ(headers.get(downstream_remote_address_without_port)[0]->value().getStringView(),
                  value_downstream_remote_address_without_port);
        EXPECT_EQ(headers.get(downstream_local_address)[0]->value().getStringView(),
                  value_downstream_local_address);
        EXPECT_EQ(headers.get(downstream_local_address_without_port)[0]->value().getStringView(),
                  value_downstream_local_address_without_port);

        Envoy::DateFormatter date_formatter("%s.%9f");
        std::string current_start_time =
            date_formatter.fromTime(dispatcher_.timeSource().systemTime());
        EXPECT_EQ(headers.get(start_time)[0]->value().getStringView(), current_start_time);
        return Http::okStatus();
      }));
  health_checker_->start();

  EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _));
  EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _))
      .WillOnce(Return(45000));
  EXPECT_CALL(*test_sessions_[0]->interval_timer_,
              enableTimer(std::chrono::milliseconds(45000), _));
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer());
  absl::optional<std::string> health_checked_cluster("locations-production-iad");
  respond(0, "200", false, false, true, false, health_checked_cluster);
  EXPECT_EQ(Host::Health::Healthy, cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->health());

  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _));
  expectStreamCreate(0);
  test_sessions_[0]->interval_timer_->invokeCallback();
}
TEST_F(HttpHealthCheckerImplTest, SuccessServiceCheckWithAdditionalHeaders) {
  const Http::LowerCaseString header_ok("x-envoy-ok");
  const Http::LowerCaseString header_cool("x-envoy-cool");
  const Http::LowerCaseString header_awesome("x-envoy-awesome");
  const Http::LowerCaseString upstream_metadata("x-upstream-metadata");
  const Http::LowerCaseString protocol("x-protocol");
  const Http::LowerCaseString downstream_remote_address("x-downstream-remote-address");
  const Http::LowerCaseString downstream_remote_address_without_port(
      "x-downstream-remote-address-without-port");
  const Http::LowerCaseString downstream_local_address("x-downstream-local-address");
  const Http::LowerCaseString downstream_local_address_without_port(
      "x-downstream-local-address-without-port");
  const Http::LowerCaseString start_time("x-start-time");

  const std::string value_ok = "ok";
  const std::string value_cool = "cool";
  const std::string value_awesome = "awesome";

  const std::string value_user_agent = "CoolEnvoy/HC";
  const std::string value_upstream_metadata = "value";
  const std::string value_protocol = "HTTP/1.1";
  const std::string value_downstream_remote_address = "127.0.0.1:0";
  const std::string value_downstream_remote_address_without_port = "127.0.0.1";
  const std::string value_downstream_local_address = "127.0.0.1:0";
  const std::string value_downstream_local_address_without_port = "127.0.0.1";

  setupServiceValidationWithAdditionalHeaders();
   
  EXPECT_CALL(runtime_.snapshot_, featureEnabled("health_check.verify_cluster", 100))
      .WillOnce(Return(true));

  EXPECT_CALL(*this, onHostStatus(_, HealthTransition::Unchanged));
  auto metadata = TestUtility::parseYaml<envoy::config::core::v3::Metadata>(
      R"EOF(
        filter_metadata:
          namespace:
            key: value
      )EOF");

  cluster_->prioritySet().getMockHostSet(0)->hosts_ = {
      makeTestHost(cluster_->info_, "tcp://127.0.0.1:80", metadata, simTime())};
  cluster_->info_->stats().upstream_cx_total_.inc();
  expectSessionCreate();
  expectStreamCreate(0);
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _));
  EXPECT_CALL(test_sessions_[0]->request_encoder_, encodeHeaders(_, true))
      .WillRepeatedly(Invoke([&](const Http::RequestHeaderMap& headers, bool) -> Http::Status {
        EXPECT_EQ(headers.get(header_ok)[0]->value().getStringView(), value_ok);
        EXPECT_EQ(headers.get(header_cool)[0]->value().getStringView(), value_cool);
        EXPECT_EQ(headers.get(header_awesome)[0]->value().getStringView(), value_awesome);

        EXPECT_EQ(headers.getUserAgentValue(), value_user_agent);
        EXPECT_EQ(headers.get(upstream_metadata)[0]->value().getStringView(),
                  value_upstream_metadata);

        EXPECT_EQ(headers.get(protocol)[0]->value().getStringView(), value_protocol);
        EXPECT_EQ(headers.get(downstream_remote_address)[0]->value().getStringView(),
                  value_downstream_remote_address);
        EXPECT_EQ(headers.get(downstream_remote_address_without_port)[0]->value().getStringView(),
                  value_downstream_remote_address_without_port);
        EXPECT_EQ(headers.get(downstream_local_address)[0]->value().getStringView(),
                  value_downstream_local_address);
        EXPECT_EQ(headers.get(downstream_local_address_without_port)[0]->value().getStringView(),
                  value_downstream_local_address_without_port);

        Envoy::DateFormatter date_formatter("%s.%9f");
        std::string current_start_time =
            date_formatter.fromTime(dispatcher_.timeSource().systemTime());
        EXPECT_EQ(headers.get(start_time)[0]->value().getStringView(), current_start_time);
        return Http::okStatus();
      }));
  health_checker_->start();

  EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.max_interval", _));
  EXPECT_CALL(runtime_.snapshot_, getInteger("health_check.min_interval", _))
      .WillOnce(Return(45000));
  EXPECT_CALL(*test_sessions_[0]->interval_timer_,
              enableTimer(std::chrono::milliseconds(45000), _));
  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, disableTimer());
  absl::optional<std::string> health_checked_cluster("locations-production-iad");
  respond(0, "200", false, false, true, false, health_checked_cluster);
  EXPECT_EQ(Host::Health::Healthy, cluster_->prioritySet().getMockHostSet(0)->hosts_[0]->health());

  EXPECT_CALL(*test_sessions_[0]->timeout_timer_, enableTimer(_, _));
  expectStreamCreate(0);
  test_sessions_[0]->interval_timer_->invokeCallback();
}