proxygen
proxygen::HTTPCodec Class Referenceabstract

#include <HTTPCodec.h>

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

Classes

class  Callback
 
struct  ExAttributes
 
class  PriorityQueue
 

Public Types

using StreamID = uint64_t
 

Public Member Functions

virtual ~HTTPCodec ()
 
virtual HPACKTableInfo getHPACKTableInfo () const
 
virtual CodecProtocol getProtocol () const =0
 
virtual const std::stringgetUserAgent () const =0
 
virtual TransportDirection getTransportDirection () const =0
 
virtual bool supportsStreamFlowControl () const
 
virtual bool supportsSessionFlowControl () const
 
virtual StreamID createStream ()=0
 
virtual void setCallback (Callback *callback)=0
 
virtual bool isBusy () const =0
 
virtual void setParserPaused (bool paused)=0
 
virtual size_t onIngress (const folly::IOBuf &buf)=0
 
virtual void onIngressEOF ()=0
 
virtual bool onIngressUpgradeMessage (const HTTPMessage &)
 
virtual bool isReusable () const =0
 
virtual bool isWaitingToDrain () const =0
 
virtual bool closeOnEgressComplete () const =0
 
virtual bool supportsParallelRequests () const =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 enableDoubleGoawayDrain ()
 
virtual void setHeaderCodecStats (HeaderCodec::Stats *)
 
virtual StreamID getLastIncomingStreamID () const
 
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
 

Static Public Attributes

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

Interface for a parser&generator that can translate between an internal representation of an HTTP request and a wire format. The details of the wire format (e.g., HTTP/1.x encoding vs. SPDY encoding) are left for subclasses to implement.

Definition at line 36 of file HTTPCodec.h.

Member Typedef Documentation

Key that uniquely identifies a request/response pair within (and only within) the scope of the codec. Code outside the codec should regard the StreamID as an opaque data structure; different subclasses of HTTPCodec are likely to use different conventions for generating StreamID values.

A value of zero indicates an uninitialized/unknown/unspecified StreamID.

Definition at line 49 of file HTTPCodec.h.

Constructor & Destructor Documentation

virtual proxygen::HTTPCodec::~HTTPCodec ( )
inlinevirtual

Definition at line 332 of file HTTPCodec.h.

332 {}

Member Function Documentation

virtual size_t proxygen::HTTPCodec::addPriorityNodes ( PriorityQueue ,
folly::IOBufQueue ,
uint8_t   
)
inlinevirtual

Create virtual nodes in HTTP/2 priority tree. Some protocols (SPDY) have a linear priority structure which must be simulated in the HTTP/2 tree structure with "virtual" nodes representing different priority bands. There are other cases we simply want a "plain" linear priority structure even with HTTP/2. In that case a Priority frame will also be sent out for each virtual node created so that peer will have the same linear structure.

Parameters
queuethe priority queue to add nodes
writeBufIOBufQueue to append priority frames to send. For SPDY, the writeBuf will be ignored.
maxLavelthe max level of virtual priority nodes to create. For SPDY, this value will be ignored.

Reimplemented in proxygen::HTTP2Codec, and proxygen::SPDYCodec.

Definition at line 696 of file HTTPCodec.h.

Referenced by proxygen::MockHTTPCodec::generateCertificate(), proxygen::HTTPDownstreamSession::onNativeProtocolUpgrade(), proxygen::HTTPUpstreamSession::onNativeProtocolUpgrade(), proxygen::HTTPDownstreamSession::startNow(), and proxygen::HTTPUpstreamSession::startNow().

699  {
700  return 0;
701  }
virtual bool proxygen::HTTPCodec::closeOnEgressComplete ( ) const
pure virtual

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

Implemented in proxygen::HTTP1xCodec, and proxygen::HTTPParallelCodec.

Referenced by onIngressUpgradeMessage(), and proxygen::HTTPSession::shutdownTransport().

virtual void proxygen::HTTPCodec::enableDoubleGoawayDrain ( )
inlinevirtual

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

Reimplemented in proxygen::HTTPParallelCodec.

Definition at line 665 of file HTTPCodec.h.

Referenced by proxygen::HTTPSession::enableDoubleGoawayDrain(), and proxygen::MockHTTPCodec::generateCertificate().

665 {}
virtual size_t proxygen::HTTPCodec::generateBody ( folly::IOBufQueue writeBuf,
StreamID  stream,
std::unique_ptr< folly::IOBuf chain,
folly::Optional< uint8_t padding,
bool  eom 
)
pure virtual

Write part of an egress message body.

This will automatically generate a chunk header and footer around the data if necessary (e.g. you haven't manually sent a chunk header and the message should be chunked).

Parameters
paddingOptionally add padding bytes to the body if possible
eomimplicitly generate the EOM marker with this body frame
Returns
number of bytes written

Implemented in proxygen::HTTP2Codec, proxygen::SPDYCodec, proxygen::HTTP1xCodec, and proxygen::MockHTTPCodec.

Referenced by generateExHeader(), and proxygen::HTTPSession::sendBody().

virtual size_t proxygen::HTTPCodec::generateCertificate ( folly::IOBufQueue ,
uint16_t  ,
std::unique_ptr< folly::IOBuf  
)
inlinevirtual

Reimplemented in proxygen::MockHTTPCodec, and proxygen::HTTP2Codec.

Definition at line 642 of file HTTPCodec.h.

Referenced by proxygen::HTTPSession::onCertificateRequest().

645  {
646  return 0;
647  }
virtual size_t proxygen::HTTPCodec::generateCertificateRequest ( folly::IOBufQueue ,
uint16_t  ,
std::unique_ptr< folly::IOBuf  
)
inlinevirtual

Reimplemented in proxygen::HTTP2Codec, and proxygen::MockHTTPCodec.

Definition at line 631 of file HTTPCodec.h.

Referenced by proxygen::HTTPSession::sendCertificateRequest().

634  {
635  return 0;
636  }
virtual size_t proxygen::HTTPCodec::generateChunkHeader ( folly::IOBufQueue writeBuf,
StreamID  stream,
size_t  length 
)
pure virtual
virtual size_t proxygen::HTTPCodec::generateChunkTerminator ( folly::IOBufQueue writeBuf,
StreamID  stream 
)
pure virtual
virtual size_t proxygen::HTTPCodec::generateConnectionPreface ( folly::IOBufQueue )
inlinevirtual

Generate a connection preface, if there is any for this protocol.

Returns
size of the generated message

Reimplemented in proxygen::HTTP2Codec.

Definition at line 475 of file HTTPCodec.h.

References generateHeader(), folly::size(), and fizz::detail::writeBuf().

Referenced by HTTPParallelCodecTest::SetUp(), proxygen::HTTPSession::setupCodec(), and HTTPParallelCodecTest::SetUpUpstreamTest().

475  {
476  return 0;
477  }
virtual size_t proxygen::HTTPCodec::generateEOM ( folly::IOBufQueue writeBuf,
StreamID  stream 
)
pure virtual

Generate any protocol framing needed to finalize an egress message. This method must be called to complete a stream.

Returns
number of bytes written

Implemented in proxygen::HTTP2Codec, proxygen::SPDYCodec, and proxygen::HTTP1xCodec.

Referenced by proxygen::MockHTTPCodec::generateBody(), generateExHeader(), and proxygen::HTTPSession::sendEOM().

virtual void proxygen::HTTPCodec::generateExHeader ( folly::IOBufQueue ,
StreamID  ,
const HTTPMessage ,
const HTTPCodec::ExAttributes ,
bool  ,
HTTPHeaderSize  
)
inlinevirtual
virtual size_t proxygen::HTTPCodec::generateGoaway ( folly::IOBufQueue writeBuf,
StreamID  lastStream,
ErrorCode  code,
std::unique_ptr< folly::IOBuf debugData = nullptr 
)
pure virtual
virtual void proxygen::HTTPCodec::generateHeader ( folly::IOBufQueue writeBuf,
StreamID  stream,
const HTTPMessage msg,
bool  eom = false,
HTTPHeaderSize size = nullptr 
)
pure virtual

Write an egress message header. For pushed streams, you must specify the assocStream.

Return values
sizethe size of the generated message, both the actual size and the size of the uncompressed data.
Returns
None

Implemented in proxygen::SPDYCodec, proxygen::HTTP1xCodec, and proxygen::HTTP2Codec.

Referenced by generateConnectionPreface(), and proxygen::HTTPSession::sendHeaders().

virtual size_t proxygen::HTTPCodec::generatePingReply ( folly::IOBufQueue ,
uint64_t   
)
inlinevirtual

Generate a reply to a ping message, if supported in the protocol implemented by the codec.

Reimplemented in proxygen::HTTP2Codec, and proxygen::SPDYCodec.

Definition at line 584 of file HTTPCodec.h.

Referenced by proxygen::MockHTTPCodec::generateGoaway(), and proxygen::HTTPSession::onPingRequest().

586  { return 0; }
virtual size_t proxygen::HTTPCodec::generatePingRequest ( folly::IOBufQueue )
inlinevirtual

If the protocol supports it, generate a ping message that the other side should respond to.

Reimplemented in proxygen::HTTP2Codec, and proxygen::SPDYCodec.

Definition at line 576 of file HTTPCodec.h.

Referenced by proxygen::MockHTTPCodec::generateGoaway(), and proxygen::HTTPSession::sendPing().

576  {
577  return 0;
578  }
virtual size_t proxygen::HTTPCodec::generatePriority ( folly::IOBufQueue ,
StreamID  ,
const HTTPMessage::HTTPPriority  
)
inlinevirtual

Reimplemented in proxygen::HTTP2Codec.

Definition at line 620 of file HTTPCodec.h.

Referenced by proxygen::HTTPSession::sendPriorityImpl().

623  {
624  return 0;
625  }
virtual void proxygen::HTTPCodec::generatePushPromise ( folly::IOBufQueue ,
StreamID  ,
const HTTPMessage ,
StreamID  ,
bool  ,
HTTPHeaderSize  
)
inlinevirtual

Reimplemented in proxygen::HTTP2Codec, and proxygen::SPDYCodec.

Definition at line 492 of file HTTPCodec.h.

Referenced by proxygen::HTTPSession::sendHeaders().

497  {}
virtual size_t proxygen::HTTPCodec::generateRstStream ( folly::IOBufQueue writeBuf,
StreamID  stream,
ErrorCode  code 
)
pure virtual

Generate any protocol framing needed to abort a stream.

Returns
number of bytes written

Implemented in proxygen::HTTP2Codec, proxygen::SPDYCodec, and proxygen::HTTP1xCodec.

Referenced by proxygen::MockHTTPCodec::generateBody(), generateExHeader(), proxygen::HTTPSession::onNewTransactionParseError(), and proxygen::HTTPSession::sendAbort().

virtual size_t proxygen::HTTPCodec::generateSettings ( folly::IOBufQueue )
inlinevirtual

Generate a settings message, if supported in the protocol implemented by the codec.

Reimplemented in proxygen::HTTP2Codec, and proxygen::SPDYCodec.

Definition at line 592 of file HTTPCodec.h.

Referenced by proxygen::MockHTTPCodec::generateGoaway(), proxygen::HTTPSession::sendSettings(), HTTPParallelCodecTest::SetUpUpstreamTest(), and proxygen::HTTPSession::startNow().

592  {
593  return 0;
594  }
virtual size_t proxygen::HTTPCodec::generateSettingsAck ( folly::IOBufQueue )
inlinevirtual

Generate a settings ack message, if supported in the protocol implemented by the codec.

Reimplemented in proxygen::HTTP2Codec.

Definition at line 600 of file HTTPCodec.h.

Referenced by proxygen::MockHTTPCodec::generateGoaway(), and proxygen::HTTPSession::onSettings().

600  {
601  return 0;
602  }
virtual size_t proxygen::HTTPCodec::generateTrailers ( folly::IOBufQueue writeBuf,
StreamID  stream,
const HTTPHeaders trailers 
)
pure virtual

Write the message trailers

Returns
number of bytes written

Implemented in proxygen::HTTP2Codec, proxygen::SPDYCodec, and proxygen::HTTP1xCodec.

Referenced by proxygen::MockHTTPCodec::generateBody(), generateExHeader(), and proxygen::HTTPSession::sendEOM().

virtual size_t proxygen::HTTPCodec::generateWindowUpdate ( folly::IOBufQueue ,
StreamID  ,
uint32_t   
)
inlinevirtual
virtual uint32_t proxygen::HTTPCodec::getDefaultWindowSize ( ) const
inlinevirtual
virtual HPACKTableInfo proxygen::HTTPCodec::getHPACKTableInfo ( ) const
inlinevirtual

Gets both the egress and ingress header table size, bytes stored in header table, and the number of headers stored in the header table

Reimplemented in proxygen::HTTP2Codec.

Definition at line 338 of file HTTPCodec.h.

References getProtocol(), getTransportDirection(), getUserAgent(), and string.

Referenced by proxygen::HTTPTransaction::onIngressHeadersComplete(), and proxygen::HTTPTransaction::sendHeadersWithOptionalEOM().

338  {
339  HPACKTableInfo defaultHPACKTableInfo;
340  return defaultHPACKTableInfo;
341  }
virtual const HTTPSettings* proxygen::HTTPCodec::getIngressSettings ( ) const
inlinevirtual
virtual StreamID proxygen::HTTPCodec::getLastIncomingStreamID ( ) const
inlinevirtual

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

Reimplemented in proxygen::HTTPParallelCodec.

Definition at line 675 of file HTTPCodec.h.

Referenced by proxygen::HTTPSession::closeWhenIdle(), proxygen::HTTPSession::getGracefulGoawayAck(), proxygen::HTTPSession::onSessionParseError(), and proxygen::HTTPSession::shutdownTransport().

675 { return 0; }
virtual TransportDirection proxygen::HTTPCodec::getTransportDirection ( ) const
pure virtual
virtual const std::string& proxygen::HTTPCodec::getUserAgent ( ) const
pure virtual

Gets the user agent string of the client. Thus, it is only meaningful for a DOWNSTREAM session. Note that the value is available after onHeadersComplete(). It can help in diagnosing the interactions between different codec implementation.

Implemented in proxygen::SPDYCodec, proxygen::HTTP2Codec, and proxygen::HTTP1xCodec.

Referenced by proxygen::HTTPSession::describe(), and getHPACKTableInfo().

virtual bool proxygen::HTTPCodec::isBusy ( ) const
pure virtual

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

Implemented in proxygen::HTTP1xCodec, and proxygen::HTTPParallelCodec.

Referenced by proxygen::HTTPSession::isBusy(), proxygen::HTTPUpstreamSession::isReusable(), and supportsSessionFlowControl().

virtual bool proxygen::HTTPCodec::isReusable ( ) const
pure virtual

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.

Implemented in proxygen::HTTPParallelCodec, and proxygen::HTTP1xCodec.

Referenced by proxygen::HTTPSession::drainImpl(), proxygen::HTTPSession::getGracefulGoawayAck(), proxygen::HTTPUpstreamSession::isReusable(), proxygen::HTTPSession::onEgressMessageFinished(), proxygen::HTTPSession::onError(), proxygen::HTTPSession::onHeadersComplete(), proxygen::HTTPDownstreamSession::onHeadersSent(), onIngressUpgradeMessage(), proxygen::HTTPSession::onMessageComplete(), proxygen::HTTPSession::onNewTransactionParseError(), proxygen::HTTPSession::onWriteSuccess(), proxygen::HTTPSession::sendAbort(), proxygen::HTTPSession::sendHeaders(), and proxygen::HTTPSession::shouldShutdown().

virtual bool proxygen::HTTPCodec::isWaitingToDrain ( ) const
pure virtual

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.

Implemented in proxygen::HTTPParallelCodec, and proxygen::HTTP1xCodec.

Referenced by proxygen::HTTPSession::drainImpl(), proxygen::HTTPSession::getGracefulGoawayAck(), and onIngressUpgradeMessage().

virtual int8_t proxygen::HTTPCodec::mapDependencyToPriority ( StreamID  ) const
inlinevirtual

Map the parent back to the priority, -1 if this doesn't make sense.

Reimplemented in proxygen::SPDYCodec.

Definition at line 713 of file HTTPCodec.h.

713  {
714  return -1;
715  }
virtual StreamID proxygen::HTTPCodec::mapPriorityToDependency ( uint8_t  ) const
inlinevirtual

Map the given linear priority to the correct parent node dependency

Reimplemented in proxygen::HTTP2Codec, and proxygen::SPDYCodec.

Definition at line 706 of file HTTPCodec.h.

Referenced by proxygen::MockHTTPCodec::generateCertificate(), proxygen::HTTPSession::getMessagePriority(), and proxygen::HTTPTransaction::updateAndSendPriority().

706  {
707  return 0;
708  }
virtual size_t proxygen::HTTPCodec::onIngress ( const folly::IOBuf buf)
pure virtual
virtual void proxygen::HTTPCodec::onIngressEOF ( )
pure virtual

Finish parsing when the ingress stream has ended.

Implemented in proxygen::HTTPParallelCodec, and proxygen::HTTP1xCodec.

Referenced by proxygen::HTTPSession::shutdownTransport(), and supportsSessionFlowControl().

virtual bool proxygen::HTTPCodec::onIngressUpgradeMessage ( const HTTPMessage )
inlinevirtual

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 in proxygen::HTTPParallelCodec, and proxygen::HTTP2Codec.

Definition at line 418 of file HTTPCodec.h.

References closeOnEgressComplete(), isReusable(), isWaitingToDrain(), supportsParallelRequests(), and supportsPushTransactions().

418  {
419  return true;
420  }
virtual void proxygen::HTTPCodec::setCallback ( Callback callback)
pure virtual

Set the callback to notify on ingress events

Parameters
callbackThe callback object

Implemented in proxygen::HTTPParallelCodec, and proxygen::HTTP1xCodec.

Referenced by proxygen::PassThroughHTTPCodecFilter::PassThroughHTTPCodecFilter(), and supportsSessionFlowControl().

virtual void proxygen::HTTPCodec::setHeaderCodecStats ( HeaderCodec::Stats )
inlinevirtual

set stats for the header codec, if the protocol supports header compression

Reimplemented in proxygen::HTTP2Codec, and proxygen::SPDYCodec.

Definition at line 670 of file HTTPCodec.h.

Referenced by proxygen::HTTPUpstreamSession::attachThreadLocals(), proxygen::HTTPUpstreamSession::detachThreadLocals(), and proxygen::HTTPSession::setHeaderCodecStats().

670 {}
virtual void proxygen::HTTPCodec::setParserPaused ( bool  paused)
pure virtual
virtual bool proxygen::HTTPCodec::supportsExTransactions ( ) const
inlinevirtual

Check whether the codec supports bidirectional communications between server and client.

Reimplemented in proxygen::HTTP2Codec.

Definition at line 466 of file HTTPCodec.h.

466  {
467  return false;
468  }
virtual bool proxygen::HTTPCodec::supportsPushTransactions ( ) const
pure virtual

Check whether the codec supports pushing resources from server to client.

Implemented in proxygen::HTTP2Codec, proxygen::SPDYCodec, and proxygen::HTTP1xCodec.

Referenced by proxygen::HTTPSession::newPushedTransaction(), and onIngressUpgradeMessage().

virtual bool proxygen::HTTPCodec::supportsSessionFlowControl ( ) const
inlinevirtual

Returns true iff this codec supports session level flow control

Reimplemented in proxygen::SPDYCodec, and proxygen::HTTPParallelCodec.

Definition at line 374 of file HTTPCodec.h.

References createStream(), isBusy(), onIngress(), onIngressEOF(), setCallback(), and setParserPaused().

Referenced by proxygen::HTTPSession::setupCodec().

374  {
375  return false;
376  }
virtual bool proxygen::HTTPCodec::supportsStreamFlowControl ( ) const
inlinevirtual

Returns true iff this codec supports per stream flow control

Reimplemented in proxygen::SPDYCodec, and proxygen::HTTPParallelCodec.

Definition at line 367 of file HTTPCodec.h.

Referenced by proxygen::HTTPSession::createTransaction(), and proxygen::HTTPSession::onNativeProtocolUpgradeImpl().

367  {
368  return false;
369  }

Member Data Documentation

const StreamID proxygen::HTTPCodec::MAX_STREAM_ID = 1u << 31
static
const folly::Optional< uint8_t > proxygen::HTTPCodec::NoPadding = folly::none
static

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