proxygen
proxygen::HTTPParallelCodec Class Reference

#include <HTTPParallelCodec.h>

Inheritance diagram for proxygen::HTTPParallelCodec:
proxygen::HTTPCodec proxygen::HTTP2Codec proxygen::SPDYCodec

Public Member Functions

 HTTPParallelCodec (TransportDirection direction)
 
TransportDirection getTransportDirection () const override
 
StreamID createStream () override
 
bool isBusy () const override
 
bool supportsStreamFlowControl () const override
 
bool supportsSessionFlowControl () const override
 
bool supportsParallelRequests () const override
 
bool closeOnEgressComplete () const override
 
void setCallback (Callback *callback) override
 
void setParserPaused (bool) override
 
void onIngressEOF () override
 
bool isReusable () const override
 
bool isWaitingToDrain () const override
 
StreamID getLastIncomingStreamID () const override
 
void enableDoubleGoawayDrain () override
 
bool onIngressUpgradeMessage (const HTTPMessage &msg) override
 
void setNextEgressStreamId (StreamID nextEgressStreamID)
 
bool isInitiatedStream (StreamID stream) const
 
bool isStreamIngressEgressAllowed (StreamID stream) const
 
- Public Member Functions inherited from proxygen::HTTPCodec
virtual ~HTTPCodec ()
 
virtual HPACKTableInfo getHPACKTableInfo () const
 
virtual CodecProtocol getProtocol () const =0
 
virtual const std::stringgetUserAgent () const =0
 
virtual size_t onIngress (const folly::IOBuf &buf)=0
 
virtual bool supportsPushTransactions () const =0
 
virtual bool supportsExTransactions () const
 
virtual size_t generateConnectionPreface (folly::IOBufQueue &)
 
virtual void generateHeader (folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, bool eom=false, HTTPHeaderSize *size=nullptr)=0
 
virtual void generatePushPromise (folly::IOBufQueue &, StreamID, const HTTPMessage &, StreamID, bool, HTTPHeaderSize *)
 
virtual void generateExHeader (folly::IOBufQueue &, StreamID, const HTTPMessage &, const HTTPCodec::ExAttributes &, bool, HTTPHeaderSize *)
 
virtual size_t generateBody (folly::IOBufQueue &writeBuf, StreamID stream, std::unique_ptr< folly::IOBuf > chain, folly::Optional< uint8_t > padding, bool eom)=0
 
virtual size_t generateChunkHeader (folly::IOBufQueue &writeBuf, StreamID stream, size_t length)=0
 
virtual size_t generateChunkTerminator (folly::IOBufQueue &writeBuf, StreamID stream)=0
 
virtual size_t generateTrailers (folly::IOBufQueue &writeBuf, StreamID stream, const HTTPHeaders &trailers)=0
 
virtual size_t generateEOM (folly::IOBufQueue &writeBuf, StreamID stream)=0
 
virtual size_t generateRstStream (folly::IOBufQueue &writeBuf, StreamID stream, ErrorCode code)=0
 
virtual size_t generateGoaway (folly::IOBufQueue &writeBuf, StreamID lastStream, ErrorCode code, std::unique_ptr< folly::IOBuf > debugData=nullptr)=0
 
virtual size_t generatePingRequest (folly::IOBufQueue &)
 
virtual size_t generatePingReply (folly::IOBufQueue &, uint64_t)
 
virtual size_t generateSettings (folly::IOBufQueue &)
 
virtual size_t generateSettingsAck (folly::IOBufQueue &)
 
virtual size_t generateWindowUpdate (folly::IOBufQueue &, StreamID, uint32_t)
 
virtual size_t generatePriority (folly::IOBufQueue &, StreamID, const HTTPMessage::HTTPPriority &)
 
virtual size_t generateCertificateRequest (folly::IOBufQueue &, uint16_t, std::unique_ptr< folly::IOBuf >)
 
virtual size_t generateCertificate (folly::IOBufQueue &, uint16_t, std::unique_ptr< folly::IOBuf >)
 
virtual HTTPSettingsgetEgressSettings ()
 
virtual const HTTPSettingsgetIngressSettings () const
 
virtual void setHeaderCodecStats (HeaderCodec::Stats *)
 
virtual uint32_t getDefaultWindowSize () const
 
virtual size_t addPriorityNodes (PriorityQueue &, folly::IOBufQueue &, uint8_t)
 
virtual StreamID mapPriorityToDependency (uint8_t) const
 
virtual int8_t mapDependencyToPriority (StreamID) const
 

Protected Types

enum  ClosingState {
  OPEN = 0, OPEN_WITH_GRACEFUL_DRAIN_ENABLED = 1, FIRST_GOAWAY_SENT = 2, CLOSING = 3,
  CLOSED = 4
}
 

Protected Member Functions

template<typename T , typename... Args>
bool deliverCallbackIfAllowed (T callbackFn, char const *cbName, StreamID stream, Args &&...args)
 

Protected Attributes

TransportDirection transportDirection_
 
StreamID nextEgressStreamID_
 
StreamID lastStreamID_ {0}
 
HTTPCodec::Callbackcallback_ {nullptr}
 
StreamID ingressGoawayAck_ {std::numeric_limits<uint32_t>::max()}
 
StreamID egressGoawayAck_ {std::numeric_limits<uint32_t>::max()}
 
std::string goawayErrorMessage_
 
enum proxygen::HTTPParallelCodec::ClosingState sessionClosing_
 

Additional Inherited Members

- Public Types inherited from proxygen::HTTPCodec
using StreamID = uint64_t
 
- Static Public Attributes inherited from proxygen::HTTPCodec
static const folly::Optional< StreamIDNoStream
 
static const folly::Optional< uint8_tNoPadding = folly::none
 
static const StreamID MAX_STREAM_ID = 1u << 31
 
static const folly::Optional< ExAttributesNoExAttributes
 

Detailed Description

An implementation of common codec functionality used for multiple parallel stream downloads. Currently shared by SPDY and HTTP/2

Definition at line 31 of file HTTPParallelCodec.h.

Member Enumeration Documentation

Enumerator
OPEN 
OPEN_WITH_GRACEFUL_DRAIN_ENABLED 
FIRST_GOAWAY_SENT 
CLOSING 
CLOSED 

Definition at line 84 of file HTTPParallelCodec.h.

Constructor & Destructor Documentation

proxygen::HTTPParallelCodec::HTTPParallelCodec ( TransportDirection  direction)
explicit

Definition at line 23 of file HTTPParallelCodec.cpp.

References proxygen::DOWNSTREAM, nextEgressStreamID_, transportDirection_, and proxygen::UPSTREAM.

24  : transportDirection_(direction),
25  sessionClosing_(ClosingState::OPEN) {
26  switch (transportDirection_) {
29  break;
32  break;
33  default:
34  LOG(FATAL) << "Unknown transport direction.";
35  }
36 }
enum proxygen::HTTPParallelCodec::ClosingState sessionClosing_
TransportDirection transportDirection_

Member Function Documentation

bool proxygen::HTTPParallelCodec::closeOnEgressComplete ( ) const
inlineoverridevirtual

Checks whether the socket needs to be closed when EOM is sent. This is used during CONNECT when EOF needs to be sent after upgrade to notify the server

Implements proxygen::HTTPCodec.

Definition at line 44 of file HTTPParallelCodec.h.

44 { return false; }
HTTPCodec::StreamID proxygen::HTTPParallelCodec::createStream ( )
overridevirtual

Reserve a stream ID.

Returns
A stream ID on success, or zero on error.

Implements proxygen::HTTPCodec.

Definition at line 38 of file HTTPParallelCodec.cpp.

References nextEgressStreamID_.

Referenced by proxygen::HTTP2Codec::addPriorityNodes(), TEST(), and TEST_F().

38  {
39  auto ret = nextEgressStreamID_;
41  return ret;
42 }
template<typename T , typename... Args>
bool proxygen::HTTPParallelCodec::deliverCallbackIfAllowed ( T  callbackFn,
char const *  cbName,
StreamID  stream,
Args &&...  args 
)
inlineprotected
void proxygen::HTTPParallelCodec::enableDoubleGoawayDrain ( )
overridevirtual

This enables HTTP/2 style behavior during graceful shutdown that allows 2 GOAWAYs to be sent during shutdown.

Reimplemented from proxygen::HTTPCodec.

Definition at line 58 of file HTTPParallelCodec.cpp.

References sessionClosing_.

Referenced by TEST().

58  {
59  CHECK_EQ(sessionClosing_, ClosingState::OPEN);
60  sessionClosing_ = ClosingState::OPEN_WITH_GRACEFUL_DRAIN_ENABLED;
61 }
enum proxygen::HTTPParallelCodec::ClosingState sessionClosing_
StreamID proxygen::HTTPParallelCodec::getLastIncomingStreamID ( ) const
inlineoverridevirtual

Get the identifier of the last stream started by the remote.

Reimplemented from proxygen::HTTPCodec.

Definition at line 50 of file HTTPParallelCodec.h.

50 { return lastStreamID_; }
TransportDirection proxygen::HTTPParallelCodec::getTransportDirection ( ) const
inlineoverridevirtual

Get the transport direction of this codec: DOWNSTREAM if the codec receives requests from clients or UPSTREAM if the codec sends requests to servers.

Implements proxygen::HTTPCodec.

Definition at line 35 of file HTTPParallelCodec.h.

Referenced by proxygen::HTTP2Codec::generateSettings(), proxygen::HTTP2Codec::generateSettingsAck(), proxygen::HTTP2Codec::handleSettings(), and HTTPParallelCodecTest::parseImpl().

35  {
36  return transportDirection_;
37  }
TransportDirection transportDirection_
bool proxygen::HTTPParallelCodec::isBusy ( ) const
inlineoverridevirtual

Check whether the codec still has at least one HTTP stream to parse.

Implements proxygen::HTTPCodec.

Definition at line 40 of file HTTPParallelCodec.h.

40 { return false; }
bool proxygen::HTTPParallelCodec::isInitiatedStream ( StreamID  stream) const
inline

Definition at line 63 of file HTTPParallelCodec.h.

References odd.

Referenced by proxygen::HTTP2Codec::checkNewStream().

63  {
64  bool odd = stream & 0x01;
66  return (odd && upstream) || (!odd && !upstream);
67  }
auto odd
Definition: CombineTest.cpp:35
TransportDirection transportDirection_
bool proxygen::HTTPParallelCodec::isReusable ( ) const
overridevirtual

Check whether the codec can process new streams. Typically, an implementing subclass will return true when a new codec is created and false once it encounters a situation that would prevent reuse of the underlying transport (e.g., a "Connection: close" in HTTP/1.x).

Note
A return value of true means that the codec can process new connections at some reasonable point in the future; that may mean "immediately," for codecs that support pipelined or interleaved requests, or "upon completion of the current stream" for codecs that do not.

Implements proxygen::HTTPCodec.

Definition at line 49 of file HTTPParallelCodec.cpp.

References proxygen::DOWNSTREAM, ingressGoawayAck_, isWaitingToDrain(), max, nextEgressStreamID_, sessionClosing_, and transportDirection_.

Referenced by TEST(), and TEST_F().

49  {
50  return (sessionClosing_ == ClosingState::OPEN ||
51  sessionClosing_ == ClosingState::OPEN_WITH_GRACEFUL_DRAIN_ENABLED ||
56 }
LogLevel max
Definition: LogLevel.cpp:31
enum proxygen::HTTPParallelCodec::ClosingState sessionClosing_
bool isWaitingToDrain() const override
TransportDirection transportDirection_
bool proxygen::HTTPParallelCodec::isWaitingToDrain ( ) const
overridevirtual

Returns true if this codec is in a state where it accepting new requests but will soon begin to reject new requests. For SPDY and HTTP/2, this is true when the first GOAWAY NO_ERROR is sent during graceful shutdown.

Implements proxygen::HTTPCodec.

Definition at line 44 of file HTTPParallelCodec.cpp.

References sessionClosing_.

Referenced by isReusable(), and TEST().

44  {
45  return sessionClosing_ == ClosingState::OPEN ||
46  sessionClosing_ == ClosingState::FIRST_GOAWAY_SENT;
47 }
enum proxygen::HTTPParallelCodec::ClosingState sessionClosing_
void proxygen::HTTPParallelCodec::onIngressEOF ( )
inlineoverridevirtual

Finish parsing when the ingress stream has ended.

Implements proxygen::HTTPCodec.

Definition at line 47 of file HTTPParallelCodec.h.

47 {}
bool proxygen::HTTPParallelCodec::onIngressUpgradeMessage ( const HTTPMessage )
overridevirtual

Invoked on a codec that has been upgraded to via an HTTPMessage on a different codec. The codec may return false to halt the upgrade.

Reimplemented from proxygen::HTTPCodec.

Definition at line 63 of file HTTPParallelCodec.cpp.

References proxygen::DOWNSTREAM, lastStreamID_, and transportDirection_.

Referenced by proxygen::HTTP2Codec::onIngressUpgradeMessage().

void proxygen::HTTPParallelCodec::setCallback ( Callback callback)
inlineoverridevirtual

Set the callback to notify on ingress events

Parameters
callbackThe callback object

Implements proxygen::HTTPCodec.

Definition at line 45 of file HTTPParallelCodec.h.

References callback_.

Referenced by parseSPDY(), HTTPParallelCodecTest::SetUp(), TEST(), and TEST_F().

45 { callback_ = callback; }
HTTPCodec::Callback * callback_
void proxygen::HTTPParallelCodec::setNextEgressStreamId ( StreamID  nextEgressStreamID)
inline

Definition at line 55 of file HTTPParallelCodec.h.

References max.

Referenced by TEST(), and TEST_F().

55  {
56  if (nextEgressStreamID > nextEgressStreamID_ &&
57  (nextEgressStreamID & 0x1) == (nextEgressStreamID_ & 0x1) &&
59  nextEgressStreamID_ = nextEgressStreamID;
60  }
61  }
LogLevel max
Definition: LogLevel.cpp:31
void proxygen::HTTPParallelCodec::setParserPaused ( bool  paused)
inlineoverridevirtual

Pause or resume the ingress parser

Parameters
pausedWhether the caller wants the parser to be paused

Implements proxygen::HTTPCodec.

Definition at line 46 of file HTTPParallelCodec.h.

46 {}
bool proxygen::HTTPParallelCodec::supportsParallelRequests ( ) const
inlineoverridevirtual

Check whether the codec supports the processing of multiple requests in parallel.

Implements proxygen::HTTPCodec.

Definition at line 43 of file HTTPParallelCodec.h.

43 { return true; }
bool proxygen::HTTPParallelCodec::supportsSessionFlowControl ( ) const
inlineoverridevirtual

Returns true iff this codec supports session level flow control

Reimplemented from proxygen::HTTPCodec.

Reimplemented in proxygen::SPDYCodec.

Definition at line 42 of file HTTPParallelCodec.h.

42 { return true; }
bool proxygen::HTTPParallelCodec::supportsStreamFlowControl ( ) const
inlineoverridevirtual

Returns true iff this codec supports per stream flow control

Reimplemented from proxygen::HTTPCodec.

Reimplemented in proxygen::SPDYCodec.

Definition at line 41 of file HTTPParallelCodec.h.

41 { return true; }

Member Data Documentation

StreamID proxygen::HTTPParallelCodec::egressGoawayAck_ {std::numeric_limits<uint32_t>::max()}
protected
StreamID proxygen::HTTPParallelCodec::lastStreamID_ {0}
protected
StreamID proxygen::HTTPParallelCodec::nextEgressStreamID_
protected

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