proxygen
PushService::PushRequestHandler Class Reference

#include <PushRequestHandler.h>

Inheritance diagram for PushService::PushRequestHandler:
proxygen::RequestHandler

Public Member Functions

 PushRequestHandler (PushStats *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

PushStats *const stats_ {nullptr}
 
std::unique_ptr< folly::IOBufbody_
 
proxygen::ResponseHandlerdownstreamPush_ {nullptr}
 

Additional Inherited Members

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

Detailed Description

Definition at line 23 of file PushRequestHandler.h.

Constructor & Destructor Documentation

PushService::PushRequestHandler::PushRequestHandler ( PushStats stats)
explicit

Definition at line 40 of file PushRequestHandler.cpp.

References PushService::gPushBody, PushService::kPushFileName(), and folly::readFile().

40  : stats_(stats) {
41  if (gPushBody.empty()) {
42  CHECK(folly::readFile(kPushFileName.c_str(), gPushBody))
43  << "Failed to read push file=" << kPushFileName;
44  }
45 }
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
Definition: FileUtil.h:125
std::string gPushBody
const std::string kPushFileName("proxygen/httpserver/samples/push/pusheen.txt")

Member Function Documentation

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

Invoked when we get part of body for the request.

Implements proxygen::RequestHandler.

Definition at line 85 of file PushRequestHandler.cpp.

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

85  {
86  if (body_) {
87  body_->prependChain(std::move(body));
88  } else {
89  body_ = std::move(body);
90  }
91 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > body_
void PushService::PushRequestHandler::onEOM ( )
overridevirtualnoexcept

Invoked when we finish receiving the body.

Implements proxygen::RequestHandler.

Definition at line 93 of file PushRequestHandler.cpp.

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

93  {
95  .status(200, "OK")
96  .header("Request-Number",
97  folly::to<std::string>(stats_->getRequestCount()))
99  .sendWithEOM();
100 }
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)
virtual uint64_t getRequestCount()
Definition: PushStats.h:33
std::unique_ptr< folly::IOBuf > body_
ResponseBuilder & header(const std::string &headerIn, const T &value)
ResponseHandler * downstream_
void PushService::PushRequestHandler::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 110 of file PushRequestHandler.cpp.

110  {
111  delete this;
112 }
void PushService::PushRequestHandler::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 47 of file PushRequestHandler.cpp.

References proxygen::ResponseBuilder::body(), PushService::createLargeBody(), proxygen::RequestHandler::downstream_, downstreamPush_, PushService::generateUrl(), proxygen::HTTP_HEADER_HOST, proxygen::ResponseHandler::newPushedResponse(), proxygen::ResponseBuilder::promise(), PushService::PushStats::recordRequest(), folly::netops::send(), proxygen::ResponseBuilder::sendWithEOM(), stats_, and proxygen::ResponseBuilder::status().

48  {
50  if (!headers->getHeaders().getSingleOrEmpty("X-PushIt").empty()) {
52  if (!downstreamPush_) {
53  // can't push
54  return;
55  }
56 
57  if(headers->getPath() == "/requestLargePush") {
58  LOG(INFO) << "sending large push ";
59 
61  .promise(generateUrl(*headers, "/largePush"),
63  .send();
64 
66  .status(200, "OK")
68  .sendWithEOM();
69  } else {
70  LOG(INFO) << "sending small push ";
71 
73  .promise(generateUrl(*headers, "/pusheen"),
75  .send();
76 
78  .status(200, "OK")
79  .body(gPushBody)
80  .sendWithEOM();
81  }
82  }
83 }
ResponseBuilder & status(uint16_t code, const std::string &message)
std::string generateUrl(const HTTPMessage &message, const char *path)
const std::string & getPath() const
Definition: HTTPMessage.h:215
virtual void recordRequest()
Definition: PushStats.h:29
proxygen::ResponseHandler * downstreamPush_
ResponseBuilder & body(std::unique_ptr< folly::IOBuf > bodyIn)
std::string gPushBody
ResponseBuilder & promise(const std::string &url, const std::string &host)
ssize_t send(NetworkSocket s, const void *buf, size_t len, int flags)
Definition: NetOps.cpp:319
HTTPHeaders & getHeaders()
Definition: HTTPMessage.h:273
const std::string & getSingleOrEmpty(const T &nameOrCode) const
Definition: HTTPHeaders.h:420
std::string createLargeBody()
ResponseHandler * downstream_
virtual ResponseHandler * newPushedResponse(PushHandler *pushHandler) noexcept=0
void PushService::PushRequestHandler::onUpgrade ( proxygen::UpgradeProtocol  prot)
overridevirtualnoexcept

Invoked when the session has been upgraded to a different protocol

Implements proxygen::RequestHandler.

Definition at line 102 of file PushRequestHandler.cpp.

102  {
103  // handler doesn't support upgrades
104 }
void PushService::PushRequestHandler::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 106 of file PushRequestHandler.cpp.

106  {
107  delete this;
108 }

Member Data Documentation

std::unique_ptr<folly::IOBuf> PushService::PushRequestHandler::body_
private

Definition at line 43 of file PushRequestHandler.h.

Referenced by onBody(), and onEOM().

proxygen::ResponseHandler* PushService::PushRequestHandler::downstreamPush_ {nullptr}
private

Definition at line 45 of file PushRequestHandler.h.

Referenced by onRequest().

PushStats* const PushService::PushRequestHandler::stats_ {nullptr}
private

Definition at line 41 of file PushRequestHandler.h.

Referenced by onEOM(), and onRequest().


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