proxygen
HTTPDefaultSessionCodecFactory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
11 
16 
17 namespace proxygen {
18 
20  const AcceptorConfiguration& accConfig)
21  : accConfig_(accConfig) {
22  // set up codec defaults in the case of plaintext connections
24  if (version) {
26  } else if (accConfig.plaintextProtocol == http2::kProtocolCleartextString) {
27  alwaysUseHTTP2_ = true;
28  }
29 }
30 
31 std::unique_ptr<HTTPCodec> HTTPDefaultSessionCodecFactory::getCodec(
32  const std::string& nextProtocol, TransportDirection direction, bool isTLS) {
33  if (!isTLS && alwaysUseSPDYVersion_) {
34  return std::make_unique<SPDYCodec>(direction,
37  } else if (!isTLS && alwaysUseHTTP2_) {
38  return std::make_unique<HTTP2Codec>(direction);
39  } else if (nextProtocol.empty() ||
40  HTTP1xCodec::supportsNextProtocol(nextProtocol)) {
41  auto codec = std::make_unique<HTTP1xCodec>(direction);
42  if (!isTLS) {
43  codec->setAllowedUpgradeProtocols(
45  }
46  return std::move(codec);
47  } else if (auto version = SPDYCodec::getVersion(nextProtocol)) {
48  return std::make_unique<SPDYCodec>(direction, *version,
50  } else if (nextProtocol == http2::kProtocolString ||
51  nextProtocol == http2::kProtocolDraftString ||
52  nextProtocol == http2::kProtocolExperimentalString) {
53  return std::make_unique<HTTP2Codec>(direction);
54  } else {
55  VLOG(2) << "Client requested unrecognized next protocol " << nextProtocol;
56  }
57 
58  return nullptr;
59 }
60 }
uint8_t getVersion() const
Definition: SPDYCodec.cpp:1023
const std::string kProtocolCleartextString
const std::string kProtocolString
static bool supportsNextProtocol(const std::string &npn)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CodecFactory codec
std::list< std::string > allowedPlaintextUpgradeProtocols
const std::string kProtocolDraftString
const std::string kProtocolExperimentalString
ProtocolVersion version
const char * string
Definition: Conv.cpp:212
std::unique_ptr< HTTPCodec > getCodec(const std::string &nextProtocol, TransportDirection direction, bool isTLS) override
FOLLY_CPP14_CONSTEXPR const Value & value() const &
Definition: Optional.h:268
HTTPDefaultSessionCodecFactory(const AcceptorConfiguration &accConfig)