proxygen
|
#include <ResponseBuilder.h>
Public Types | |
enum | UpgradeType { UpgradeType::CONNECT_REQUEST = 0, UpgradeType::HTTP_UPGRADE } |
Public Member Functions | |
ResponseBuilder (ResponseHandler *txn) | |
ResponseBuilder & | promise (const std::string &url, const std::string &host) |
ResponseBuilder & | status (uint16_t code, const std::string &message) |
template<typename T > | |
ResponseBuilder & | header (const std::string &headerIn, const T &value) |
template<typename T > | |
ResponseBuilder & | header (HTTPHeaderCode code, const T &value) |
ResponseBuilder & | body (std::unique_ptr< folly::IOBuf > bodyIn) |
template<typename T > | |
ResponseBuilder & | body (T &&t) |
ResponseBuilder & | closeConnection () |
ResponseBuilder & | trailers (const HTTPHeaders &trailers) |
void | sendWithEOM () |
void | send () |
void | acceptUpgradeRequest (UpgradeType upgradeType, const std::string upgradeProtocol="") |
void | rejectUpgradeRequest () |
ResponseBuilder & | setEgressWebsocketHeaders () |
Private Attributes | |
ResponseHandler *const | txn_ {nullptr} |
std::unique_ptr< HTTPMessage > | headers_ |
std::unique_ptr< folly::IOBuf > | body_ |
std::unique_ptr< HTTPHeaders > | trailers_ |
bool | sendEOM_ {false} |
Helps you make responses and send them on demand.
NOTE: We don't do any correctness checks here, we depend on state machine in HTTPTransaction to tell us when an error occurs
Three expected use cases are
ResponseBuilder(handler) .status(200, "OK") .body(...) .sendWithEOM();
ResponseBuilder(handler) .status(200, "OK") .body(...) .send(); // Without WithEOM
we make it chunked
1 or more time
ResponseBuilder(handler) .body(...) .send();
At last
ResponseBuilder(handler) .body(...) .sendWithEOM();
ResponseBuilder(handler) .acceptUpgradeRequest() // send '200 OK' without EOM
or
ResponseBuilder(handler) .rejectUpgradeRequest() // send '400 Bad Request'
Definition at line 64 of file ResponseBuilder.h.
|
strong |
Enumerator | |
---|---|
CONNECT_REQUEST | |
HTTP_UPGRADE |
Definition at line 181 of file ResponseBuilder.h.
|
inlineexplicit |
Definition at line 66 of file ResponseBuilder.h.
|
inline |
Definition at line 186 of file ResponseBuilder.h.
References CONNECT_REQUEST, headers_, proxygen::HTTP_HEADER_CONNECTION, proxygen::HTTP_HEADER_UPGRADE, proxygen::ResponseHandler::sendHeaders(), and txn_.
|
inline |
Definition at line 99 of file ResponseBuilder.h.
References body_, and folly::gen::move.
Referenced by body(), ZlibServerFilterTest::exercise_compression(), EchoService::EchoHandler::onEOM(), PushService::PushRequestHandler::onEOM(), proxygen::DirectResponseHandler::onEOM(), proxygen::ScopedHandler< HandlerType >::onEOM(), TestHandlerFactory::TestHandler::onEOM(), StaticService::StaticHandler::onRequest(), PushService::PushRequestHandler::onRequest(), ProxyService::ProxyHandler::onRequest(), and StaticService::StaticHandler::readFile().
|
inline |
Definition at line 112 of file ResponseBuilder.h.
References body(), folly::IOBuf::maybeCopyBuffer(), and folly::pushmi::detail::t.
|
inline |
Definition at line 117 of file ResponseBuilder.h.
References header(), and proxygen::HTTP_HEADER_CONNECTION.
Referenced by proxygen::RequestHandlerAdaptor::onError(), and proxygen::RequestHandlerAdaptor::onHeadersComplete().
|
inline |
Definition at line 86 of file ResponseBuilder.h.
References headers_.
Referenced by closeConnection(), ZlibServerFilterTest::exercise_compression(), PushService::PushRequestHandler::onEOM(), EchoService::EchoHandler::onEOM(), TestHandlerFactory::TestHandler::onEOM(), and TEST_F().
|
inline |
Definition at line 93 of file ResponseBuilder.h.
References headers_.
|
inline |
Definition at line 69 of file ResponseBuilder.h.
References headers_, and proxygen::HTTP_HEADER_HOST.
Referenced by PushService::PushRequestHandler::onRequest().
|
inline |
Definition at line 200 of file ResponseBuilder.h.
References headers_, proxygen::ResponseHandler::sendEOM(), proxygen::ResponseHandler::sendHeaders(), and txn_.
Referenced by proxygen::RejectConnectFilter::onRequest().
|
inline |
Definition at line 131 of file ResponseBuilder.h.
References body_, folly::gen::chunked(), proxygen::ResponseHandler::getTransaction(), headers_, proxygen::HTTP_HEADER_CONTENT_LENGTH, folly::gen::move, SCOPE_EXIT, proxygen::ResponseHandler::sendBody(), proxygen::ResponseHandler::sendChunkHeader(), proxygen::ResponseHandler::sendChunkTerminator(), proxygen::ResponseHandler::sendEOM(), sendEOM_, proxygen::ResponseHandler::sendHeaders(), proxygen::HTTPTransaction::sendTrailers(), trailers_, and txn_.
Referenced by ProxyService::ProxyHandler::connectSuccess(), ZlibServerFilterTest::exercise_compression(), proxygen::RequestHandlerAdaptor::onHeadersComplete(), StaticService::StaticHandler::onRequest(), StaticService::StaticHandler::readFile(), sendWithEOM(), and TEST_F().
|
inline |
Definition at line 126 of file ResponseBuilder.h.
References send(), and sendEOM_.
Referenced by ProxyService::ProxyHandler::connectError(), ZlibServerFilterTest::exercise_compression(), PushService::PushRequestHandler::onEOM(), EchoService::EchoHandler::onEOM(), proxygen::DirectResponseHandler::onEOM(), proxygen::ScopedHandler< HandlerType >::onEOM(), TestHandlerFactory::TestHandler::onEOM(), proxygen::RequestHandlerAdaptor::onError(), proxygen::RequestHandlerAdaptor::onHeadersComplete(), StaticService::StaticHandler::onRequest(), PushService::PushRequestHandler::onRequest(), ProxyService::ProxyHandler::onRequest(), StaticService::StaticHandler::readFile(), and TEST_F().
|
inline |
Definition at line 207 of file ResponseBuilder.h.
References headers_.
|
inline |
Definition at line 77 of file ResponseBuilder.h.
References headers_.
Referenced by ProxyService::ProxyHandler::connectError(), ProxyService::ProxyHandler::connectSuccess(), ZlibServerFilterTest::exercise_compression(), PushService::PushRequestHandler::onEOM(), EchoService::EchoHandler::onEOM(), proxygen::DirectResponseHandler::onEOM(), proxygen::ScopedHandler< HandlerType >::onEOM(), TestHandlerFactory::TestHandler::onEOM(), proxygen::RequestHandlerAdaptor::onError(), proxygen::RequestHandlerAdaptor::onHeadersComplete(), StaticService::StaticHandler::onRequest(), PushService::PushRequestHandler::onRequest(), ProxyService::ProxyHandler::onRequest(), and TEST_F().
|
inline |
Definition at line 121 of file ResponseBuilder.h.
References trailers_.
|
private |
Definition at line 216 of file ResponseBuilder.h.
|
private |
Definition at line 215 of file ResponseBuilder.h.
Referenced by acceptUpgradeRequest(), header(), promise(), rejectUpgradeRequest(), send(), setEgressWebsocketHeaders(), and status().
|
private |
Definition at line 220 of file ResponseBuilder.h.
Referenced by send(), and sendWithEOM().
|
private |
Definition at line 217 of file ResponseBuilder.h.
Referenced by send(), and trailers().
|
private |
Definition at line 213 of file ResponseBuilder.h.
Referenced by acceptUpgradeRequest(), rejectUpgradeRequest(), and send().