proxygen
|
#include <ProxyHandler.h>
Classes | |
class | ServerTransactionHandler |
Public Member Functions | |
ProxyHandler (ProxyStats *stats, folly::HHWheelTimer *timer) | |
~ProxyHandler () override | |
void | onRequest (std::unique_ptr< proxygen::HTTPMessage > headers) noexceptoverride |
void | onBody (std::unique_ptr< folly::IOBuf > body) noexceptoverride |
void | onEOM () noexceptoverride |
void | onUpgrade (proxygen::UpgradeProtocol) noexceptoverride |
void | requestComplete () noexceptoverride |
void | onError (proxygen::ProxygenError err) noexceptoverride |
void | onEgressPaused () noexceptoverride |
void | onEgressResumed () noexceptoverride |
void | detachServerTransaction () noexcept |
void | onServerHeadersComplete (std::unique_ptr< proxygen::HTTPMessage > msg) noexcept |
void | onServerBody (std::unique_ptr< folly::IOBuf > chain) noexcept |
void | onServerEOM () noexcept |
void | onServerError (const proxygen::HTTPException &error) noexcept |
void | onServerEgressPaused () noexcept |
void | onServerEgressResumed () noexcept |
![]() | |
virtual void | setResponseHandler (ResponseHandler *handler) noexcept |
virtual bool | canHandleExpect () noexcept |
virtual ExMessageHandler * | getExHandler () noexcept |
virtual ResponseHandler * | getDownstream () noexcept |
virtual | ~RequestHandler () |
Private Member Functions | |
void | connectSuccess (proxygen::HTTPUpstreamSession *session) override |
void | connectError (const folly::AsyncSocketException &ex) override |
void | connectSuccess () noexceptoverride |
void | connectErr (const folly::AsyncSocketException &ex) noexceptoverride |
void | getReadBuffer (void **bufReturn, size_t *lenReturn) override |
void | readDataAvailable (size_t len) noexceptoverride |
void | readEOF () noexceptoverride |
void | readErr (const folly::AsyncSocketException &ex) noexceptoverride |
void | writeSuccess () noexceptoverride |
void | writeErr (size_t bytesWritten, const folly::AsyncSocketException &ex) noexceptoverride |
void | abortDownstream () |
bool | checkForShutdown () |
![]() | |
virtual | ~Callback () |
![]() | |
virtual | ~ConnectCallback ()=default |
![]() | |
virtual | ~ReadCallback ()=default |
virtual bool | isBufferMovable () noexcept |
virtual size_t | maxBufferSize () const |
virtual void | readBufferAvailable (std::unique_ptr< IOBuf >) noexcept |
![]() | |
virtual | ~WriteCallback ()=default |
Private Attributes | |
ProxyStats *const | stats_ {nullptr} |
proxygen::HTTPConnector | connector_ |
ServerTransactionHandler | serverHandler_ |
std::unique_ptr< SessionWrapper > | session_ |
proxygen::HTTPTransaction * | txn_ {nullptr} |
bool | clientTerminated_ {false} |
std::unique_ptr< proxygen::HTTPMessage > | request_ |
std::shared_ptr< folly::AsyncSocket > | upstreamSock_ |
uint8_t | sockStatus_ {0} |
folly::IOBufQueue | body_ {folly::IOBufQueue::cacheChainLength()} |
bool | downstreamIngressPaused_ {false} |
bool | upstreamEgressPaused_ {false} |
Additional Inherited Members | |
![]() | |
ResponseHandler * | downstream_ {nullptr} |
Definition at line 26 of file ProxyHandler.h.
ProxyService::ProxyHandler::ProxyHandler | ( | ProxyStats * | stats, |
folly::HHWheelTimer * | timer | ||
) |
Definition at line 39 of file ProxyHandler.cpp.
References serverHandler_.
|
override |
Definition at line 45 of file ProxyHandler.cpp.
|
private |
Definition at line 218 of file ProxyHandler.cpp.
References clientTerminated_, proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::sendAbort().
Referenced by connectError(), onServerError(), readErr(), and writeErr().
|
private |
Definition at line 224 of file ProxyHandler.cpp.
References clientTerminated_, sockStatus_, txn_, upstreamEgressPaused_, and upstreamSock_.
Referenced by connectError(), detachServerTransaction(), onError(), readErr(), requestComplete(), writeErr(), and writeSuccess().
|
overrideprivatevirtualnoexcept |
connectErr() will be invoked if the connection attempt fails.
ex | An exception describing the error that occurred. |
Implements folly::AsyncSocket::ConnectCallback.
Definition at line 242 of file ProxyHandler.cpp.
References connectError().
|
overrideprivatevirtual |
Implements proxygen::HTTPConnector::Callback.
Definition at line 130 of file ProxyHandler.cpp.
References abortDownstream(), checkForShutdown(), clientTerminated_, proxygen::RequestHandler::downstream_, proxygen::ERROR, folly::exceptionStr(), proxygen::ResponseBuilder::sendWithEOM(), and proxygen::ResponseBuilder::status().
Referenced by connectErr().
|
overrideprivatevirtual |
Implements proxygen::HTTPConnector::Callback.
Definition at line 120 of file ProxyHandler.cpp.
References proxygen::RequestHandler::downstream_, proxygen::HTTPUpstreamSession::newTransaction(), request_, proxygen::ResponseHandler::resumeIngress(), serverHandler_, session_, and txn_.
|
overrideprivatevirtualnoexcept |
connectSuccess() will be invoked when the connection has been successfully established.
Implements folly::AsyncSocket::ConnectCallback.
Definition at line 233 of file ProxyHandler.cpp.
References proxygen::RequestHandler::downstream_, proxygen::ResponseHandler::resumeIngress(), proxygen::ResponseBuilder::send(), proxygen::ResponseBuilder::status(), and upstreamSock_.
|
noexcept |
Definition at line 163 of file ProxyHandler.cpp.
References checkForShutdown(), and txn_.
Referenced by ProxyService::ProxyHandler::ServerTransactionHandler::detachTransaction().
|
overrideprivatevirtual |
When data becomes available, getReadBuffer() will be invoked to get the buffer into which data should be read.
This method allows the ReadCallback to delay buffer allocation until data becomes available. This allows applications to manage large numbers of idle connections, without having to maintain a separate read buffer for each idle connection.
It is possible that in some cases, getReadBuffer() may be called multiple times before readDataAvailable() is invoked. In this case, the data will be written to the buffer returned from the most recent call to readDataAvailable(). If the previous calls to readDataAvailable() returned different buffers, the ReadCallback is responsible for ensuring that they are not leaked.
If getReadBuffer() throws an exception, returns a nullptr buffer, or returns a 0 length, the ReadCallback will be uninstalled and its readError() method will be invoked.
getReadBuffer() is not allowed to change the transport state before it returns. (For example, it should never uninstall the read callback, or set a different read callback.)
bufReturn | getReadBuffer() should update *bufReturn to contain the address of the read buffer. This parameter will never be nullptr. |
lenReturn | getReadBuffer() should update *lenReturn to contain the maximum number of bytes that may be written to the read buffer. This parameter will never be nullptr. |
Implements folly::AsyncReader::ReadCallback.
Definition at line 246 of file ProxyHandler.cpp.
References body_, fizz::kMaxReadSize, fizz::kMinReadSize, and folly::IOBufQueue::preallocate().
|
overridevirtualnoexcept |
Invoked when we get part of body for the request.
Implements proxygen::RequestHandler.
Definition at line 89 of file ProxyHandler.cpp.
References downstreamIngressPaused_, folly::gen::move, onServerEgressPaused(), proxygen::HTTPTransaction::sendBody(), txn_, upstreamEgressPaused_, and upstreamSock_.
|
overridevirtualnoexcept |
Signals from HTTP layer when client queue is full or empty. If you are sending a streaming response, consider implementing these and acting accordingly. Saves your server from running out of memory.
Reimplemented from proxygen::RequestHandler.
Definition at line 202 of file ProxyHandler.cpp.
References proxygen::HTTPTransaction::pauseIngress(), txn_, and upstreamSock_.
|
overridevirtualnoexcept |
Reimplemented from proxygen::RequestHandler.
Definition at line 210 of file ProxyHandler.cpp.
References proxygen::HTTPTransaction::resumeIngress(), txn_, and upstreamSock_.
|
overridevirtualnoexcept |
Invoked when we finish receiving the body.
Implements proxygen::RequestHandler.
Definition at line 107 of file ProxyHandler.cpp.
References proxygen::HTTPTransaction::sendEOM(), sockStatus_, txn_, and upstreamSock_.
|
overridevirtualnoexcept |
Request failed. Maybe because of read/write error on socket or client not being able to send request in time.
NOTE: Can be invoked at any time (except for before onRequest).
No more callbacks will be invoked after this. You should clean up after yourself.
Implements proxygen::RequestHandler.
Definition at line 190 of file ProxyHandler.cpp.
References checkForShutdown(), clientTerminated_, proxygen::ERROR, proxygen::getErrorString(), proxygen::HTTPTransaction::sendAbort(), txn_, and upstreamSock_.
|
overridevirtualnoexcept |
Invoked when we have successfully fetched headers from client. This will always be the first callback invoked on your handler.
Implements proxygen::RequestHandler.
Definition at line 49 of file ProxyHandler.cpp.
References addr, proxygen::ResponseBuilder::body(), proxygen::HTTPConnector::connect(), connector_, proxygen::RequestHandler::downstream_, folly::EventBaseManager::get(), folly::EventBaseManager::getEventBase(), folly::getEventBase(), folly::gen::move, folly::AsyncSocket::newSocket(), proxygen::ResponseHandler::pauseIngress(), ProxyService::ProxyStats::recordRequest(), request_, proxygen::ResponseBuilder::sendWithEOM(), stats_, proxygen::ResponseBuilder::status(), and upstreamSock_.
|
noexcept |
Definition at line 149 of file ProxyHandler.cpp.
References clientTerminated_, proxygen::RequestHandler::downstream_, folly::gen::move, and proxygen::ResponseHandler::sendBody().
Referenced by ProxyService::ProxyHandler::ServerTransactionHandler::onBody().
|
noexcept |
Definition at line 173 of file ProxyHandler.cpp.
References clientTerminated_, proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::pauseIngress().
Referenced by onBody(), and ProxyService::ProxyHandler::ServerTransactionHandler::onEgressPaused().
|
noexcept |
Definition at line 179 of file ProxyHandler.cpp.
References clientTerminated_, proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::resumeIngress().
Referenced by ProxyService::ProxyHandler::ServerTransactionHandler::onEgressResumed(), and writeSuccess().
|
noexcept |
Definition at line 156 of file ProxyHandler.cpp.
References clientTerminated_, proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::sendEOM().
Referenced by ProxyService::ProxyHandler::ServerTransactionHandler::onEOM(), and readEOF().
|
noexcept |
Definition at line 168 of file ProxyHandler.cpp.
References abortDownstream(), proxygen::ERROR, and folly::pushmi::operators::error().
Referenced by ProxyService::ProxyHandler::ServerTransactionHandler::onError().
|
noexcept |
Definition at line 142 of file ProxyHandler.cpp.
References clientTerminated_, proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::sendHeaders().
Referenced by ProxyService::ProxyHandler::ServerTransactionHandler::onHeadersComplete().
|
inlineoverridevirtualnoexcept |
Invoked when the session has been upgraded to a different protocol
Implements proxygen::RequestHandler.
Definition at line 43 of file ProxyHandler.h.
References folly::pushmi::operators::error(), and folly::pushmi::__adl::noexcept().
|
overrideprivatevirtualnoexcept |
readDataAvailable() will be invoked when data has been successfully read into the buffer returned by the last call to getReadBuffer().
The read callback remains installed after readDataAvailable() returns. It must be explicitly uninstalled to stop receiving read events. getReadBuffer() will be called at least once before each call to readDataAvailable(). getReadBuffer() will also be called before any call to readEOF().
len | The number of bytes placed in the buffer. |
Implements folly::AsyncReader::ReadCallback.
Definition at line 253 of file ProxyHandler.cpp.
References body_, proxygen::RequestHandler::downstream_, folly::IOBufQueue::move(), folly::IOBufQueue::postallocate(), and proxygen::ResponseHandler::sendBody().
|
overrideprivatevirtualnoexcept |
readEOF() will be invoked when the transport is closed.
The read callback will be automatically uninstalled immediately before readEOF() is invoked.
Implements folly::AsyncReader::ReadCallback.
Definition at line 258 of file ProxyHandler.cpp.
References onServerEOM(), and sockStatus_.
|
overrideprivatevirtualnoexcept |
readError() will be invoked if an error occurs reading from the transport.
The read callback will be automatically uninstalled immediately before readError() is invoked.
ex | An exception describing the error that occurred. |
Implements folly::AsyncReader::ReadCallback.
Definition at line 263 of file ProxyHandler.cpp.
References abortDownstream(), checkForShutdown(), proxygen::ERROR, folly::exceptionStr(), and upstreamSock_.
|
overridevirtualnoexcept |
Invoked when request processing has been completed and nothing more needs to be done. This may be a good place to log some stats and clean up resources. This is distinct from onEOM() because it is invoked after the response is fully sent. Once this callback has been received, downstream_
should be considered invalid.
Implements proxygen::RequestHandler.
Definition at line 185 of file ProxyHandler.cpp.
References checkForShutdown(), and clientTerminated_.
|
overrideprivatevirtualnoexcept |
writeError() will be invoked if an error occurs writing the data.
bytesWritten | The number of bytes that were successfull |
ex | An exception describing the error that occurred. |
Implements folly::AsyncWriter::WriteCallback.
Definition at line 279 of file ProxyHandler.cpp.
References abortDownstream(), checkForShutdown(), proxygen::ERROR, folly::exceptionStr(), upstreamEgressPaused_, and upstreamSock_.
|
overrideprivatevirtualnoexcept |
writeSuccess() will be invoked when all of the data has been successfully written.
Note that this mainly signals that the buffer containing the data to write is no longer needed and may be freed or re-used. It does not guarantee that the data has been fully transmitted to the remote endpoint. For example, on socket-based transports, writeSuccess() only indicates that the data has been given to the kernel for eventual transmission.
Implements folly::AsyncWriter::WriteCallback.
Definition at line 270 of file ProxyHandler.cpp.
References checkForShutdown(), downstreamIngressPaused_, onServerEgressResumed(), and upstreamEgressPaused_.
|
private |
Definition at line 142 of file ProxyHandler.h.
Referenced by getReadBuffer(), and readDataAvailable().
|
private |
Definition at line 135 of file ProxyHandler.h.
Referenced by abortDownstream(), checkForShutdown(), connectError(), onError(), onServerBody(), onServerEgressPaused(), onServerEgressResumed(), onServerEOM(), onServerHeadersComplete(), and requestComplete().
|
private |
Definition at line 131 of file ProxyHandler.h.
Referenced by onRequest().
|
private |
Definition at line 143 of file ProxyHandler.h.
Referenced by onBody(), and writeSuccess().
|
private |
Definition at line 137 of file ProxyHandler.h.
Referenced by connectSuccess(), and onRequest().
|
private |
Definition at line 132 of file ProxyHandler.h.
Referenced by connectSuccess(), and ProxyHandler().
|
private |
Definition at line 133 of file ProxyHandler.h.
Referenced by connectSuccess().
|
private |
Definition at line 141 of file ProxyHandler.h.
Referenced by checkForShutdown(), onEOM(), and readEOF().
|
private |
Definition at line 130 of file ProxyHandler.h.
Referenced by onRequest().
|
private |
Definition at line 134 of file ProxyHandler.h.
Referenced by checkForShutdown(), connectSuccess(), detachServerTransaction(), onBody(), onEgressPaused(), onEgressResumed(), onEOM(), and onError().
|
private |
Definition at line 144 of file ProxyHandler.h.
Referenced by checkForShutdown(), onBody(), writeErr(), and writeSuccess().
|
private |
Definition at line 140 of file ProxyHandler.h.
Referenced by checkForShutdown(), connectSuccess(), onBody(), onEgressPaused(), onEgressResumed(), onEOM(), onError(), onRequest(), readErr(), and writeErr().