proxygen
proxygen::HTTPDirectResponseHandler Class Reference

#include <HTTPDirectResponseHandler.h>

Inheritance diagram for proxygen::HTTPDirectResponseHandler:
proxygen::HTTPTransactionHandler

Public Member Functions

 HTTPDirectResponseHandler (unsigned statusCode, const std::string &statusMsg, const HTTPErrorPage *errorPage=nullptr)
 
void forceConnectionClose (bool close)
 
void setTransaction (HTTPTransaction *txn) noexceptoverride
 
void detachTransaction () noexceptoverride
 
void onHeadersComplete (std::unique_ptr< HTTPMessage > msg) noexceptoverride
 
void onBody (std::unique_ptr< folly::IOBuf > chain) noexceptoverride
 
void onTrailers (std::unique_ptr< HTTPHeaders > trailers) noexceptoverride
 
void onEOM () noexceptoverride
 
void onUpgrade (UpgradeProtocol protocol) noexceptoverride
 
void onError (const HTTPException &error) noexceptoverride
 
void onEgressPaused () noexceptoverride
 
void onEgressResumed () noexceptoverride
 
- Public Member Functions inherited from proxygen::HTTPTransactionHandler
virtual void onChunkHeader (size_t) noexcept
 
virtual void onChunkComplete () noexcept
 
virtual void onPushedTransaction (HTTPTransaction *) noexcept
 
virtual void onExTransaction (HTTPTransaction *) noexcept
 
virtual void onGoaway (ErrorCode) noexcept
 
virtual ~HTTPTransactionHandler ()
 

Private Member Functions

 ~HTTPDirectResponseHandler () override
 

Private Attributes

HTTPTransactiontxn_
 
const HTTPErrorPageerrorPage_
 
std::string statusMessage_
 
unsigned statusCode_
 
bool headersSent_:1
 
bool eomSent_:1
 
bool forceConnectionClose_:1
 

Detailed Description

Definition at line 18 of file HTTPDirectResponseHandler.h.

Constructor & Destructor Documentation

proxygen::HTTPDirectResponseHandler::HTTPDirectResponseHandler ( unsigned  statusCode,
const std::string statusMsg,
const HTTPErrorPage errorPage = nullptr 
)
proxygen::HTTPDirectResponseHandler::~HTTPDirectResponseHandler ( )
overrideprivate

Definition at line 33 of file HTTPDirectResponseHandler.cpp.

Referenced by onEgressResumed().

33  {
34 }

Member Function Documentation

void proxygen::HTTPDirectResponseHandler::detachTransaction ( )
overridevirtualnoexcept

Called once after a transaction successfully completes. It will be called even if a read or write error happened earlier. This is a terminal callback, which means that the HTTPTransaction object that gives this call will be invalid after this function completes.

Implements proxygen::HTTPTransactionHandler.

Definition at line 42 of file HTTPDirectResponseHandler.cpp.

Referenced by forceConnectionClose().

42  {
43  delete this;
44 }
void proxygen::HTTPDirectResponseHandler::forceConnectionClose ( bool  close)
inline
void proxygen::HTTPDirectResponseHandler::onBody ( std::unique_ptr< folly::IOBuf chain)
overridevirtualnoexcept

Can be called multiple times per transaction. If you had previously called pauseIngress(), this callback will be delayed until you call resumeIngress().

Implements proxygen::HTTPTransactionHandler.

Definition at line 77 of file HTTPDirectResponseHandler.cpp.

Referenced by forceConnectionClose().

77  {
78  VLOG(4) << "discarding request body";
79 }
void proxygen::HTTPDirectResponseHandler::onEgressPaused ( )
inlineoverridevirtualnoexcept

If the remote side's receive buffer fills up, this callback will be invoked so you can attempt to stop sending to the remote side.

Implements proxygen::HTTPTransactionHandler.

Definition at line 37 of file HTTPDirectResponseHandler.h.

37 {};
void proxygen::HTTPDirectResponseHandler::onEgressResumed ( )
inlineoverridevirtualnoexcept

This callback lets you know that the remote side has resumed reading and you can now continue to send data.

Implements proxygen::HTTPTransactionHandler.

Definition at line 38 of file HTTPDirectResponseHandler.h.

References ~HTTPDirectResponseHandler().

38 {};
void proxygen::HTTPDirectResponseHandler::onEOM ( )
overridevirtualnoexcept

Can be called once per transaction. If you had previously called pauseIngress(), this callback will be delayed until you call resumeIngress(). After this callback is received, there will be no more normal ingress callbacks received (onEgress*() and onError() may still be invoked). The Handler should consider ingress complete after receiving this message. This Transaction is still valid, and work may still occur on it until detachTransaction is called.

Implements proxygen::HTTPTransactionHandler.

Definition at line 87 of file HTTPDirectResponseHandler.cpp.

References eomSent_, proxygen::HTTPTransaction::sendEOM(), and txn_.

Referenced by forceConnectionClose(), and onError().

void proxygen::HTTPDirectResponseHandler::onError ( const HTTPException error)
overridevirtualnoexcept

Can be called at any time before detachTransaction(). This callback implies that an error has occurred. To determine if ingress or egress is affected, check the direciont on the HTTPException. If the direction is INGRESS, it MAY still be possible to send egress.

Implements proxygen::HTTPTransactionHandler.

Definition at line 95 of file HTTPDirectResponseHandler.cpp.

References eomSent_, folly::pushmi::operators::error(), headersSent_, proxygen::HTTPException::INGRESS, proxygen::kErrorTimeout, onEOM(), and onHeadersComplete().

Referenced by forceConnectionClose().

95  {
96  if (error.getDirection() == HTTPException::Direction::INGRESS) {
97  if (error.getProxygenError() == kErrorTimeout) {
98  VLOG(4) << "processing ingress timeout";
99  if (!headersSent_) {
100  onHeadersComplete(nullptr);
101  }
102  if (!eomSent_) {
103  onEOM();
104  }
105  } else {
106  VLOG(4) << "processing ingress error";
107  if (!headersSent_) {
108  onHeadersComplete(nullptr);
109  }
110  if (!eomSent_) {
111  onEOM();
112  }
113  }
114  }
115 }
requires And< SemiMovable< VN >... > &&SemiMovable< E > auto error(E e)
Definition: error.h:48
void onHeadersComplete(std::unique_ptr< HTTPMessage > msg) noexceptoverride
void proxygen::HTTPDirectResponseHandler::onHeadersComplete ( std::unique_ptr< HTTPMessage msg)
overridevirtualnoexcept

Called at most once per transaction. This is usually the first ingress callback. It is possible to get a read error before this however. If you had previously called pauseIngress(), this callback will be delayed until you call resumeIngress().

Implements proxygen::HTTPTransactionHandler.

Definition at line 46 of file HTTPDirectResponseHandler.cpp.

References proxygen::HTTPHeaders::add(), folly::IOBuf::computeChainDataLength(), proxygen::HTTPErrorPage::Page::content, proxygen::HTTPErrorPage::Page::contentType, proxygen::empty_string, errorPage_, forceConnectionClose_, proxygen::HTTPErrorPage::generate(), proxygen::HTTPMessage::getDefaultReason(), proxygen::HTTPMessage::getHeaders(), headersSent_, proxygen::HTTP_HEADER_CONNECTION, proxygen::HTTP_HEADER_CONTENT_LENGTH, proxygen::HTTP_HEADER_CONTENT_TYPE, folly::gen::move, proxygen::HTTPTransaction::sendBody(), proxygen::HTTPTransaction::sendHeaders(), proxygen::HTTPMessage::setHTTPVersion(), proxygen::HTTPMessage::setStatusCode(), proxygen::HTTPMessage::setStatusMessage(), statusCode_, statusMessage_, and txn_.

Referenced by forceConnectionClose(), and onError().

47  {
48  VLOG(4) << "processing request";
49  headersSent_ = true;
50  HTTPMessage response;
51  std::unique_ptr<folly::IOBuf> responseBody;
52  response.setHTTPVersion(1, 1);
53  response.setStatusCode(statusCode_);
54  if (!statusMessage_.empty()) {
55  response.setStatusMessage(statusMessage_);
56  } else {
57  response.setStatusMessage(HTTPMessage::getDefaultReason(statusCode_));
58  }
60  response.getHeaders().add(HTTP_HEADER_CONNECTION, "close");
61  }
62  if (errorPage_) {
63  HTTPErrorPage::Page page = errorPage_->generate(0, statusCode_,
64  statusMessage_, nullptr, empty_string);
65  VLOG(4) << "sending error page with type " << page.contentType;
66  response.getHeaders().add(HTTP_HEADER_CONTENT_TYPE, page.contentType);
67  responseBody = std::move(page.content);
68  }
69  response.getHeaders().add(HTTP_HEADER_CONTENT_LENGTH, folly::to<string>(
70  responseBody ? responseBody->computeChainDataLength() : 0));
71  txn_->sendHeaders(response);
72  if (responseBody) {
73  txn_->sendBody(std::move(responseBody));
74  }
75 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const std::string contentType
Definition: HTTPErrorPage.h:37
virtual void sendBody(std::unique_ptr< folly::IOBuf > body)
virtual void sendHeaders(const HTTPMessage &headers)
virtual Page generate(uint64_t requestID, unsigned httpStatusCode, const std::string &reason, std::unique_ptr< folly::IOBuf > body, const std::string &detailReason) const =0
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
const std::string empty_string
Definition: HTTPHeaders.cpp:23
static const char * getDefaultReason(uint16_t status)
void proxygen::HTTPDirectResponseHandler::onTrailers ( std::unique_ptr< HTTPHeaders trailers)
overridevirtualnoexcept

Can be called any number of times per transaction. If you had previously called pauseIngress(), this callback will be delayed until you call resumeIngress(). Trailers can be received once right before the EOM of a chunked HTTP/1.1 reponse or multiple times per transaction from SPDY and HTTP/2.0 HEADERS frames.

Implements proxygen::HTTPTransactionHandler.

Definition at line 81 of file HTTPDirectResponseHandler.cpp.

Referenced by forceConnectionClose().

82  {
83  VLOG(4) << "discarding request trailers";
84 }
void proxygen::HTTPDirectResponseHandler::onUpgrade ( UpgradeProtocol  protocol)
overridevirtualnoexcept

Can be called once per transaction. If you had previously called pauseIngress(), this callback will be delayed until you call resumeIngress(). After this callback is invoked, further data will be forwarded using the onBody() callback. Once the data transfer is completed (EOF recevied in case of CONNECT), onEOM() callback will be invoked.

Implements proxygen::HTTPTransactionHandler.

Definition at line 92 of file HTTPDirectResponseHandler.cpp.

Referenced by forceConnectionClose().

93  {}
void proxygen::HTTPDirectResponseHandler::setTransaction ( HTTPTransaction txn)
overridevirtualnoexcept

Called once per transaction. This notifies the handler of which transaction it should talk to and will receive callbacks from.

Implements proxygen::HTTPTransactionHandler.

Definition at line 37 of file HTTPDirectResponseHandler.cpp.

References txn_.

Referenced by forceConnectionClose().

37  {
38  txn_ = txn;
39 }

Member Data Documentation

bool proxygen::HTTPDirectResponseHandler::eomSent_
private

Definition at line 48 of file HTTPDirectResponseHandler.h.

Referenced by onEOM(), and onError().

const HTTPErrorPage* proxygen::HTTPDirectResponseHandler::errorPage_
private

Definition at line 44 of file HTTPDirectResponseHandler.h.

Referenced by onHeadersComplete().

bool proxygen::HTTPDirectResponseHandler::forceConnectionClose_
private

Definition at line 49 of file HTTPDirectResponseHandler.h.

Referenced by forceConnectionClose(), and onHeadersComplete().

bool proxygen::HTTPDirectResponseHandler::headersSent_
private

Definition at line 47 of file HTTPDirectResponseHandler.h.

Referenced by onError(), and onHeadersComplete().

unsigned proxygen::HTTPDirectResponseHandler::statusCode_
private

Definition at line 46 of file HTTPDirectResponseHandler.h.

Referenced by onHeadersComplete().

std::string proxygen::HTTPDirectResponseHandler::statusMessage_
private

Definition at line 45 of file HTTPDirectResponseHandler.h.

Referenced by onHeadersComplete().

HTTPTransaction* proxygen::HTTPDirectResponseHandler::txn_
private

Definition at line 43 of file HTTPDirectResponseHandler.h.

Referenced by onEOM(), onHeadersComplete(), and setTransaction().


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