TEST(HTTPDefaultSessionCodecFactoryTest, GetCodec) {
  AcceptorConfiguration conf;
  HTTPDefaultSessionCodecFactory factory(conf);

  // Empty protocol should default to http/1.1
  auto codec =
      factory.getCodec("", TransportDirection::DOWNSTREAM, false /* isTLS */);
  HTTP1xCodec* http1Codec = dynamic_cast<HTTP1xCodec*>(codec.get());
  EXPECT_NE(http1Codec, nullptr);
  EXPECT_EQ(http1Codec->getProtocol(), CodecProtocol::HTTP_1_1);

  codec = factory.getCodec(
      "spdy/3.1", TransportDirection::UPSTREAM, false /* isTLS */);
  SPDYCodec* spdyCodec = dynamic_cast<SPDYCodec*>(codec.get());
  EXPECT_NE(spdyCodec, nullptr);
  EXPECT_EQ(spdyCodec->getProtocol(), CodecProtocol::SPDY_3_1);

  codec =
      factory.getCodec("h2", TransportDirection::DOWNSTREAM, false /* isTLS */);
  HTTP2Codec* httpCodec = dynamic_cast<HTTP2Codec*>(codec.get());
  EXPECT_NE(httpCodec, nullptr);
  EXPECT_EQ(httpCodec->getProtocol(), CodecProtocol::HTTP_2);

  // Not supported protocols should return nullptr.
  codec = factory.getCodec(
      "not/supported", TransportDirection::DOWNSTREAM, false /* isTLS */);
  EXPECT_EQ(codec, nullptr);
}
TEST(HTTPDefaultSessionCodecFactoryTest, GetCodecH2) {
  AcceptorConfiguration conf;
  // If set directly on the acceptor, we should always return the H2C version.
  conf.plaintextProtocol = "h2c";
  HTTPDefaultSessionCodecFactory factory(conf);
  auto codec = factory.getCodec(
      "http/1.1", TransportDirection::DOWNSTREAM, false /* isTLS */);
  HTTP2Codec* httpCodec = dynamic_cast<HTTP2Codec*>(codec.get());
  EXPECT_NE(httpCodec, nullptr);
  EXPECT_EQ(httpCodec->getProtocol(), CodecProtocol::HTTP_2);

  // On a somewhat contrived example, if TLS we should return the version
  // negotiated through ALPN.
  codec = factory.getCodec(
      "http/1.1", TransportDirection::UPSTREAM, true /* isTLS */);
  HTTP1xCodec* http1Codec = dynamic_cast<HTTP1xCodec*>(codec.get());
  EXPECT_NE(http1Codec, nullptr);
  EXPECT_EQ(http1Codec->getProtocol(), CodecProtocol::HTTP_1_1);
}