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);
}
Example #2
0
 /*
  * hackIngress is used to keep the codec's strict checks while having
  * separate checks for tests
  */
 bool parseImpl(HTTP2Codec& codec, std::function<void(IOBuf*)> hackIngress) {
   dumpToFile(codec.getTransportDirection() == TransportDirection::UPSTREAM);
   auto ingress = output_.move();
   if (hackIngress) {
     hackIngress(ingress.get());
   }
   size_t parsed = codec.onIngress(*ingress);
   return (parsed == ingress->computeChainDataLength());
 }
Example #3
0
 bool parseImpl(HTTP2Codec& codec, std::function<void(IOBuf*)> hackIngress) {
   auto ingress = output_.move();
   if (hackIngress) {
     hackIngress(ingress.get());
   }
   size_t parsed = codec.onIngress(*ingress);
   return (parsed == ingress->computeChainDataLength());
 }
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);
}
Example #5
0
void HTTP2CodecTest::testBigHeader(bool continuation) {
  if (continuation) {
    HTTP2Codec::setHeaderSplitSize(1);
  }
  auto settings = downstreamCodec_.getEgressSettings();
  settings->setSetting(SettingsId::MAX_HEADER_LIST_SIZE, 37);
  IOBufQueue dummy;
  downstreamCodec_.generateSettings(dummy);
  HTTPMessage req = getGetRequest("/guacamole");
  req.getHeaders().add("user-agent", "coolio");
  req.getHeaders().add("x-long-long-header",
                       "supercalafragalisticexpialadoshus");
  upstreamCodec_.generateHeader(output_, 1, req, 0, true /* eom */);

  parse();
  // session error
  EXPECT_EQ(callbacks_.messageBegin, continuation ? 1 : 0);
  EXPECT_EQ(callbacks_.headersComplete, 0);
  EXPECT_EQ(callbacks_.messageComplete, 0);
  EXPECT_EQ(callbacks_.streamErrors, 0);
  EXPECT_EQ(callbacks_.sessionErrors, 1);
}