proxygen
|
#include <HTTPConnector.h>
Classes | |
class | Callback |
Public Member Functions | |
HTTPConnector (Callback *callback, folly::HHWheelTimer *timeoutSet) | |
HTTPConnector (Callback *callback, const WheelTimerInstance &timeout) | |
~HTTPConnector () override | |
void | reset () |
void | setPlaintextProtocol (const std::string &plaintextProto) |
void | setHTTPVersionOverride (bool enabled) |
void | connect (folly::EventBase *eventBase, const folly::SocketAddress &connectAddr, std::chrono::milliseconds timeoutMs=std::chrono::milliseconds(0), const folly::AsyncSocket::OptionMap &socketOptions=folly::AsyncSocket::emptyOptionMap, const folly::SocketAddress &bindAddr=folly::AsyncSocket::anyAddress()) |
void | connectSSL (folly::EventBase *eventBase, const folly::SocketAddress &connectAddr, const std::shared_ptr< folly::SSLContext > &ctx, SSL_SESSION *session=nullptr, std::chrono::milliseconds timeoutMs=std::chrono::milliseconds(0), const folly::AsyncSocket::OptionMap &socketOptions=folly::AsyncSocket::emptyOptionMap, const folly::SocketAddress &bindAddr=folly::AsyncSocket::anyAddress(), const std::string &serverName=empty_string) |
std::chrono::milliseconds | timeElapsed () |
bool | isBusy () const |
void | setHTTPCodecFactory (std::unique_ptr< DefaultHTTPCodecFactory > factory) |
Protected Member Functions | |
void | connectSuccess () noexceptoverride |
void | connectErr (const folly::AsyncSocketException &ex) noexceptoverride |
Protected Member Functions inherited from folly::AsyncSocket::ConnectCallback | |
virtual | ~ConnectCallback ()=default |
Protected Attributes | |
Callback * | cb_ |
WheelTimerInstance | timeout_ |
folly::AsyncTransportWrapper::UniquePtr | socket_ |
wangle::TransportInfo | transportInfo_ |
std::string | plaintextProtocol_ |
TimePoint | connectStart_ |
std::unique_ptr< DefaultHTTPCodecFactory > | httpCodecFactory_ |
This class establishes new connections to HTTP or HTTPS servers. It can be reused, even to connect to different addresses, but it can only service setting up one connection at a time.
Definition at line 31 of file HTTPConnector.h.
proxygen::HTTPConnector::HTTPConnector | ( | Callback * | callback, |
folly::HHWheelTimer * | timeoutSet | ||
) |
Construct a HTTPConnector. The constructor arguments are those parameters HTTPConnector needs to keep a copy of through the connection process.
callback | The interface on which to receive the result. Whatever object is passed here MUST outlive this connector and MUST NOT be null. |
timeoutSet | The timeout set to be used for the transactions that are opened on the session. |
Definition at line 27 of file HTTPConnector.cpp.
Referenced by proxygen::HTTPConnector::Callback::~Callback().
proxygen::HTTPConnector::HTTPConnector | ( | Callback * | callback, |
const WheelTimerInstance & | timeout | ||
) |
Definition at line 32 of file HTTPConnector.cpp.
|
override |
Clients may delete the connector at any time to cancel it. No callbacks will be received.
Definition at line 38 of file HTTPConnector.cpp.
References reset().
Referenced by proxygen::HTTPConnector::Callback::~Callback().
void proxygen::HTTPConnector::connect | ( | folly::EventBase * | eventBase, |
const folly::SocketAddress & | connectAddr, | ||
std::chrono::milliseconds | timeoutMs = std::chrono::milliseconds(0) , |
||
const folly::AsyncSocket::OptionMap & | socketOptions = folly::AsyncSocket::emptyOptionMap , |
||
const folly::SocketAddress & | bindAddr = folly::AsyncSocket::anyAddress() |
||
) |
Begin the process of getting a plaintext connection to the server specified by 'connectAddr'. This function immediately starts async work and may invoke functions on Callback immediately.
eventBase | The event base to put events on. |
connectAddr | The address to connect to. |
timeoutMs | Optional. If this value is greater than zero, then a connect error will be given if no connection is established within this amount of time. |
socketOptions | Optional socket options to set on the connection. |
bindAddr | Optional address to bind to locally. |
Definition at line 59 of file HTTPConnector.cpp.
References connectStart_, proxygen::getCurrentTime(), isBusy(), wangle::TransportInfo::secure, socket_, and transportInfo_.
Referenced by ScopedServerTest::connectPlainText(), ProxyService::ProxyHandler::onRequest(), TEST(), and proxygen::HTTPConnector::Callback::~Callback().
|
overrideprotectedvirtualnoexcept |
connectErr() will be invoked if the connection attempt fails.
ex | An exception describing the error that occurred. |
Implements folly::AsyncSocket::ConnectCallback.
Definition at line 151 of file HTTPConnector.cpp.
References cb_, proxygen::HTTPConnector::Callback::connectError(), and socket_.
Referenced by setHTTPCodecFactory().
void proxygen::HTTPConnector::connectSSL | ( | folly::EventBase * | eventBase, |
const folly::SocketAddress & | connectAddr, | ||
const std::shared_ptr< folly::SSLContext > & | ctx, | ||
SSL_SESSION * | session = nullptr , |
||
std::chrono::milliseconds | timeoutMs = std::chrono::milliseconds(0) , |
||
const folly::AsyncSocket::OptionMap & | socketOptions = folly::AsyncSocket::emptyOptionMap , |
||
const folly::SocketAddress & | bindAddr = folly::AsyncSocket::anyAddress() , |
||
const std::string & | serverName = empty_string |
||
) |
Begin the process of getting a secure connection to the server specified by 'connectAddr'. This function immediately starts async work and may invoke functions on Callback immediately.
eventBase | The event base to put events on. |
connectAddr | The address to connect to. |
ctx | SSL context to use. Must not be null. |
session | Optional ssl session to use. |
timeoutMs | Optional. If this value is greater than zero, then a connect error will be given if no connection is established within this amount of time. |
socketOptions | Optional socket options to set on the connection. |
bindAddr | Optional address to bind to locally. |
Definition at line 76 of file HTTPConnector.cpp.
References connectStart_, proxygen::getCurrentTime(), isBusy(), wangle::TransportInfo::secure, socket_, and transportInfo_.
Referenced by ScopedServerTest::connectSSL(), and proxygen::HTTPConnector::Callback::~Callback().
|
overrideprotectedvirtualnoexcept |
connectSuccess() will be invoked when the connection has been successfully established.
Implements folly::AsyncSocket::ConnectCallback.
Definition at line 110 of file HTTPConnector.cpp.
References wangle::TransportInfo::acceptTime, wangle::TransportInfo::appProtocol, cb_, codec, connectStart_, proxygen::HTTPConnector::Callback::connectSuccess(), proxygen::getCurrentTime(), folly::AsyncSSLSocket::getNegotiatedCipherName(), wangle::SSLUtil::getResumeState(), folly::AsyncSSLSocket::getSSLVersion(), httpCodecFactory_, proxygen::millisecondsSince(), folly::gen::move, plaintextProtocol_, wangle::TransportInfo::secure, socket_, wangle::TransportInfo::sslCipher, wangle::TransportInfo::sslResume, wangle::TransportInfo::sslSetupTime, wangle::TransportInfo::sslVersion, timeout_, transportInfo_, and proxygen::UPSTREAM.
|
inline |
Definition at line 145 of file HTTPConnector.h.
References socket_.
Referenced by connect(), and connectSSL().
void proxygen::HTTPConnector::reset | ( | ) |
Reset the object so that it can begin a new connection. No callbacks will be invoked as a result of executing this function. After this function returns, isBusy() will return false.
Definition at line 42 of file HTTPConnector.cpp.
Referenced by proxygen::HTTPConnector::Callback::~Callback(), and ~HTTPConnector().
|
inline |
Definition at line 147 of file HTTPConnector.h.
References connectErr(), proxygen::HTTPConnector::Callback::connectSuccess(), httpCodecFactory_, folly::gen::move, and folly::pushmi::__adl::noexcept().
void proxygen::HTTPConnector::setHTTPVersionOverride | ( | bool | enabled | ) |
Overrides the HTTP version to always use the latest and greatest version we support.
Definition at line 55 of file HTTPConnector.cpp.
References httpCodecFactory_.
Referenced by proxygen::HTTPConnector::Callback::~Callback().
void proxygen::HTTPConnector::setPlaintextProtocol | ( | const std::string & | plaintextProto | ) |
Sets the plain text protocol to use after the connection is established.
Definition at line 51 of file HTTPConnector.cpp.
References plaintextProtocol_.
Referenced by main(), and proxygen::HTTPConnector::Callback::~Callback().
std::chrono::milliseconds proxygen::HTTPConnector::timeElapsed | ( | ) |
Definition at line 101 of file HTTPConnector.cpp.
References connectStart_, proxygen::millisecondsSince(), and proxygen::timePointInitialized().
Referenced by proxygen::HTTPConnector::Callback::~Callback().
|
protected |
Definition at line 157 of file HTTPConnector.h.
Referenced by connectErr(), connectSuccess(), and reset().
|
protected |
Definition at line 162 of file HTTPConnector.h.
Referenced by connect(), connectSSL(), connectSuccess(), and timeElapsed().
|
protected |
Definition at line 163 of file HTTPConnector.h.
Referenced by connectSuccess(), setHTTPCodecFactory(), and setHTTPVersionOverride().
|
protected |
Definition at line 161 of file HTTPConnector.h.
Referenced by connectSuccess(), and setPlaintextProtocol().
|
protected |
Definition at line 159 of file HTTPConnector.h.
Referenced by connect(), connectErr(), connectSSL(), connectSuccess(), isBusy(), and reset().
|
protected |
Definition at line 158 of file HTTPConnector.h.
Referenced by connectSuccess().
|
protected |
Definition at line 160 of file HTTPConnector.h.
Referenced by connect(), connectSSL(), and connectSuccess().