proxygen
EchoService::EchoHandler Class Reference

#include <EchoHandler.h>

Inheritance diagram for EchoService::EchoHandler:
proxygen::RequestHandler

Public Member Functions

 EchoHandler (EchoStats *stats)
 
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 proto) noexceptoverride
 
void requestComplete () noexceptoverride
 
void onError (proxygen::ProxygenError err) noexceptoverride
 
- Public Member Functions inherited from proxygen::RequestHandler
virtual void setResponseHandler (ResponseHandler *handler) noexcept
 
virtual void onEgressPaused () noexcept
 
virtual void onEgressResumed () noexcept
 
virtual bool canHandleExpect () noexcept
 
virtual ExMessageHandlergetExHandler () noexcept
 
virtual ResponseHandlergetDownstream () noexcept
 
virtual ~RequestHandler ()
 

Private Attributes

EchoStats *const stats_ {nullptr}
 
std::unique_ptr< folly::IOBufbody_
 

Additional Inherited Members

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

Detailed Description

Definition at line 23 of file EchoHandler.h.

Constructor & Destructor Documentation

EchoHandler::EchoHandler ( EchoStats stats)
explicit

Definition at line 21 of file EchoHandler.cpp.

21  : stats_(stats) {
22 }
EchoStats *const stats_
Definition: EchoHandler.h:41

Member Function Documentation

void EchoHandler::onBody ( std::unique_ptr< folly::IOBuf body)
overridevirtualnoexcept

Invoked when we get part of body for the request.

Implements proxygen::RequestHandler.

Definition at line 28 of file EchoHandler.cpp.

References body_, and folly::gen::move.

28  {
29  if (body_) {
30  body_->prependChain(std::move(body));
31  } else {
32  body_ = std::move(body);
33  }
34 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > body_
Definition: EchoHandler.h:43
void EchoHandler::onEOM ( )
overridevirtualnoexcept

Invoked when we finish receiving the body.

Implements proxygen::RequestHandler.

Definition at line 36 of file EchoHandler.cpp.

References proxygen::ResponseBuilder::body(), body_, proxygen::RequestHandler::downstream_, EchoService::EchoStats::getRequestCount(), proxygen::ResponseBuilder::header(), folly::gen::move, proxygen::ResponseBuilder::sendWithEOM(), stats_, and proxygen::ResponseBuilder::status().

36  {
38  .status(200, "OK")
39  .header("Request-Number",
40  folly::to<std::string>(stats_->getRequestCount()))
42  .sendWithEOM();
43 }
ResponseBuilder & status(uint16_t code, const std::string &message)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
ResponseBuilder & body(std::unique_ptr< folly::IOBuf > bodyIn)
std::unique_ptr< folly::IOBuf > body_
Definition: EchoHandler.h:43
EchoStats *const stats_
Definition: EchoHandler.h:41
ResponseBuilder & header(const std::string &headerIn, const T &value)
virtual uint64_t getRequestCount()
Definition: EchoStats.h:33
ResponseHandler * downstream_
void EchoHandler::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 53 of file EchoHandler.cpp.

53 { delete this; }
void EchoHandler::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 24 of file EchoHandler.cpp.

References EchoService::EchoStats::recordRequest(), and stats_.

24  {
26 }
virtual void recordRequest()
Definition: EchoStats.h:29
EchoStats *const stats_
Definition: EchoHandler.h:41
void EchoHandler::onUpgrade ( proxygen::UpgradeProtocol  prot)
overridevirtualnoexcept

Invoked when the session has been upgraded to a different protocol

Implements proxygen::RequestHandler.

Definition at line 45 of file EchoHandler.cpp.

45  {
46  // handler doesn't support upgrades
47 }
void EchoHandler::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 49 of file EchoHandler.cpp.

49  {
50  delete this;
51 }

Member Data Documentation

std::unique_ptr<folly::IOBuf> EchoService::EchoHandler::body_
private

Definition at line 43 of file EchoHandler.h.

Referenced by onBody(), and onEOM().

EchoStats* const EchoService::EchoHandler::stats_ {nullptr}
private

Definition at line 41 of file EchoHandler.h.

Referenced by onEOM(), and onRequest().


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