TEST_F(RouterTest, Coalesce1xxHeaders) {
  // Setup.
  NiceMock<Http::MockRequestEncoder> encoder1;
  Http::ResponseDecoder* response_decoder = nullptr;
  EXPECT_CALL(cm_.thread_local_cluster_.conn_pool_, newStream(_, _))
      .WillOnce(Invoke(
          [&](Http::ResponseDecoder& decoder,
              Http::ConnectionPool::Callbacks& callbacks) -> Http::ConnectionPool::Cancellable* {
            response_decoder = &decoder;
            callbacks.onPoolReady(encoder1, cm_.thread_local_cluster_.conn_pool_.host_,
                                  upstream_stream_info_, Http::Protocol::Http10);
            return nullptr;
          }));
  expectResponseTimerCreate();

  Http::TestRequestHeaderMapImpl headers;
  HttpTestUtility::addDefaultHeaders(headers);
  router_.decodeHeaders(headers, true);
  EXPECT_EQ(1U,
            callbacks_.route_->route_entry_.virtual_cluster_.stats().upstream_rq_total_.value());

  // Initial 100-continue, this is processed normally.
  EXPECT_CALL(callbacks_, encode1xxHeaders_(_));
  {
    Http::ResponseHeaderMapPtr continue_headers(
        new Http::TestResponseHeaderMapImpl{{":status", "100"}});
    // NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage)
    response_decoder->decode1xxHeaders(std::move(continue_headers));
  }
  EXPECT_EQ(
      1U,
      cm_.thread_local_cluster_.cluster_.info_->stats_store_.counter("upstream_rq_100").value());

  // No encode1xxHeaders() invocation for the second 100-continue (but we continue to track
  // stats from upstream).
  EXPECT_CALL(callbacks_, encode1xxHeaders_(_)).Times(0);
  {
    Http::ResponseHeaderMapPtr continue_headers(
        new Http::TestResponseHeaderMapImpl{{":status", "100"}});
    // NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage)
    response_decoder->decode1xxHeaders(std::move(continue_headers));
  }
  EXPECT_EQ(
      2U,
      cm_.thread_local_cluster_.cluster_.info_->stats_store_.counter("upstream_rq_100").value());

  // Reset stream and cleanup.
  EXPECT_CALL(cm_.thread_local_cluster_.conn_pool_.host_->outlier_detector_,
              putResult(Upstream::Outlier::Result::LocalOriginConnectFailed, _));
  encoder1.stream_.resetStream(Http::StreamResetReason::RemoteReset);
  EXPECT_EQ(1U,
            callbacks_.route_->route_entry_.virtual_cluster_.stats().upstream_rq_total_.value());
}
TEST_F(RouterTest, Coalesce1xxHeaders) {
   
  NiceMock<Http::MockRequestEncoder> encoder1;
  Http::ResponseDecoder* response_decoder = nullptr;
  EXPECT_CALL(cm_.thread_local_cluster_.conn_pool_, newStream(_, _))
      .WillOnce(Invoke(
          [&](Http::ResponseDecoder& decoder,
              Http::ConnectionPool::Callbacks& callbacks) -> Http::ConnectionPool::Cancellable* {
            response_decoder = &decoder;
            callbacks.onPoolReady(encoder1, cm_.thread_local_cluster_.conn_pool_.host_,
                                  upstream_stream_info_, Http::Protocol::Http10);
            return nullptr;
          }));
  expectResponseTimerCreate();

  Http::TestRequestHeaderMapImpl headers;
  HttpTestUtility::addDefaultHeaders(headers);
  router_.decodeHeaders(headers, true);
  EXPECT_EQ(1U,
            callbacks_.route_->route_entry_.virtual_cluster_.stats().upstream_rq_total_.value());

   
  EXPECT_CALL(callbacks_, encode1xxHeaders_(_));
  {
    Http::ResponseHeaderMapPtr continue_headers(
        new Http::TestResponseHeaderMapImpl{{":status", "100"}});
     
    response_decoder->decode1xxHeaders(std::move(continue_headers));
  }
  EXPECT_EQ(
      1U,
      cm_.thread_local_cluster_.cluster_.info_->stats_store_.counter("upstream_rq_100").value());

   
   
  EXPECT_CALL(callbacks_, encode1xxHeaders_(_)).Times(0);
  {
    Http::ResponseHeaderMapPtr continue_headers(
        new Http::TestResponseHeaderMapImpl{{":status", "100"}});
     
    response_decoder->decode1xxHeaders(std::move(continue_headers));
  }
  EXPECT_EQ(
      2U,
      cm_.thread_local_cluster_.cluster_.info_->stats_store_.counter("upstream_rq_100").value());

   
  EXPECT_CALL(cm_.thread_local_cluster_.conn_pool_.host_->outlier_detector_,
              putResult(Upstream::Outlier::Result::LocalOriginConnectFailed, _));
  encoder1.stream_.resetStream(Http::StreamResetReason::RemoteReset);
  EXPECT_EQ(1U,
            callbacks_.route_->route_entry_.virtual_cluster_.stats().upstream_rq_total_.value());
}