proxygen
HTTPServerAcceptor.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 
12 #include <folly/ExceptionString.h>
18 
20 
21 namespace proxygen {
22 
24  const HTTPServer::IPConfig& ipConfig,
25  const HTTPServerOptions& opts) {
26 
28  conf.bindAddress = ipConfig.address;
34  conf.acceptBacklog = opts.listenBacklog;
36 
37  if (opts.enableExHeaders) {
38  conf.egressSettings.push_back(
40  }
41 
42  if (ipConfig.protocol == HTTPServer::Protocol::SPDY) {
43  conf.plaintextProtocol = "spdy/3.1";
44  } else if (ipConfig.protocol == HTTPServer::Protocol::HTTP2) {
46  } else if (opts.h2cEnabled) {
48  }
49 
50  conf.sslContextConfigs = ipConfig.sslConfigs;
51  conf.strictSSL = ipConfig.strictSSL;
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()) {
61  }
62  return conf;
63 }
64 
65 std::unique_ptr<HTTPServerAcceptor> HTTPServerAcceptor::make(
66  const AcceptorConfiguration& conf,
67  const HTTPServerOptions& opts,
68  const std::shared_ptr<HTTPCodecFactory>& codecFactory) {
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 }
80 
82  const AcceptorConfiguration& conf,
83  const std::shared_ptr<HTTPCodecFactory>& codecFactory,
84  std::vector<RequestHandlerFactory*> handlerFactories,
85  const HTTPServerOptions& options)
86  : HTTPSessionAcceptor(conf, codecFactory),
87  serverOptions_(options),
88  handlerFactories_(handlerFactories) {
89 }
90 
91 void HTTPServerAcceptor::setCompletionCallback(std::function<void()> f) {
93 }
94 
96 }
97 
99  HTTPTransaction& txn,
100  HTTPMessage* msg) noexcept {
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 }
116 
119  const SocketAddress* address,
120  const std::string& nextProtocolName,
121  SecureTransportType secureTransportType,
122  const wangle::TransportInfo& tinfo) {
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 }
136 
138  if (completionCallback_) {
140  }
141 }
142 
143 }
HTTPTransaction::Handler * newHandler(HTTPTransaction &txn, HTTPMessage *msg) noexceptoverride
folly::Optional< folly::AsyncSocket::OptionMap > acceptorSocketOptions
Definition: HTTPServer.h:79
*than *hazptr_holder h
Definition: Hazptr.h:116
std::chrono::milliseconds transactionIdleTimeout
static AcceptorConfiguration makeConfig(const HTTPServer::IPConfig &ipConfig, const HTTPServerOptions &opts)
auto f
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
std::chrono::milliseconds connectionIdleTimeout
const std::string kProtocolCleartextString
std::chrono::milliseconds idleTimeout
const HTTPServerOptions & serverOptions_
fbstring exceptionStr(const std::exception &e)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::function< void()> completionCallback_
NewConnectionFilter newConnectionFilter
folly::SocketAddress address
Definition: HTTPServer.h:48
requires E e noexcept(noexcept(s.error(std::move(e))))
std::list< std::string > allowedPlaintextUpgradeProtocols
void onNewConnection(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress *address, const std::string &nextProtocol, wangle::SecureTransportType secureTransportType, const wangle::TransportInfo &tinfo) override
HTTPServerAcceptor(const AcceptorConfiguration &conf, const std::shared_ptr< HTTPCodecFactory > &codecFactory, std::vector< RequestHandlerFactory * > handlerFactories, const HTTPServerOptions &options)
folly::SocketAddress bindAddress
void setSocketOptions(const folly::AsyncSocket::OptionMap &opts)
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
std::vector< wangle::SSLContextConfig > sslConfigs
Definition: HTTPServer.h:51
std::vector< std::unique_ptr< RequestHandlerFactory > > handlerFactories
FOLLY_CPP14_CONSTEXPR bool hasValue() const noexcept
Definition: Optional.h:300
virtual void onRequest(std::unique_ptr< HTTPMessage > headers) noexcept=0
void onNewConnection(folly::AsyncTransportWrapper::UniquePtr sock, const folly::SocketAddress *address, const std::string &nextProtocolName, wangle::SecureTransportType secureTransportType, const wangle::TransportInfo &tinfo) override
TLSTicketKeySeeds initialTicketSeeds
const char * string
Definition: Conv.cpp:212
const std::vector< RequestHandlerFactory * > handlerFactories_
void setCompletionCallback(std::function< void()> f)
FOLLY_CPP14_CONSTEXPR const Value & value() const &
Definition: Optional.h:268
static std::unique_ptr< HTTPServerAcceptor > make(const AcceptorConfiguration &conf, const HTTPServerOptions &opts, const std::shared_ptr< HTTPCodecFactory > &codecFactory=nullptr)
std::vector< SSLContextConfig > sslContextConfigs
folly::Optional< wangle::TLSTicketKeySeeds > ticketSeeds
Definition: HTTPServer.h:60