proxygen
HTTPServer.h
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  */
10 #pragma once
11 
18 #include <thread>
19 
20 namespace proxygen {
21 
22 class SignalHandler;
23 class HTTPServerAcceptor;
24 
28 class HTTPServer final {
29  public:
34  enum class Protocol: uint8_t {
35  HTTP,
36  SPDY,
37  HTTP2,
38  };
39 
40  struct IPConfig {
42  Protocol p,
43  std::shared_ptr<HTTPCodecFactory> c = nullptr)
44  : address(a),
45  protocol(p),
46  codecFactory(c) {}
47 
50  std::shared_ptr<HTTPCodecFactory> codecFactory;
51  std::vector<wangle::SSLContextConfig> sslConfigs;
52 
53  /*
54  * Sets the initial ticket seeds to use when starting the HTTPServer.
55  * Ticket seeds are used to generate the session ticket encryption keys
56  * for ticket resumption. When using session tickets, it is important
57  * to change them and keep them updated, see updateTicketSeeds to keep
58  * seeds up to date.
59  */
61 
62  /*
63  * Whether to allow an insecure connection on a secure port.
64  * This should be used in very few cases where a HTTP server needs to
65  * support insecure and secure connections on the same address.
66  */
67  bool allowInsecureConnectionsOnSecureServer{false};
68  bool enableTCPFastOpen{false};
72  uint32_t fastOpenQueueSize{10000};
73 
74  /*
75  * Determines if this server does strict checking when loading SSL contexts.
76  */
77  bool strictSSL{true};
78 
80  };
81 
85  explicit HTTPServer(HTTPServerOptions options);
86  ~HTTPServer();
87 
95  void bind(std::vector<IPConfig>&& addrs);
96  void bind(std::vector<IPConfig> const& addrs);
97 
111  void start(std::function<void()> onSuccess = nullptr,
112  std::function<void(std::exception_ptr)> onError = nullptr);
113 
122  void stopListening();
123 
133  void stop();
134 
139  std::vector<IPConfig> addresses() const {
140  return addresses_;
141  }
142 
146  const std::vector<const folly::AsyncSocketBase*> getSockets() const;
147 
149  sessionInfoCb_ = cb;
150  }
151 
155  int getListenSocket() const;
156 
160  void updateTLSCredentials();
161 
166 
167  private:
168  std::shared_ptr<HTTPServerOptions> options_;
169 
174 
178  std::unique_ptr<SignalHandler> signalHandler_;
179 
183  std::vector<IPConfig> addresses_;
184  std::vector<wangle::ServerBootstrap<wangle::DefaultPipeline>> bootstrap_;
185 
190 };
191 
192 }
folly::Optional< folly::AsyncSocket::OptionMap > acceptorSocketOptions
Definition: HTTPServer.h:79
void start(std::function< void()> onSuccess=nullptr, std::function< void(std::exception_ptr)> onError=nullptr)
Definition: HTTPServer.cpp:119
void bind(std::vector< IPConfig > &&addrs)
Definition: HTTPServer.cpp:85
folly::SocketAddress address
Definition: HTTPServer.h:48
int getListenSocket() const
Definition: HTTPServer.cpp:224
std::shared_ptr< HTTPCodecFactory > codecFactory
Definition: HTTPServer.h:50
std::vector< wangle::SSLContextConfig > sslConfigs
Definition: HTTPServer.h:51
std::vector< IPConfig > addresses() const
Definition: HTTPServer.h:139
char a
std::vector< IPConfig > addresses_
Definition: HTTPServer.h:183
std::unique_ptr< SignalHandler > signalHandler_
Definition: HTTPServer.h:178
folly::EventBase * mainEventBase_
Definition: HTTPServer.h:173
HTTPSession::InfoCallback * sessionInfoCb_
Definition: HTTPServer.h:189
std::shared_ptr< HTTPServerOptions > options_
Definition: HTTPServer.h:168
void updateTicketSeeds(wangle::TLSTicketKeySeeds seeds)
Definition: HTTPServer.cpp:262
std::vector< wangle::ServerBootstrap< wangle::DefaultPipeline > > bootstrap_
Definition: HTTPServer.h:184
HTTPServer(HTTPServerOptions options)
Definition: HTTPServer.cpp:59
char c
const std::vector< const folly::AsyncSocketBase * > getSockets() const
Definition: HTTPServer.cpp:211
void setSessionInfoCallback(HTTPSession::InfoCallback *cb)
Definition: HTTPServer.h:148
IPConfig(folly::SocketAddress a, Protocol p, std::shared_ptr< HTTPCodecFactory > c=nullptr)
Definition: HTTPServer.h:41
folly::Optional< wangle::TLSTicketKeySeeds > ticketSeeds
Definition: HTTPServer.h:60