proxygen
proxygen::Filter Class Reference

#include <Filters.h>

Inheritance diagram for proxygen::Filter:
proxygen::RequestHandler proxygen::ResponseHandler DummyFilterFactory::DummyFilter proxygen::RejectConnectFilter proxygen::ZlibServerFilter

Public Member Functions

 Filter (RequestHandler *upstream)
 
void setResponseHandler (ResponseHandler *handler) noexceptoverride
 
void onRequest (std::unique_ptr< HTTPMessage > headers) noexceptoverride
 
void onBody (std::unique_ptr< folly::IOBuf > body) noexceptoverride
 
void onUpgrade (UpgradeProtocol protocol) noexceptoverride
 
void onEOM () noexceptoverride
 
void requestComplete () noexceptoverride
 
void onError (ProxygenError err) noexceptoverride
 
void onEgressPaused () noexceptoverride
 
void onEgressResumed () noexceptoverride
 
bool canHandleExpect () noexceptoverride
 
ExMessageHandlergetExHandler () noexceptoverride
 
void sendHeaders (HTTPMessage &msg) noexceptoverride
 
void sendChunkHeader (size_t len) noexceptoverride
 
void sendBody (std::unique_ptr< folly::IOBuf > body) noexceptoverride
 
void sendChunkTerminator () noexceptoverride
 
void sendEOM () noexceptoverride
 
void sendAbort () noexceptoverride
 
void refreshTimeout () noexceptoverride
 
void pauseIngress () noexceptoverride
 
void resumeIngress () noexceptoverride
 
ResponseHandlernewPushedResponse (PushHandler *handler) noexceptoverride
 
const wangle::TransportInfogetSetupTransportInfo () const noexceptoverride
 
void getCurrentTransportInfo (wangle::TransportInfo *tinfo) const override
 
- Public Member Functions inherited from proxygen::RequestHandler
virtual ResponseHandlergetDownstream () noexcept
 
virtual ~RequestHandler ()
 
- Public Member Functions inherited from proxygen::ResponseHandler
 ResponseHandler (RequestHandler *upstream)
 
virtual ~ResponseHandler ()
 
virtual ResponseHandlernewExMessage (ExMessageHandler *, bool=false) noexcept
 
HTTPTransactiongetTransaction () const noexcept
 

Additional Inherited Members

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

Detailed Description

Filters are a way to add functionality to HTTPServer without complicating app specific RequestHandler. The basic idea is

App-handler <=> Filter-1 <=> Filter-2 <=> Client

The data flows through these filters between client and handler. They can do things like modify the data flowing through them, can update stats, create traces and even send direct response if they feel like.

The default implementation just lets everything pass through.

Definition at line 29 of file Filters.h.

Constructor & Destructor Documentation

proxygen::Filter::Filter ( RequestHandler upstream)
inlineexplicit

Definition at line 31 of file Filters.h.

32  : ResponseHandler(upstream) {
33  }
ResponseHandler(RequestHandler *upstream)

Member Function Documentation

bool proxygen::Filter::canHandleExpect ( )
inlineoverridevirtualnoexcept

Returns true if the handler is responsible for responding to Expect headers, false otherwise.

Reimplemented from proxygen::RequestHandler.

Definition at line 79 of file Filters.h.

References proxygen::RequestHandler::canHandleExpect(), and proxygen::ResponseHandler::upstream_.

79  {
80  return upstream_->canHandleExpect();
81  }
virtual bool canHandleExpect() noexcept
RequestHandler * upstream_
void proxygen::Filter::getCurrentTransportInfo ( wangle::TransportInfo tinfo) const
inlineoverridevirtual

Implements proxygen::ResponseHandler.

Definition at line 132 of file Filters.h.

References proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::getCurrentTransportInfo().

132  {
134  }
virtual void getCurrentTransportInfo(wangle::TransportInfo *tinfo) const =0
ResponseHandler * downstream_
ExMessageHandler* proxygen::Filter::getExHandler ( )
inlineoverridevirtualnoexcept

Implement in control stream handler to support incoming child EX streams.

Reimplemented from proxygen::RequestHandler.

Definition at line 83 of file Filters.h.

References proxygen::RequestHandler::getExHandler(), and proxygen::ResponseHandler::upstream_.

83  {
84  return upstream_->getExHandler();
85  }
virtual ExMessageHandler * getExHandler() noexcept
RequestHandler * upstream_
const wangle::TransportInfo& proxygen::Filter::getSetupTransportInfo ( ) const
inlineoverridevirtualnoexcept

Implements proxygen::ResponseHandler.

Definition at line 128 of file Filters.h.

References proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::getSetupTransportInfo().

128  {
130  }
virtual const wangle::TransportInfo & getSetupTransportInfo() const noexcept=0
ResponseHandler * downstream_
ResponseHandler* proxygen::Filter::newPushedResponse ( PushHandler handler)
inlineoverridevirtualnoexcept

Implements proxygen::ResponseHandler.

Definition at line 124 of file Filters.h.

References proxygen::RequestHandler::downstream_, handler(), and proxygen::ResponseHandler::newPushedResponse().

124  {
126  }
void handler(int, siginfo_t *, void *)
ResponseHandler * downstream_
virtual ResponseHandler * newPushedResponse(PushHandler *pushHandler) noexcept=0
void proxygen::Filter::onBody ( std::unique_ptr< folly::IOBuf body)
inlineoverridevirtualnoexcept

Invoked when we get part of body for the request.

Implements proxygen::RequestHandler.

Definition at line 47 of file Filters.h.

References folly::gen::move, proxygen::RequestHandler::onBody(), and proxygen::ResponseHandler::upstream_.

47  {
48  upstream_->onBody(std::move(body));
49  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
RequestHandler * upstream_
virtual void onBody(std::unique_ptr< folly::IOBuf > body) noexcept=0
void proxygen::Filter::onEgressPaused ( )
inlineoverridevirtualnoexcept

Signals from HTTP layer when client queue is full or empty. If you are sending a streaming response, consider implementing these and acting accordingly. Saves your server from running out of memory.

Reimplemented from proxygen::RequestHandler.

Definition at line 71 of file Filters.h.

References proxygen::RequestHandler::onEgressPaused(), and proxygen::ResponseHandler::upstream_.

71  {
73  }
virtual void onEgressPaused() noexcept
RequestHandler * upstream_
void proxygen::Filter::onEgressResumed ( )
inlineoverridevirtualnoexcept

Reimplemented from proxygen::RequestHandler.

Definition at line 75 of file Filters.h.

References proxygen::RequestHandler::onEgressResumed(), and proxygen::ResponseHandler::upstream_.

75  {
77  }
RequestHandler * upstream_
virtual void onEgressResumed() noexcept
void proxygen::Filter::onEOM ( )
inlineoverridevirtualnoexcept

Invoked when we finish receiving the body.

Implements proxygen::RequestHandler.

Definition at line 55 of file Filters.h.

References proxygen::RequestHandler::onEOM(), and proxygen::ResponseHandler::upstream_.

55  {
56  upstream_->onEOM();
57  }
virtual void onEOM() noexcept=0
RequestHandler * upstream_
void proxygen::Filter::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 65 of file Filters.h.

References proxygen::RequestHandler::downstream_, proxygen::RequestHandler::onError(), and proxygen::ResponseHandler::upstream_.

65  {
66  downstream_ = nullptr;
67  upstream_->onError(err);
68  delete this;
69  }
RequestHandler * upstream_
virtual void onError(ProxygenError err) noexcept=0
ResponseHandler * downstream_
void proxygen::Filter::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 43 of file Filters.h.

References folly::gen::move, proxygen::RequestHandler::onRequest(), and proxygen::ResponseHandler::upstream_.

43  {
44  upstream_->onRequest(std::move(headers));
45  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void onRequest(std::unique_ptr< HTTPMessage > headers) noexcept=0
RequestHandler * upstream_
void proxygen::Filter::onUpgrade ( UpgradeProtocol  prot)
inlineoverridevirtualnoexcept

Invoked when the session has been upgraded to a different protocol

Implements proxygen::RequestHandler.

Definition at line 51 of file Filters.h.

References proxygen::RequestHandler::onUpgrade(), and proxygen::ResponseHandler::upstream_.

51  {
52  upstream_->onUpgrade(protocol);
53  }
RequestHandler * upstream_
virtual void onUpgrade(proxygen::UpgradeProtocol prot) noexcept=0
void proxygen::Filter::pauseIngress ( )
inlineoverridevirtualnoexcept

Implements proxygen::ResponseHandler.

Definition at line 116 of file Filters.h.

References proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::pauseIngress().

116  {
118  }
virtual void pauseIngress() noexcept=0
ResponseHandler * downstream_
void proxygen::Filter::refreshTimeout ( )
inlineoverridevirtualnoexcept

Implements proxygen::ResponseHandler.

Definition at line 112 of file Filters.h.

References proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::refreshTimeout().

112  {
114  }
virtual void refreshTimeout() noexcept=0
ResponseHandler * downstream_
void proxygen::Filter::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 59 of file Filters.h.

References proxygen::RequestHandler::downstream_, proxygen::RequestHandler::requestComplete(), and proxygen::ResponseHandler::upstream_.

59  {
60  downstream_ = nullptr;
62  delete this;
63  }
virtual void requestComplete() noexcept=0
RequestHandler * upstream_
ResponseHandler * downstream_
void proxygen::Filter::resumeIngress ( )
inlineoverridevirtualnoexcept

Implements proxygen::ResponseHandler.

Definition at line 120 of file Filters.h.

References proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::resumeIngress().

120  {
122  }
virtual void resumeIngress() noexcept=0
ResponseHandler * downstream_
void proxygen::Filter::sendAbort ( )
inlineoverridevirtualnoexcept

Implements proxygen::ResponseHandler.

Definition at line 108 of file Filters.h.

References proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::sendAbort().

Referenced by proxygen::ZlibServerFilter::fail().

108  {
110  }
virtual void sendAbort() noexcept=0
ResponseHandler * downstream_
void proxygen::Filter::sendBody ( std::unique_ptr< folly::IOBuf body)
inlineoverridevirtualnoexcept

Implements proxygen::ResponseHandler.

Definition at line 96 of file Filters.h.

References proxygen::RequestHandler::downstream_, folly::gen::move, and proxygen::ResponseHandler::sendBody().

Referenced by proxygen::ZlibServerFilter::sendBody(), and proxygen::ZlibServerFilter::sendEOM().

96  {
98  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void sendBody(std::unique_ptr< folly::IOBuf > body) noexcept=0
ResponseHandler * downstream_
void proxygen::Filter::sendChunkHeader ( size_t  len)
inlineoverridevirtualnoexcept
void proxygen::Filter::sendChunkTerminator ( )
inlineoverridevirtualnoexcept
void proxygen::Filter::sendEOM ( )
inlineoverridevirtualnoexcept

Implements proxygen::ResponseHandler.

Definition at line 104 of file Filters.h.

References proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::sendEOM().

Referenced by proxygen::ZlibServerFilter::sendEOM().

104  {
105  downstream_->sendEOM();
106  }
virtual void sendEOM() noexcept=0
ResponseHandler * downstream_
void proxygen::Filter::sendHeaders ( HTTPMessage msg)
inlineoverridevirtualnoexcept

NOTE: We take response message as non-const reference, to allow filters between your handler and client to be able to modify response if they want to.

eg. a compression filter might want to change the content-encoding

Implements proxygen::ResponseHandler.

Definition at line 88 of file Filters.h.

References proxygen::RequestHandler::downstream_, and proxygen::ResponseHandler::sendHeaders().

Referenced by proxygen::ZlibServerFilter::sendBody(), and proxygen::ZlibServerFilter::sendHeaders().

88  {
90  }
virtual void sendHeaders(HTTPMessage &msg) noexcept=0
ResponseHandler * downstream_
void proxygen::Filter::setResponseHandler ( ResponseHandler handler)
inlineoverridevirtualnoexcept

Saves the downstream handle with itself. Implementations of this interface should use downstream_ to send back response.

XXX: Only override this method if you are ABSOLUTELY sure what you are doing. If possible, just use downstream_ variable and dont mess with these things.

Reimplemented from proxygen::RequestHandler.

Definition at line 36 of file Filters.h.

References proxygen::RequestHandler::downstream_, handler(), proxygen::RequestHandler::setResponseHandler(), proxygen::ResponseHandler::txn_, and proxygen::ResponseHandler::upstream_.

36  {
37  // Save downstream handler and pass ourselves as downstream handler
39  txn_ = handler->getTransaction();
41  }
virtual void setResponseHandler(ResponseHandler *handler) noexcept
HTTPTransaction * txn_
void handler(int, siginfo_t *, void *)
RequestHandler * upstream_
ResponseHandler * downstream_

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