proxygen
ProxyService::ProxyHandler Class Reference

#include <ProxyHandler.h>

Inheritance diagram for ProxyService::ProxyHandler:
proxygen::RequestHandler proxygen::HTTPConnector::Callback folly::AsyncSocket::ConnectCallback folly::AsyncReader::ReadCallback folly::AsyncWriter::WriteCallback

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
 
- Public Member Functions inherited from proxygen::RequestHandler
virtual void setResponseHandler (ResponseHandler *handler) noexcept
 
virtual bool canHandleExpect () noexcept
 
virtual ExMessageHandlergetExHandler () noexcept
 
virtual ResponseHandlergetDownstream () 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 ()
 
- Private Member Functions inherited from proxygen::HTTPConnector::Callback
virtual ~Callback ()
 
- Private Member Functions inherited from folly::AsyncSocket::ConnectCallback
virtual ~ConnectCallback ()=default
 
- Private Member Functions inherited from folly::AsyncReader::ReadCallback
virtual ~ReadCallback ()=default
 
virtual bool isBufferMovable () noexcept
 
virtual size_t maxBufferSize () const
 
virtual void readBufferAvailable (std::unique_ptr< IOBuf >) noexcept
 
- Private Member Functions inherited from folly::AsyncWriter::WriteCallback
virtual ~WriteCallback ()=default
 

Private Attributes

ProxyStats *const stats_ {nullptr}
 
proxygen::HTTPConnector connector_
 
ServerTransactionHandler serverHandler_
 
std::unique_ptr< SessionWrappersession_
 
proxygen::HTTPTransactiontxn_ {nullptr}
 
bool clientTerminated_ {false}
 
std::unique_ptr< proxygen::HTTPMessagerequest_
 
std::shared_ptr< folly::AsyncSocketupstreamSock_
 
uint8_t sockStatus_ {0}
 
folly::IOBufQueue body_ {folly::IOBufQueue::cacheChainLength()}
 
bool downstreamIngressPaused_ {false}
 
bool upstreamEgressPaused_ {false}
 

Additional Inherited Members

- Protected Attributes inherited from proxygen::RequestHandler
ResponseHandlerdownstream_ {nullptr}
 

Detailed Description

Definition at line 26 of file ProxyHandler.h.

Constructor & Destructor Documentation

ProxyService::ProxyHandler::ProxyHandler ( ProxyStats stats,
folly::HHWheelTimer timer 
)

Definition at line 39 of file ProxyHandler.cpp.

References serverHandler_.

39  :
40  stats_(stats),
41  connector_{this, timer},
42  serverHandler_(*this) {
43 }
ServerTransactionHandler serverHandler_
Definition: ProxyHandler.h:132
ProxyStats *const stats_
Definition: ProxyHandler.h:130
proxygen::HTTPConnector connector_
Definition: ProxyHandler.h:131
ProxyService::ProxyHandler::~ProxyHandler ( )
override

Definition at line 45 of file ProxyHandler.cpp.

45  {
46  VLOG(4) << "deleting ProxyHandler";
47 }

Member Function Documentation

void ProxyService::ProxyHandler::abortDownstream ( )
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().

218  {
219  if (!clientTerminated_) {
221  }
222 }
virtual void sendAbort() noexcept=0
ResponseHandler * downstream_
bool ProxyService::ProxyHandler::checkForShutdown ( )
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().

224  {
225  if (clientTerminated_ && !txn_ &&
226  (!upstreamSock_ || (sockStatus_ == CLOSED && !upstreamEgressPaused_))) {
227  delete this;
228  return true;
229  }
230  return false;
231 }
proxygen::HTTPTransaction * txn_
Definition: ProxyHandler.h:134
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
void ProxyService::ProxyHandler::connectErr ( const folly::AsyncSocketException ex)
overrideprivatevirtualnoexcept

connectErr() will be invoked if the connection attempt fails.

Parameters
exAn exception describing the error that occurred.

Implements folly::AsyncSocket::ConnectCallback.

Definition at line 242 of file ProxyHandler.cpp.

References connectError().

242  {
243  connectError(ex);
244 }
void connectError(const folly::AsyncSocketException &ex) override
void ProxyService::ProxyHandler::connectError ( const folly::AsyncSocketException ex)
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().

130  {
131  LOG(ERROR) << "Failed to connect: " << folly::exceptionStr(ex);
132  if (!clientTerminated_) {
134  .status(503, "Bad Gateway")
135  .sendWithEOM();
136  } else {
137  abortDownstream();
139  }
140 }
ResponseBuilder & status(uint16_t code, const std::string &message)
fbstring exceptionStr(const std::exception &e)
ResponseHandler * downstream_
void ProxyService::ProxyHandler::connectSuccess ( proxygen::HTTPUpstreamSession session)
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_.

120  {
121  LOG(INFO) << "Established " << *session;
122  session_ = std::make_unique<SessionWrapper>(session);
123  txn_ = session->newTransaction(&serverHandler_);
124  LOG(INFO) << "Forwarding client request: " << request_->getURL()
125  << " to server";
126  txn_->sendHeaders(*request_);
128 }
HTTPTransaction * newTransaction(HTTPTransaction::Handler *handler) override
proxygen::HTTPTransaction * txn_
Definition: ProxyHandler.h:134
ServerTransactionHandler serverHandler_
Definition: ProxyHandler.h:132
std::unique_ptr< SessionWrapper > session_
Definition: ProxyHandler.h:133
std::unique_ptr< proxygen::HTTPMessage > request_
Definition: ProxyHandler.h:137
virtual void resumeIngress() noexcept=0
ResponseHandler * downstream_
void ProxyService::ProxyHandler::connectSuccess ( )
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_.

233  {
234  LOG(INFO) << "Connected to upstream " << upstreamSock_;
236  .status(200, "OK")
237  .send();
238  upstreamSock_->setReadCB(this);
240 }
ResponseBuilder & status(uint16_t code, const std::string &message)
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
virtual void resumeIngress() noexcept=0
ResponseHandler * downstream_
void ProxyService::ProxyHandler::detachServerTransaction ( )
noexcept

Definition at line 163 of file ProxyHandler.cpp.

References checkForShutdown(), and txn_.

Referenced by ProxyService::ProxyHandler::ServerTransactionHandler::detachTransaction().

163  {
164  txn_ = nullptr;
166 }
proxygen::HTTPTransaction * txn_
Definition: ProxyHandler.h:134
void ProxyService::ProxyHandler::getReadBuffer ( void **  bufReturn,
size_t *  lenReturn 
)
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.)

Parameters
bufReturngetReadBuffer() should update *bufReturn to contain the address of the read buffer. This parameter will never be nullptr.
lenReturngetReadBuffer() 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().

246  {
247  std::pair<void*,uint32_t> readSpace = body_.preallocate(kMinReadSize,
248  kMaxReadSize);
249  *bufReturn = readSpace.first;
250  *lenReturn = readSpace.second;
251 }
static const uint32_t kMaxReadSize
static const uint32_t kMinReadSize
std::pair< void *, std::size_t > preallocate(std::size_t min, std::size_t newAllocationSize, std::size_t max=std::numeric_limits< std::size_t >::max())
Definition: IOBufQueue.h:356
folly::IOBufQueue body_
Definition: ProxyHandler.h:142
void ProxyService::ProxyHandler::onBody ( std::unique_ptr< folly::IOBuf body)
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_.

89  {
90  if (txn_) {
91  LOG(INFO) << "Forwarding " <<
92  ((body) ? body->computeChainDataLength() : 0) << " body bytes to server";
93  txn_->sendBody(std::move(body));
94  } else if (upstreamSock_) {
95  upstreamEgressPaused_ = true;
96  upstreamSock_->writeChain(this, std::move(body));
100  }
101  } else {
102  LOG(WARNING) << "Dropping " <<
103  ((body) ? body->computeChainDataLength() : 0) << " body bytes to server";
104  }
105 }
void onServerEgressPaused() noexcept
proxygen::HTTPTransaction * txn_
Definition: ProxyHandler.h:134
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void sendBody(std::unique_ptr< folly::IOBuf > body)
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
void ProxyService::ProxyHandler::onEgressPaused ( )
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_.

202  {
203  if (txn_) {
204  txn_->pauseIngress();
205  } else if (upstreamSock_) {
206  upstreamSock_->setReadCB(nullptr);
207  }
208 }
proxygen::HTTPTransaction * txn_
Definition: ProxyHandler.h:134
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
void ProxyService::ProxyHandler::onEgressResumed ( )
overridevirtualnoexcept

Reimplemented from proxygen::RequestHandler.

Definition at line 210 of file ProxyHandler.cpp.

References proxygen::HTTPTransaction::resumeIngress(), txn_, and upstreamSock_.

210  {
211  if (txn_) {
212  txn_->resumeIngress();
213  } else if (upstreamSock_) {
214  upstreamSock_->setReadCB(this);
215  }
216 }
proxygen::HTTPTransaction * txn_
Definition: ProxyHandler.h:134
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
void ProxyService::ProxyHandler::onEOM ( )
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_.

107  {
108  if (txn_) {
109  LOG(INFO) << "Forwarding client EOM to server";
110  txn_->sendEOM();
111  } else if (upstreamSock_) {
112  LOG(INFO) << "Closing upgraded socket";
113  sockStatus_ |= WRITES_SHUTDOWN;
114  upstreamSock_->shutdownWrite();
115  } else {
116  LOG(INFO) << "Dropping client EOM to server";
117  }
118 }
proxygen::HTTPTransaction * txn_
Definition: ProxyHandler.h:134
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
void ProxyService::ProxyHandler::onError ( proxygen::ProxygenError  err)
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_.

190  {
191  LOG(ERROR) << "Client error: " << proxygen::getErrorString(err);
192  clientTerminated_ = true;
193  if (txn_) {
194  LOG(ERROR) << "Aborting server txn: " << *txn_;
195  txn_->sendAbort();
196  } else if (upstreamSock_) {
197  upstreamSock_.reset();
198  }
200 }
proxygen::HTTPTransaction * txn_
Definition: ProxyHandler.h:134
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
const char * getErrorString(ProxygenError error)
void ProxyService::ProxyHandler::onRequest ( std::unique_ptr< proxygen::HTTPMessage headers)
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_.

49  {
50  // This HTTP proxy does not obey the rules in the spec, such as stripping
51  // hop-by-hop headers. Example only!
52 
54  request_ = std::move(headers);
55  proxygen::URL url(request_->getURL());
56 
58  try {
59  // Note, this does a synchronous DNS lookup which is bad in event driven
60  // code
61  addr.setFromHostPort(url.getHost(), url.getPort());
62  } catch (...) {
64  .status(503, "Bad Gateway")
65  .body(folly::to<string>("Could not parse server from URL: ",
66  request_->getURL()))
67  .sendWithEOM();
68  return;
69  }
70 
71 
73  LOG(INFO) << "Trying to connect to " << addr;
75  if (request_->getMethod() == HTTPMethod::CONNECT) {
77  upstreamSock_->connect(this, addr, FLAGS_proxy_connect_timeout);
78  } else {
79  // A more sophisticated proxy would have a connection pool here
81  {{SOL_SOCKET, SO_REUSEADDR}, 1}};
84  std::chrono::milliseconds(FLAGS_proxy_connect_timeout),
85  opts);
86  }
87 }
ResponseBuilder & status(uint16_t code, const std::string &message)
EventBase * getEventBase() const
ProxyStats *const stats_
Definition: ProxyHandler.h:130
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
EventBase * getEventBase()
ResponseBuilder & body(std::unique_ptr< folly::IOBuf > bodyIn)
std::unique_ptr< proxygen::HTTPMessage > request_
Definition: ProxyHandler.h:137
static EventBaseManager * get()
std::map< OptionKey, int > OptionMap
Definition: AsyncSocket.h:376
proxygen::HTTPConnector connector_
Definition: ProxyHandler.h:131
virtual void recordRequest()
Definition: ProxyStats.h:29
static std::shared_ptr< AsyncSocket > newSocket(EventBase *evb)
Definition: AsyncSocket.h:281
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())
virtual void pauseIngress() noexcept=0
ResponseHandler * downstream_
ThreadPoolListHook * addr
void ProxyService::ProxyHandler::onServerBody ( std::unique_ptr< folly::IOBuf chain)
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().

149  {
150  CHECK(!clientTerminated_);
151  LOG(INFO) << "Forwarding " <<
152  ((chain) ? chain->computeChainDataLength() : 0) << " body bytes to client";
153  downstream_->sendBody(std::move(chain));
154 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void sendBody(std::unique_ptr< folly::IOBuf > body) noexcept=0
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
ResponseHandler * downstream_
void ProxyService::ProxyHandler::onServerEgressPaused ( )
noexcept
void ProxyService::ProxyHandler::onServerEgressResumed ( )
noexcept
void ProxyService::ProxyHandler::onServerEOM ( )
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().

156  {
157  if (!clientTerminated_) {
158  LOG(INFO) << "Forwarding server EOM to client";
159  downstream_->sendEOM();
160  }
161 }
virtual void sendEOM() noexcept=0
ResponseHandler * downstream_
void ProxyService::ProxyHandler::onServerError ( const proxygen::HTTPException error)
noexcept

Definition at line 168 of file ProxyHandler.cpp.

References abortDownstream(), proxygen::ERROR, and folly::pushmi::operators::error().

Referenced by ProxyService::ProxyHandler::ServerTransactionHandler::onError().

168  {
169  LOG(ERROR) << "Server error: " << error;
170  abortDownstream();
171 }
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
void ProxyService::ProxyHandler::onServerHeadersComplete ( std::unique_ptr< proxygen::HTTPMessage msg)
noexcept

Definition at line 142 of file ProxyHandler.cpp.

References clientTerminated_, proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::sendHeaders().

Referenced by ProxyService::ProxyHandler::ServerTransactionHandler::onHeadersComplete().

143  {
144  CHECK(!clientTerminated_);
145  LOG(INFO) << "Forwarding " << msg->getStatusCode() << " response to client";
146  downstream_->sendHeaders(*msg);
147 }
uint16_t getStatusCode() const
virtual void sendHeaders(HTTPMessage &msg) noexcept=0
ResponseHandler * downstream_
void ProxyService::ProxyHandler::onUpgrade ( proxygen::UpgradeProtocol  prot)
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().

43 {}
void ProxyService::ProxyHandler::readDataAvailable ( size_t  len)
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().

Parameters
lenThe 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().

253  {
254  body_.postallocate(len);
256 }
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
folly::IOBufQueue body_
Definition: ProxyHandler.h:142
virtual void sendBody(std::unique_ptr< folly::IOBuf > body) noexcept=0
void postallocate(std::size_t n)
Definition: IOBufQueue.h:380
ResponseHandler * downstream_
void ProxyService::ProxyHandler::readEOF ( )
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_.

258  {
259  sockStatus_ |= READS_SHUTDOWN;
260  onServerEOM();
261 }
void ProxyService::ProxyHandler::readErr ( const folly::AsyncSocketException ex)
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.

Parameters
exAn 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_.

263  {
264  LOG(ERROR) << "Server read error: " << folly::exceptionStr(ex);
265  abortDownstream();
266  upstreamSock_.reset();
268 }
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
fbstring exceptionStr(const std::exception &e)
void ProxyService::ProxyHandler::requestComplete ( )
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_.

185  {
186  clientTerminated_ = true;
188 }
void ProxyService::ProxyHandler::writeErr ( size_t  bytesWritten,
const folly::AsyncSocketException ex 
)
overrideprivatevirtualnoexcept

writeError() will be invoked if an error occurs writing the data.

Parameters
bytesWrittenThe number of bytes that were successfull
exAn 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_.

280  {
281  LOG(ERROR) << "Server write error: " << folly::exceptionStr(ex);;
282  upstreamEgressPaused_ = false;
283  abortDownstream();
284  upstreamSock_.reset();
286 }
std::shared_ptr< folly::AsyncSocket > upstreamSock_
Definition: ProxyHandler.h:140
fbstring exceptionStr(const std::exception &e)
void ProxyService::ProxyHandler::writeSuccess ( )
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_.

270  {
271  upstreamEgressPaused_ = false;
273  downstreamIngressPaused_ = false;
275  }
277 }
void onServerEgressResumed() noexcept

Member Data Documentation

folly::IOBufQueue ProxyService::ProxyHandler::body_ {folly::IOBufQueue::cacheChainLength()}
private

Definition at line 142 of file ProxyHandler.h.

Referenced by getReadBuffer(), and readDataAvailable().

bool ProxyService::ProxyHandler::clientTerminated_ {false}
private
proxygen::HTTPConnector ProxyService::ProxyHandler::connector_
private

Definition at line 131 of file ProxyHandler.h.

Referenced by onRequest().

bool ProxyService::ProxyHandler::downstreamIngressPaused_ {false}
private

Definition at line 143 of file ProxyHandler.h.

Referenced by onBody(), and writeSuccess().

std::unique_ptr<proxygen::HTTPMessage> ProxyService::ProxyHandler::request_
private

Definition at line 137 of file ProxyHandler.h.

Referenced by connectSuccess(), and onRequest().

ServerTransactionHandler ProxyService::ProxyHandler::serverHandler_
private

Definition at line 132 of file ProxyHandler.h.

Referenced by connectSuccess(), and ProxyHandler().

std::unique_ptr<SessionWrapper> ProxyService::ProxyHandler::session_
private

Definition at line 133 of file ProxyHandler.h.

Referenced by connectSuccess().

uint8_t ProxyService::ProxyHandler::sockStatus_ {0}
private

Definition at line 141 of file ProxyHandler.h.

Referenced by checkForShutdown(), onEOM(), and readEOF().

ProxyStats* const ProxyService::ProxyHandler::stats_ {nullptr}
private

Definition at line 130 of file ProxyHandler.h.

Referenced by onRequest().

proxygen::HTTPTransaction* ProxyService::ProxyHandler::txn_ {nullptr}
private
bool ProxyService::ProxyHandler::upstreamEgressPaused_ {false}
private

Definition at line 144 of file ProxyHandler.h.

Referenced by checkForShutdown(), onBody(), writeErr(), and writeSuccess().

std::shared_ptr<folly::AsyncSocket> ProxyService::ProxyHandler::upstreamSock_
private

The documentation for this class was generated from the following files: