proxygen
|
#include <HTTPServer.h>
Classes | |
struct | IPConfig |
Public Types | |
enum | Protocol : uint8_t { Protocol::HTTP, Protocol::SPDY, Protocol::HTTP2 } |
Public Member Functions | |
HTTPServer (HTTPServerOptions options) | |
~HTTPServer () | |
void | bind (std::vector< IPConfig > &&addrs) |
void | bind (std::vector< IPConfig > const &addrs) |
void | start (std::function< void()> onSuccess=nullptr, std::function< void(std::exception_ptr)> onError=nullptr) |
void | stopListening () |
void | stop () |
std::vector< IPConfig > | addresses () const |
const std::vector< const folly::AsyncSocketBase * > | getSockets () const |
void | setSessionInfoCallback (HTTPSession::InfoCallback *cb) |
int | getListenSocket () const |
void | updateTLSCredentials () |
void | updateTicketSeeds (wangle::TLSTicketKeySeeds seeds) |
Private Attributes | |
std::shared_ptr< HTTPServerOptions > | options_ |
folly::EventBase * | mainEventBase_ {nullptr} |
std::unique_ptr< SignalHandler > | signalHandler_ |
std::vector< IPConfig > | addresses_ |
std::vector< wangle::ServerBootstrap< wangle::DefaultPipeline > > | bootstrap_ |
HTTPSession::InfoCallback * | sessionInfoCb_ {nullptr} |
HTTPServer based on proxygen http libraries
Definition at line 28 of file HTTPServer.h.
|
strong |
For each IP you can specify HTTP protocol to use. You can use plain old HTTP/1.1 protocol or SPDY/3.1 for now.
Enumerator | |
---|---|
HTTP | |
SPDY | |
HTTP2 |
Definition at line 34 of file HTTPServer.h.
|
explicit |
Create a new HTTPServer
Definition at line 59 of file HTTPServer.cpp.
References options_.
proxygen::HTTPServer::~HTTPServer | ( | ) |
|
inline |
Get the list of addresses server is listening on. Empty if sockets are not bound yet.
Definition at line 139 of file HTTPServer.h.
References addresses_, and getSockets().
Referenced by TEST().
void proxygen::HTTPServer::bind | ( | std::vector< IPConfig > && | addrs | ) |
Configure server to bind to the following addresses.
Actual bind happens in start
function.
Can be called from any thread.
Definition at line 85 of file HTTPServer.cpp.
References addresses_, and folly::gen::move.
Referenced by main().
void proxygen::HTTPServer::bind | ( | std::vector< IPConfig > const & | addrs | ) |
int proxygen::HTTPServer::getListenSocket | ( | ) | const |
Returns a file descriptor associated with the listening socket
Definition at line 224 of file HTTPServer.cpp.
References bootstrap_, and folly::AsyncServerSocket::getSockets().
Referenced by setSessionInfoCallback(), and TEST().
const std::vector< const folly::AsyncSocketBase * > proxygen::HTTPServer::getSockets | ( | ) | const |
Get the sockets the server is currently bound to.
Definition at line 211 of file HTTPServer.cpp.
References bootstrap_, FOR_EACH_RANGE, and i.
Referenced by addresses().
|
inline |
Definition at line 148 of file HTTPServer.h.
References getListenSocket(), sessionInfoCb_, updateTicketSeeds(), and updateTLSCredentials().
void proxygen::HTTPServer::start | ( | std::function< void()> | onSuccess = nullptr , |
std::function< void(std::exception_ptr)> | onError = nullptr |
||
) |
Start HTTPServer.
Note this is a blocking call and the current thread will be used to listen for incoming connections. Throws exception if something goes wrong (say somebody else is already listening on that socket).
onSuccess
callback will be invoked from the event loop which shows that all the setup was successfully done.
onError
callback will be invoked if some errors occurs while starting the server instead of throwing exception.
Definition at line 119 of file HTTPServer.cpp.
References addresses_, bootstrap_, exe, FOR_EACH_RANGE, folly::pushmi::operators::get, i, folly::EventBase::loopForever(), mainEventBase_, proxygen::HTTPServerAcceptor::makeConfig(), folly::gen::move, options_, folly::EventBase::runInLoop(), sessionInfoCb_, signalHandler_, and stop().
Referenced by main().
void proxygen::HTTPServer::stop | ( | ) |
Stop HTTPServer.
Can be called from any thread, but only after start() has called onSuccess. Server will stop listening for new connections and will wait for running requests to finish.
TODO: Separate method to do hard shutdown?
Definition at line 193 of file HTTPServer.cpp.
References bootstrap_, mainEventBase_, signalHandler_, stopListening(), and folly::EventBase::terminateLoopSoon().
Referenced by proxygen::SignalHandler::signalReceived(), and start().
void proxygen::HTTPServer::stopListening | ( | ) |
Stop listening on bound ports. (Stop accepting new work). It does not wait for pending work to complete. You must still invoke stop() before destroying the server. You do NOT need to invoke this before calling stop(). This can be called from any thread, and it is idempotent. However, it may only be called after start() has called onSuccess.
Definition at line 187 of file HTTPServer.cpp.
References bootstrap_.
Referenced by stop(), and TEST().
void proxygen::HTTPServer::updateTicketSeeds | ( | wangle::TLSTicketKeySeeds | seeds | ) |
Updates ticket seeds for the HTTPServer for all the VIPs.
Definition at line 262 of file HTTPServer.cpp.
References bootstrap_, wangle::TLSTicketKeySeeds::currentSeeds, wangle::Acceptor::getEventBase(), wangle::Acceptor::isSSL(), wangle::TLSTicketKeySeeds::newSeeds, wangle::TLSTicketKeySeeds::oldSeeds, folly::EventBase::runInEventBaseThread(), and wangle::Acceptor::setTLSTicketSecrets().
Referenced by setSessionInfoCallback(), and TEST().
void proxygen::HTTPServer::updateTLSCredentials | ( | ) |
Re-reads the certificate / key pair for all SSL vips on all acceptors
Definition at line 245 of file HTTPServer.cpp.
References bootstrap_, wangle::Acceptor::getEventBase(), wangle::Acceptor::isSSL(), wangle::Acceptor::resetSSLContextConfigs(), and folly::EventBase::runInEventBaseThread().
Referenced by setSessionInfoCallback().
|
private |
Addresses we are listening on
Definition at line 183 of file HTTPServer.h.
Referenced by addresses(), bind(), and start().
|
private |
Definition at line 184 of file HTTPServer.h.
Referenced by getListenSocket(), getSockets(), start(), stop(), stopListening(), updateTicketSeeds(), and updateTLSCredentials().
|
private |
Event base in which we binded server sockets.
Definition at line 173 of file HTTPServer.h.
Referenced by start(), stop(), and ~HTTPServer().
|
private |
Definition at line 168 of file HTTPServer.h.
Referenced by HTTPServer(), start(), proxygen::HandlerCallbacks::threadStarted(), and proxygen::HandlerCallbacks::threadStopped().
|
private |
Callback for session create/destruction
Definition at line 189 of file HTTPServer.h.
Referenced by setSessionInfoCallback(), and start().
|
private |
Optional signal handlers on which we should shutdown server
Definition at line 178 of file HTTPServer.h.