void HttpConnectionManagerImplTest::setUpEncoderAndDecoder(bool request_with_data_and_trailers,
                                                           bool decode_headers_stop_all) {
  setUpBufferLimits();
  EXPECT_CALL(*codec_, dispatch(_))
      .WillOnce(Invoke([&, request_with_data_and_trailers](Buffer::Instance&) -> Http::Status {
        RequestDecoder* decoder = &conn_manager_->newStream(response_encoder_);
        RequestHeaderMapPtr headers{new TestRequestHeaderMapImpl{
            {":authority", "host"}, {":path", "/"}, {":method", "GET"}}};
        if (request_with_data_and_trailers) {
          decoder->decodeHeaders(std::move(headers), false);

          Buffer::OwnedImpl fake_data("12345");
          decoder->decodeData(fake_data, false);

          RequestTrailerMapPtr trailers{new TestRequestTrailerMapImpl{{"foo", "bar"}}};
          decoder->decodeTrailers(std::move(trailers));
        } else {
          decoder->decodeHeaders(std::move(headers), true);
        }
        return Http::okStatus();
      }));

  setupFilterChain(2, 2);

  EXPECT_CALL(*decoder_filters_[0], decodeHeaders(_, _))
      .WillOnce(InvokeWithoutArgs([&, decode_headers_stop_all]() -> FilterHeadersStatus {
        Buffer::OwnedImpl data("hello");
        decoder_filters_[0]->callbacks_->addDecodedData(data, true);
        if (decode_headers_stop_all) {
          return FilterHeadersStatus::StopAllIterationAndBuffer;
        } else {
          return FilterHeadersStatus::Continue;
        }
      }));
  EXPECT_CALL(*decoder_filters_[0], decodeComplete());
}
void HttpConnectionManagerImplTest::setUpEncoderAndDecoder(bool request_with_data_and_trailers,
                                                           bool decode_headers_stop_all) {
  setUpBufferLimits();
  EXPECT_CALL(*codec_, dispatch(_))
      .WillOnce(Invoke([&, request_with_data_and_trailers](Buffer::Instance&) -> Http::Status {
        RequestDecoder* decoder = &conn_manager_->newStream(response_encoder_);
        RequestHeaderMapPtr headers{new TestRequestHeaderMapImpl{
            {":authority", "host"}, {":path", "/"}, {":method", "GET"}}};
        if (request_with_data_and_trailers) {
          decoder->decodeHeaders(std::move(headers), false);

          Buffer::OwnedImpl fake_data("12345");
          decoder->decodeData(fake_data, false);

          RequestTrailerMapPtr trailers{new TestRequestTrailerMapImpl{{"foo", "bar"}}};
          decoder->decodeTrailers(std::move(trailers));
        } else {
          decoder->decodeHeaders(std::move(headers), true);
        }
        return Http::okStatus();
      }));

  setupFilterChain(2, 2);

  EXPECT_CALL(*decoder_filters_[0], decodeHeaders(_, _))
      .WillOnce(InvokeWithoutArgs([&, decode_headers_stop_all]() -> FilterHeadersStatus {
        Buffer::OwnedImpl data("hello");
        decoder_filters_[0]->callbacks_->addDecodedData(data, true);
        if (decode_headers_stop_all) {
          return FilterHeadersStatus::StopAllIterationAndBuffer;
        } else {
          return FilterHeadersStatus::Continue;
        }
      }));
  EXPECT_CALL(*decoder_filters_[0], decodeComplete());
}