proxygen
proxygen::DirectResponseHandler Class Reference

#include <DirectResponseHandler.h>

Inheritance diagram for proxygen::DirectResponseHandler:
proxygen::RequestHandler

Public Member Functions

 DirectResponseHandler (int code, std::string message, std::string body)
 
void onRequest (std::unique_ptr< HTTPMessage >) noexceptoverride
 
void onBody (std::unique_ptr< folly::IOBuf >) noexceptoverride
 
void onUpgrade (proxygen::UpgradeProtocol) noexceptoverride
 
void onEOM () noexceptoverride
 
void requestComplete () noexceptoverride
 
void onError (ProxygenError) 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

const int code_
 
std::string message_
 
std::unique_ptr< folly::IOBufbody_
 

Additional Inherited Members

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

Detailed Description

Handler that sends a fixed response back.

Definition at line 20 of file DirectResponseHandler.h.

Constructor & Destructor Documentation

proxygen::DirectResponseHandler::DirectResponseHandler ( int  code,
std::string  message,
std::string  body 
)
inline

Definition at line 22 of file DirectResponseHandler.h.

25  : code_(code),
28  }
Definition: test.c:42
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > body_
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587

Member Function Documentation

void proxygen::DirectResponseHandler::onBody ( std::unique_ptr< folly::IOBuf body)
inlineoverridevirtualnoexcept

Invoked when we get part of body for the request.

Implements proxygen::RequestHandler.

Definition at line 32 of file DirectResponseHandler.h.

32 {}
void proxygen::DirectResponseHandler::onEOM ( )
inlineoverridevirtualnoexcept

Invoked when we finish receiving the body.

Implements proxygen::RequestHandler.

Definition at line 36 of file DirectResponseHandler.h.

References proxygen::ResponseBuilder::body(), body_, code_, proxygen::RequestHandler::downstream_, message_, folly::gen::move, proxygen::ResponseBuilder::sendWithEOM(), and proxygen::ResponseBuilder::status().

36  {
37  ResponseBuilder(downstream_)
38  .status(code_, std::move(message_))
39  .body(std::move(body_))
40  .sendWithEOM();
41  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > body_
ResponseHandler * downstream_
void proxygen::DirectResponseHandler::onError ( ProxygenError  err)
inlineoverridevirtualnoexcept

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 47 of file DirectResponseHandler.h.

47 { delete this; }
void proxygen::DirectResponseHandler::onRequest ( std::unique_ptr< HTTPMessage headers)
inlineoverridevirtualnoexcept

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 30 of file DirectResponseHandler.h.

30 {}
void proxygen::DirectResponseHandler::onUpgrade ( proxygen::UpgradeProtocol  prot)
inlineoverridevirtualnoexcept

Invoked when the session has been upgraded to a different protocol

Implements proxygen::RequestHandler.

Definition at line 34 of file DirectResponseHandler.h.

34 {}
void proxygen::DirectResponseHandler::requestComplete ( )
inlineoverridevirtualnoexcept

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 43 of file DirectResponseHandler.h.

43  {
44  delete this;
45  }

Member Data Documentation

std::unique_ptr<folly::IOBuf> proxygen::DirectResponseHandler::body_
private

Definition at line 52 of file DirectResponseHandler.h.

Referenced by onEOM().

const int proxygen::DirectResponseHandler::code_
private

Definition at line 50 of file DirectResponseHandler.h.

Referenced by onEOM().

std::string proxygen::DirectResponseHandler::message_
private

Definition at line 51 of file DirectResponseHandler.h.

Referenced by onEOM().


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