proxygen
DefaultHTTPCodecFactory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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  bool forceHTTP1xCodecTo1_1)
21  : forceHTTP1xCodecTo1_1_(forceHTTP1xCodecTo1_1) {
22 }
23 
24 std::unique_ptr<HTTPCodec> DefaultHTTPCodecFactory::getCodec(
25  const std::string& chosenProto,
26  TransportDirection direction,
27  bool /* isTLS */) {
28 
29  auto spdyVersion = SPDYCodec::getVersion(chosenProto);
30  if (spdyVersion) {
31  return std::make_unique<SPDYCodec>(direction,
32  *spdyVersion);
33  } else if (chosenProto == proxygen::http2::kProtocolString ||
37  return std::make_unique<HTTP2Codec>(direction);
38  } else {
39  if (!chosenProto.empty() &&
40  !HTTP1xCodec::supportsNextProtocol(chosenProto)) {
41  LOG(ERROR) << "Chosen upstream protocol " <<
42  "\"" << chosenProto << "\" is unimplemented. " <<
43  "Attempting to use HTTP/1.1";
44  }
45 
46  return std::make_unique<HTTP1xCodec>(direction,
48  }
49 }
50 }
uint8_t getVersion() const
Definition: SPDYCodec.cpp:1023
const std::string kProtocolCleartextString
const std::string kProtocolString
static bool supportsNextProtocol(const std::string &npn)
const std::string kProtocolDraftString
const std::string kProtocolExperimentalString
const char * string
Definition: Conv.cpp:212
std::unique_ptr< HTTPCodec > getCodec(const std::string &nextProtocol, TransportDirection direction, bool isTLS) override
DefaultHTTPCodecFactory(bool forceHTTP1xCodecTo1_1)