proxygen
proxygen::HTTPServerAcceptor Class Referencefinal

#include <HTTPServerAcceptor.h>

Inheritance diagram for proxygen::HTTPServerAcceptor:
proxygen::HTTPSessionAcceptor proxygen::HTTPAcceptor proxygen::HTTPSessionBase::InfoCallback wangle::Acceptor folly::AsyncServerSocket::AcceptCallback wangle::ConnectionManager::Callback folly::AsyncUDPServerSocket::Callback

Public Member Functions

void setCompletionCallback (std::function< void()> f)
 
 ~HTTPServerAcceptor () override
 
- Public Member Functions inherited from proxygen::HTTPSessionAcceptor
 HTTPSessionAcceptor (const AcceptorConfiguration &accConfig)
 
 HTTPSessionAcceptor (const AcceptorConfiguration &accConfig, std::shared_ptr< HTTPCodecFactory > codecFactory)
 
 ~HTTPSessionAcceptor () override
 
void setDefaultErrorPage (std::unique_ptr< HTTPErrorPage > generator)
 
const HTTPErrorPagegetDefaultErrorPage () const
 
void setDiagnosticErrorPage (std::unique_ptr< HTTPErrorPage > generator)
 
const HTTPErrorPagegetDiagnosticErrorPage () const
 
virtual const HTTPErrorPagegetErrorPage (const folly::SocketAddress &addr) const
 
void setCodecFactory (std::shared_ptr< HTTPCodecFactory > codecFactory)
 
std::shared_ptr< HTTPCodecFactorygetCodecFactory ()
 
void setSessionInfoCallback (HTTPSession::InfoCallback *cb)
 
virtual bool getHttp2PrioritiesEnabled ()
 
- Public Member Functions inherited from proxygen::HTTPAcceptor
 HTTPAcceptor (const AcceptorConfiguration &accConfig)
 
bool isInternal () const
 
virtual const WheelTimerInstancegetTransactionTimeoutSet ()
 
void init (folly::AsyncServerSocket *serverSocket, folly::EventBase *eventBase, wangle::SSLStats *=nullptr) override
 
const AcceptorConfigurationgetConfig () const
 
- Public Member Functions inherited from wangle::Acceptor
 Acceptor (const ServerSocketConfig &accConfig)
 
 ~Acceptor () override
 
virtual void setSSLCacheProvider (const std::shared_ptr< SSLCacheProvider > &cacheProvider)
 
virtual void resetSSLContextConfigs ()
 
void addSSLContextConfig (const SSLContextConfig &sslCtxConfig)
 
SSLContextManagergetSSLContextManager () const
 
virtual void setTLSTicketSecrets (const std::vector< std::string > &oldSecrets, const std::vector< std::string > &currentSecrets, const std::vector< std::string > &newSecrets)
 
uint32_t getNumConnections () const
 
virtual folly::EventBasegetEventBase () const
 
virtual wangle::ConnectionManagergetConnectionManager ()
 
void addConnection (wangle::ManagedConnection *connection)
 
State getState () const
 
std::chrono::milliseconds getConnTimeout () const
 
const std::stringgetName () const
 
std::chrono::milliseconds getSSLHandshakeTimeout () const
 
void setGracefulShutdownTimeout (std::chrono::milliseconds gracefulShutdown)
 
std::chrono::milliseconds getGracefulShutdownTimeout () const
 
virtual void forceStop ()
 
bool isSSL () const
 
const ServerSocketConfiggetConfig () const
 
virtual void onDoneAcceptingConnection (int fd, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime) noexcept
 
void processEstablishedConnection (int fd, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
 
virtual void startHandshakeManager (folly::AsyncSSLSocket::UniquePtr sslSock, Acceptor *acceptor, const folly::SocketAddress &clientAddr, std::chrono::steady_clock::time_point acceptTime, TransportInfo &tinfo) noexcept
 
void drainAllConnections ()
 
virtual void drainConnections (double pctToDrain)
 
void dropAllConnections ()
 
virtual void dropConnections (double pctToDrop)
 
virtual void plaintextConnectionReady (folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, TransportInfo &tinfo)
 
void connectionReady (folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocolName, SecureTransportType secureTransportType, TransportInfo &tinfo)
 
virtual void sslConnectionReady (folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress &clientAddr, const std::string &nextProtocol, SecureTransportType secureTransportType, TransportInfo &tinfo)
 
virtual void sslConnectionError (const folly::exception_wrapper &ex)
 
virtual void updateSSLStats (const folly::AsyncTransportWrapper *, std::chrono::milliseconds, SSLErrorEnum) noexcept
 
- Public Member Functions inherited from folly::AsyncServerSocket::AcceptCallback
virtual ~AcceptCallback ()=default
 
virtual void acceptStarted () noexcept
 
- Public Member Functions inherited from wangle::ConnectionManager::Callback
virtual ~Callback ()=default
 
- Public Member Functions inherited from folly::AsyncUDPServerSocket::Callback
virtual void onListenPaused () noexcept
 
virtual void onListenResumed () noexcept
 
virtual ~Callback ()=default
 

Static Public Member Functions

static AcceptorConfiguration makeConfig (const HTTPServer::IPConfig &ipConfig, const HTTPServerOptions &opts)
 
static std::unique_ptr< HTTPServerAcceptormake (const AcceptorConfiguration &conf, const HTTPServerOptions &opts, const std::shared_ptr< HTTPCodecFactory > &codecFactory=nullptr)
 
- Static Public Member Functions inherited from wangle::Acceptor
static uint64_t getTotalNumPendingSSLConns ()
 

Private Member Functions

 HTTPServerAcceptor (const AcceptorConfiguration &conf, const std::shared_ptr< HTTPCodecFactory > &codecFactory, std::vector< RequestHandlerFactory * > handlerFactories, const HTTPServerOptions &options)
 
HTTPTransaction::HandlernewHandler (HTTPTransaction &txn, HTTPMessage *msg) noexceptoverride
 
void onNewConnection (folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress *address, const std::string &nextProtocolName, wangle::SecureTransportType secureTransportType, const wangle::TransportInfo &tinfo) override
 
void onConnectionsDrained () override
 

Private Attributes

const HTTPServerOptionsserverOptions_
 
std::function< void()> completionCallback_
 
const std::vector< RequestHandlerFactory * > handlerFactories_ {nullptr}
 

Additional Inherited Members

- Public Types inherited from wangle::Acceptor
enum  State : uint32_t { State::kInit, State::kRunning, State::kDraining, State::kDone }
 
- Protected Member Functions inherited from proxygen::HTTPSessionAcceptor
virtual HTTPSessionControllergetController ()
 
HTTPSession::InfoCallbackgetSessionInfoCallback ()
 
void onNewConnection (folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress *address, const std::string &nextProtocol, wangle::SecureTransportType secureTransportType, const wangle::TransportInfo &tinfo) override
 
folly::AsyncSocket::UniquePtr makeNewAsyncSocket (folly::EventBase *base, int fd) override
 
virtual size_t dropIdleConnections (size_t num)
 
virtual void onSessionCreationError (ProxygenError)
 
- Protected Member Functions inherited from wangle::Acceptor
virtual uint64_t getConnectionCountForLoadShedding (void) const
 
virtual uint64_t getActiveConnectionCountForLoadShedding () const
 
virtual uint64_t getWorkerMaxConnections () const
 
virtual bool canAccept (const folly::SocketAddress &)
 
void onListenStarted () noexceptoverride
 
void onListenStopped () noexceptoverride
 
void onDataAvailable (std::shared_ptr< folly::AsyncUDPSocket >, const folly::SocketAddress &, std::unique_ptr< folly::IOBuf >, bool) noexceptoverride
 
virtual folly::AsyncSSLSocket::UniquePtr makeNewAsyncSSLSocket (const std::shared_ptr< folly::SSLContext > &ctx, folly::EventBase *base, int fd)
 
void connectionAccepted (int fd, const folly::SocketAddress &clientAddr) noexceptoverride
 
void acceptError (const std::exception &ex) noexceptoverride
 
void acceptStopped () noexceptoverride
 
void onEmpty (const wangle::ConnectionManager &cm) override
 
void onConnectionAdded (const ManagedConnection *) override
 
void onConnectionRemoved (const ManagedConnection *) override
 
void setLoadShedConfig (std::shared_ptr< const LoadShedConfiguration > loadShedConfig, const IConnectionCounter *counter)
 
virtual void initDownstreamConnectionManager (folly::EventBase *eventBase)
 
virtual DefaultToFizzPeekingCallbackgetFizzPeeker ()
 
virtual std::shared_ptr< fizz::server::FizzServerContextcreateFizzContext ()
 
virtual std::shared_ptr< fizz::server::TicketCiphercreateFizzTicketCipher (folly::Optional< std::string >=folly::none)
 
void updateFizzContext (fizz::server::FizzServerContext *)
 
- Protected Attributes inherited from proxygen::HTTPSessionAcceptor
HTTPSessionStatsdownstreamSessionStats_ {nullptr}
 
- Protected Attributes inherited from proxygen::HTTPAcceptor
AcceptorConfiguration accConfig_
 
- Protected Attributes inherited from wangle::Acceptor
folly::EventBasebase_ {nullptr}
 
const ServerSocketConfig accConfig_
 
folly::AsyncSocket::OptionMap socketOptions_
 
std::unique_ptr< SSLContextManagersslCtxManager_
 
SecurityProtocolContextManager securityProtocolCtxManager_
 
TLSPlaintextPeekingCallback tlsPlaintextPeekingCallback_
 
DefaultToSSLPeekingCallback defaultPeekingCallback_
 
DefaultToFizzPeekingCallback defaultFizzPeeker_
 
wangle::ConnectionManager::UniquePtr downstreamConnectionManager_
 
std::shared_ptr< SSLCacheProvidercacheProvider_
 
wangle::TLSTicketKeySeeds currentSecrets_
 

Detailed Description

Definition at line 18 of file HTTPServerAcceptor.h.

Constructor & Destructor Documentation

proxygen::HTTPServerAcceptor::~HTTPServerAcceptor ( )
override

Definition at line 95 of file HTTPServerAcceptor.cpp.

95  {
96 }
proxygen::HTTPServerAcceptor::HTTPServerAcceptor ( const AcceptorConfiguration conf,
const std::shared_ptr< HTTPCodecFactory > &  codecFactory,
std::vector< RequestHandlerFactory * >  handlerFactories,
const HTTPServerOptions options 
)
private

Definition at line 81 of file HTTPServerAcceptor.cpp.

Referenced by make().

86  : HTTPSessionAcceptor(conf, codecFactory),
87  serverOptions_(options),
88  handlerFactories_(handlerFactories) {
89 }
const HTTPServerOptions & serverOptions_
HTTPSessionAcceptor(const AcceptorConfiguration &accConfig)
const std::vector< RequestHandlerFactory * > handlerFactories_

Member Function Documentation

std::unique_ptr< HTTPServerAcceptor > proxygen::HTTPServerAcceptor::make ( const AcceptorConfiguration conf,
const HTTPServerOptions opts,
const std::shared_ptr< HTTPCodecFactory > &  codecFactory = nullptr 
)
static

Definition at line 65 of file HTTPServerAcceptor.cpp.

References f, proxygen::HTTPServerOptions::handlerFactories, and HTTPServerAcceptor().

Referenced by proxygen::AcceptorFactory::newAcceptor().

68  {
69  // Create a copy of the filter chain in reverse order since we need to create
70  // Handlers in that order.
71  std::vector<RequestHandlerFactory*> handlerFactories;
72  for (auto& f: opts.handlerFactories) {
73  handlerFactories.push_back(f.get());
74  }
75  std::reverse(handlerFactories.begin(), handlerFactories.end());
76 
77  return std::unique_ptr<HTTPServerAcceptor>(
78  new HTTPServerAcceptor(conf, codecFactory, handlerFactories, opts));
79 }
auto f
HTTPServerAcceptor(const AcceptorConfiguration &conf, const std::shared_ptr< HTTPCodecFactory > &codecFactory, std::vector< RequestHandlerFactory * > handlerFactories, const HTTPServerOptions &options)
AcceptorConfiguration proxygen::HTTPServerAcceptor::makeConfig ( const HTTPServer::IPConfig ipConfig,
const HTTPServerOptions opts 
)
static

Definition at line 23 of file HTTPServerAcceptor.cpp.

References wangle::ServerSocketConfig::acceptBacklog, proxygen::HTTPServer::IPConfig::acceptorSocketOptions, proxygen::HTTPServer::IPConfig::address, proxygen::AcceptorConfiguration::allowedPlaintextUpgradeProtocols, proxygen::HTTPServer::IPConfig::allowInsecureConnectionsOnSecureServer, wangle::ServerSocketConfig::allowInsecureConnectionsOnSecureServer, wangle::ServerSocketConfig::bindAddress, wangle::ServerSocketConfig::connectionIdleTimeout, proxygen::AcceptorConfiguration::egressSettings, proxygen::ENABLE_EX_HEADERS, proxygen::HTTPServerOptions::enableExHeaders, proxygen::HTTPServer::IPConfig::enableTCPFastOpen, wangle::ServerSocketConfig::enableTCPFastOpen, proxygen::HTTPServer::IPConfig::fastOpenQueueSize, wangle::ServerSocketConfig::fastOpenQueueSize, proxygen::HTTPServerOptions::h2cEnabled, folly::Optional< Value >::hasValue(), proxygen::HTTPServer::HTTP2, proxygen::HTTPServerOptions::idleTimeout, proxygen::AcceptorConfiguration::initialReceiveWindow, proxygen::HTTPServerOptions::initialReceiveWindow, wangle::ServerSocketConfig::initialTicketSeeds, proxygen::http2::kProtocolCleartextString, proxygen::HTTPServerOptions::listenBacklog, proxygen::AcceptorConfiguration::maxConcurrentIncomingStreams, proxygen::HTTPServerOptions::maxConcurrentIncomingStreams, proxygen::AcceptorConfiguration::plaintextProtocol, proxygen::HTTPServer::IPConfig::protocol, proxygen::AcceptorConfiguration::receiveSessionWindowSize, proxygen::HTTPServerOptions::receiveSessionWindowSize, proxygen::AcceptorConfiguration::receiveStreamWindowSize, proxygen::HTTPServerOptions::receiveStreamWindowSize, wangle::ServerSocketConfig::setSocketOptions(), proxygen::HTTPServer::SPDY, proxygen::HTTPServer::IPConfig::sslConfigs, wangle::ServerSocketConfig::sslContextConfigs, proxygen::HTTPServer::IPConfig::strictSSL, wangle::ServerSocketConfig::strictSSL, proxygen::HTTPServer::IPConfig::ticketSeeds, proxygen::AcceptorConfiguration::transactionIdleTimeout, and folly::Optional< Value >::value().

Referenced by proxygen::HTTPServer::start().

25  {
26 
27  AcceptorConfiguration conf;
28  conf.bindAddress = ipConfig.address;
29  conf.connectionIdleTimeout = opts.idleTimeout;
30  conf.transactionIdleTimeout = opts.idleTimeout;
31  conf.initialReceiveWindow = opts.initialReceiveWindow;
32  conf.receiveStreamWindowSize = opts.receiveStreamWindowSize;
33  conf.receiveSessionWindowSize = opts.receiveSessionWindowSize;
34  conf.acceptBacklog = opts.listenBacklog;
35  conf.maxConcurrentIncomingStreams = opts.maxConcurrentIncomingStreams;
36 
37  if (opts.enableExHeaders) {
38  conf.egressSettings.push_back(
39  HTTPSetting(SettingsId::ENABLE_EX_HEADERS, 1));
40  }
41 
42  if (ipConfig.protocol == HTTPServer::Protocol::SPDY) {
43  conf.plaintextProtocol = "spdy/3.1";
44  } else if (ipConfig.protocol == HTTPServer::Protocol::HTTP2) {
45  conf.plaintextProtocol = http2::kProtocolCleartextString;
46  } else if (opts.h2cEnabled) {
47  conf.allowedPlaintextUpgradeProtocols = { http2::kProtocolCleartextString };
48  }
49 
50  conf.sslContextConfigs = ipConfig.sslConfigs;
51  conf.strictSSL = ipConfig.strictSSL;
52  conf.allowInsecureConnectionsOnSecureServer =
53  ipConfig.allowInsecureConnectionsOnSecureServer;
54  conf.enableTCPFastOpen = ipConfig.enableTCPFastOpen;
55  conf.fastOpenQueueSize = ipConfig.fastOpenQueueSize;
56  if (ipConfig.ticketSeeds) {
57  conf.initialTicketSeeds = *ipConfig.ticketSeeds;
58  }
59  if (ipConfig.acceptorSocketOptions.hasValue()) {
60  conf.setSocketOptions(ipConfig.acceptorSocketOptions.value());
61  }
62  return conf;
63 }
const std::string kProtocolCleartextString
HTTPTransactionHandler * proxygen::HTTPServerAcceptor::newHandler ( HTTPTransaction txn,
HTTPMessage msg 
)
overrideprivatevirtualnoexcept

Create a Handler for a new transaction. The transaction and HTTP message (request) are passed so the implementation can construct different handlers based on these. The transaction will be explicitly set on the handler later via setTransaction. The request message will be passed in onHeadersComplete.

Implements proxygen::HTTPSessionAcceptor.

Definition at line 98 of file HTTPServerAcceptor.cpp.

References h, handlerFactories_, and proxygen::RequestHandler::onRequest().

100  {
101 
102  SocketAddress clientAddr, vipAddr;
103  txn.getPeerAddress(clientAddr);
104  txn.getLocalAddress(vipAddr);
105  msg->setClientAddress(clientAddr);
106  msg->setDstAddress(vipAddr);
107 
108  // Create filters chain
109  RequestHandler* h = nullptr;
110  for (auto& factory: handlerFactories_) {
111  h = factory->onRequest(h, msg);
112  }
113 
114  return new RequestHandlerAdaptor(h);
115 }
*than *hazptr_holder h
Definition: Hazptr.h:116
const std::vector< RequestHandlerFactory * > handlerFactories_
void proxygen::HTTPServerAcceptor::onConnectionsDrained ( )
overrideprivatevirtual

onConnectionsDrained() will be called once all connections have been drained while the acceptor is stopping.

Subclasses can override this method to perform any subclass-specific cleanup.

Reimplemented from wangle::Acceptor.

Definition at line 137 of file HTTPServerAcceptor.cpp.

References completionCallback_.

137  {
138  if (completionCallback_) {
140  }
141 }
std::function< void()> completionCallback_
void proxygen::HTTPServerAcceptor::onNewConnection ( folly::AsyncTransportWrapper::UniquePtr  ,
const folly::SocketAddress ,
const std::string ,
wangle::SecureTransportType  ,
const wangle::TransportInfo  
)
overrideprivatevirtual

Invoked when a new connection is created. This is where application starts processing a new downstream connection.

NOTE: Application should add the new connection to downstreamConnectionManager so that it can be garbage collected after certain period of idleness.

Parameters
sockthe socket connected to the client
addressthe address of the client
nextProtocolNamethe name of the L6 or L7 protocol to be spoken on the connection, if known (e.g., from TLS NPN during secure connection setup), or an empty string if unknown
secureTransportTypethe name of the secure transport type that was requested by the client.

Reimplemented from wangle::Acceptor.

Definition at line 117 of file HTTPServerAcceptor.cpp.

References folly::exceptionStr(), folly::pushmi::operators::filter, folly::gen::move, proxygen::HTTPServerOptions::newConnectionFilter, proxygen::HTTPSessionAcceptor::onNewConnection(), and serverOptions_.

122  {
124  if (filter) {
125  try {
126  filter(sock.get(), address, nextProtocolName, secureTransportType, tinfo);
127  } catch (const std::exception& e) {
128  sock->closeWithReset();
129  LOG(INFO) << "Exception filtering new socket: " << folly::exceptionStr(e);
130  return;
131  }
132  }
134  std::move(sock), address, nextProtocolName, secureTransportType, tinfo);
135 }
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
const HTTPServerOptions & serverOptions_
fbstring exceptionStr(const std::exception &e)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
NewConnectionFilter newConnectionFilter
void onNewConnection(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress *address, const std::string &nextProtocol, wangle::SecureTransportType secureTransportType, const wangle::TransportInfo &tinfo) override
void proxygen::HTTPServerAcceptor::setCompletionCallback ( std::function< void()>  f)

Invokes the given method when all the connections are drained

Definition at line 91 of file HTTPServerAcceptor.cpp.

References completionCallback_, and f.

91  {
93 }
auto f
std::function< void()> completionCallback_

Member Data Documentation

std::function<void()> proxygen::HTTPServerAcceptor::completionCallback_
private

Definition at line 55 of file HTTPServerAcceptor.h.

Referenced by onConnectionsDrained(), and setCompletionCallback().

const std::vector<RequestHandlerFactory*> proxygen::HTTPServerAcceptor::handlerFactories_ {nullptr}
private

Definition at line 56 of file HTTPServerAcceptor.h.

Referenced by newHandler().

const HTTPServerOptions& proxygen::HTTPServerAcceptor::serverOptions_
private

Definition at line 54 of file HTTPServerAcceptor.h.

Referenced by onNewConnection().


The documentation for this class was generated from the following files: