proxygen
HTTPSessionAcceptor.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  */
15 
16 using folly::AsyncSocket;
18 using std::list;
19 using std::string;
20 using std::unique_ptr;
21 
22 namespace proxygen {
23 
25 
27  : HTTPSessionAcceptor(accConfig, nullptr) {}
28 
30  const AcceptorConfiguration& accConfig,
31  std::shared_ptr<HTTPCodecFactory> codecFactory):
32  HTTPAcceptor(accConfig),
33  codecFactory_(codecFactory),
34  simpleController_(this) {
35  if (!codecFactory_) {
37  std::make_shared<HTTPDefaultSessionCodecFactory>(accConfig_);
38  }
39 }
40 
42 }
43 
45  const SocketAddress& addr) const {
46  const HTTPErrorPage* errorPage = nullptr;
47  if (isInternal()) {
48  if (addr.isPrivateAddress()) {
49  errorPage = diagnosticErrorPage_.get();
50  }
51  }
52  if (errorPage == nullptr) {
53  errorPage = defaultErrorPage_.get();
54  }
55  return errorPage;
56 }
57 
60  const SocketAddress* peerAddress,
61  const string& nextProtocol,
63  const wangle::TransportInfo& tinfo) {
64 
65  unique_ptr<HTTPCodec> codec
66  = codecFactory_->getCodec(
67  nextProtocol,
69  // we assume if security protocol isn't empty, then it's TLS
70  !sock->getSecurityProtocol().empty());
71 
72  if (!codec) {
73  VLOG(2) << "codecFactory_ failed to provide codec";
75  return;
76  }
77 
78  auto controller = getController();
79  SocketAddress localAddress;
80  try {
81  sock->getLocalAddress(&localAddress);
82  } catch (...) {
83  VLOG(3) << "couldn't get local address for socket";
84  localAddress = unknownSocketAddress_;
85  }
86 
87  // overwrite address if the socket has no IP, e.g. Unix domain socket
88  if (!localAddress.isFamilyInet()) {
90  localAddress = accConfig_.bindAddress;
91  } else {
92  localAddress = unknownSocketAddress_;
93  }
94  VLOG(4) << "set localAddress=" << localAddress.describe();
95  }
96 
97  auto sessionInfoCb = sessionInfoCb_ ? sessionInfoCb_ : this;
98  VLOG(4) << "Created new " << nextProtocol
99  << " session for peer " << *peerAddress;
100  HTTPDownstreamSession* session =
102  localAddress, *peerAddress,
103  controller, std::move(codec), tinfo,
104  sessionInfoCb);
108  }
110 
111  // set HTTP2 priorities flag on session object
112  auto HTTP2PrioritiesEnabled = getHttp2PrioritiesEnabled();
113  session->setHTTP2PrioritiesEnabled(HTTP2PrioritiesEnabled);
114 
115  // set flow control parameters
119  if (accConfig_.writeBufferLimit > 0) {
121  }
123  Acceptor::addConnection(session);
124  session->startNow();
125 }
126 
128  // release in batch for more efficiency
129  VLOG(6) << "attempt to release resource";
130  return downstreamConnectionManager_->dropIdleConnections(num);
131 }
132 
133 } // proxygen
AcceptorConfiguration accConfig_
Definition: HTTPAcceptor.h:52
void setWriteBufferLimit(uint32_t limit)
void setSessionStats(HTTPSessionStats *stats) override
virtual void onSessionCreationError(ProxygenError)
virtual const WheelTimerInstance & getTransactionTimeoutSet()
Definition: HTTPAcceptor.h:37
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CodecFactory codec
void setMaxConcurrentIncomingStreams(uint32_t num) override
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
Definition: Acceptor.h:438
std::string describe() const
#define nullptr
Definition: http_parser.c:41
HTTPSessionAcceptor(const AcceptorConfiguration &accConfig)
virtual size_t dropIdleConnections(size_t num)
void onNewConnection(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress *address, const std::string &nextProtocol, wangle::SecureTransportType secureTransportType, const wangle::TransportInfo &tinfo) override
bool isFamilyInet() const
folly::SocketAddress bindAddress
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
void setFlowControl(size_t initialReceiveWindow, size_t receiveStreamWindowSize, size_t receiveSessionWindowSize) override
Encoder::MutableCompressedList list
void setEgressSettings(const SettingsList &inSettings) override
virtual const HTTPErrorPage * getErrorPage(const folly::SocketAddress &addr) const
HTTPSessionStats * downstreamSessionStats_
std::unique_ptr< HTTPErrorPage > diagnosticErrorPage_
virtual HTTPSessionController * getController()
void setHTTP2PrioritiesEnabled(bool enabled) override
Definition: HTTPSession.h:118
const char * string
Definition: Conv.cpp:212
bool isPrivateAddress() const
bool isInternal() const
Definition: HTTPAcceptor.h:30
HTTPSession::InfoCallback * sessionInfoCb_
std::unique_ptr< HTTPErrorPage > defaultErrorPage_
static const folly::SocketAddress unknownSocketAddress_
ThreadPoolListHook * addr
std::shared_ptr< HTTPCodecFactory > codecFactory_