TEST_F(HttpConnectionManagerImplTest, RequestHeaderTimeoutDisarmedAfterHeaders) {
  request_headers_timeout_ = std::chrono::milliseconds(10);
  setup(false, "");

  Event::MockTimer* request_header_timer;
  EXPECT_CALL(*codec_, dispatch(_))
      .WillOnce(Invoke([&](Buffer::Instance&) -> Http::Status {
        request_header_timer = setUpTimer();
        EXPECT_CALL(*request_header_timer, enableTimer(request_headers_timeout_, _));

        decoder_ = &conn_manager_->newStream(response_encoder_);
        return Http::okStatus();
      }))
      .WillOnce(Return(Http::okStatus()))
      .WillOnce([&](Buffer::Instance&) {
        RequestHeaderMapPtr headers{new TestRequestHeaderMapImpl{
            {":authority", "localhost:8080"}, {":path", "/"}, {":method", "GET"}}};

        EXPECT_CALL(*request_header_timer, disableTimer);
        decoder_->decodeHeaders(std::move(headers), false);
        return Http::okStatus();
      });

  Buffer::OwnedImpl first_line("GET /HTTP/1.1\r\n");
  Buffer::OwnedImpl second_line("Host: localhost:8080\r\n");
  Buffer::OwnedImpl empty_line("\r\n");
  conn_manager_->onData(first_line, false);
  EXPECT_TRUE(request_header_timer->enabled_);
  conn_manager_->onData(second_line, false);
  EXPECT_TRUE(request_header_timer->enabled_);
  conn_manager_->onData(empty_line, false);
  Mock::VerifyAndClearExpectations(codec_);
  Mock::VerifyAndClearExpectations(request_header_timer);

  expectOnDestroy();
  filter_callbacks_.connection_.raiseEvent(Network::ConnectionEvent::RemoteClose);
}
TEST_F(HttpConnectionManagerImplTest, RequestHeaderTimeoutDisarmedAfterHeaders) {
  request_headers_timeout_ = std::chrono::milliseconds(10);
  setup(false, "");

  Event::MockTimer* request_header_timer;
  EXPECT_CALL(*codec_, dispatch(_))
      .WillOnce(Invoke([&](Buffer::Instance&) -> Http::Status {
        request_header_timer = setUpTimer();
        EXPECT_CALL(*request_header_timer, enableTimer(request_headers_timeout_, _));

        decoder_ = &conn_manager_->newStream(response_encoder_);
        return Http::okStatus();
      }))
      .WillOnce(Return(Http::okStatus()))
      .WillOnce([&](Buffer::Instance&) {
        RequestHeaderMapPtr headers{new TestRequestHeaderMapImpl{
            {":authority", "localhost:8080"}, {":path", "/"}, {":method", "GET"}}};

        EXPECT_CALL(*request_header_timer, disableTimer);
        decoder_->decodeHeaders(std::move(headers), false);
        return Http::okStatus();
      });

  Buffer::OwnedImpl first_line("GET /HTTP/1.1\r\n");
  Buffer::OwnedImpl second_line("Host: localhost:8080\r\n");
  Buffer::OwnedImpl empty_line("\r\n");
  conn_manager_->onData(first_line, false);
  EXPECT_TRUE(request_header_timer->enabled_);
  conn_manager_->onData(second_line, false);
  EXPECT_TRUE(request_header_timer->enabled_);
  conn_manager_->onData(empty_line, false);
  Mock::VerifyAndClearExpectations(codec_);
  Mock::VerifyAndClearExpectations(request_header_timer);

  expectOnDestroy();
  filter_callbacks_.connection_.raiseEvent(Network::ConnectionEvent::RemoteClose);
}