proxygen
proxygen::HTTP2Codec Class Reference

#include <HTTP2Codec.h>

Inheritance diagram for proxygen::HTTP2Codec:
proxygen::HTTPParallelCodec proxygen::HPACK::StreamingCallback proxygen::HTTPCodec

Public Member Functions

void onHeader (const folly::fbstring &name, const folly::fbstring &value) override
 
void onHeadersComplete (HTTPHeaderSize decodedSize) override
 
void onDecodeError (HPACK::DecodeError decodeError) override
 
 HTTP2Codec (TransportDirection direction)
 
 ~HTTP2Codec () override
 
CodecProtocol getProtocol () const override
 
const std::stringgetUserAgent () const override
 
size_t onIngress (const folly::IOBuf &buf) override
 
bool onIngressUpgradeMessage (const HTTPMessage &msg) override
 
size_t generateConnectionPreface (folly::IOBufQueue &writeBuf) override
 
void generateHeader (folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, bool eom=false, HTTPHeaderSize *size=nullptr) override
 
void generateContinuation (folly::IOBufQueue &writeBuf, folly::IOBufQueue &queue, StreamID stream, size_t maxFrameSize)
 
void generatePushPromise (folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, StreamID assocStream, bool eom=false, HTTPHeaderSize *size=nullptr) override
 
void generateExHeader (folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, const HTTPCodec::ExAttributes &exAttributes, bool eom=false, HTTPHeaderSize *size=nullptr) override
 
size_t generateBody (folly::IOBufQueue &writeBuf, StreamID stream, std::unique_ptr< folly::IOBuf > chain, folly::Optional< uint8_t > padding, bool eom) override
 
size_t generateChunkHeader (folly::IOBufQueue &writeBuf, StreamID stream, size_t length) override
 
size_t generateChunkTerminator (folly::IOBufQueue &writeBuf, StreamID stream) override
 
size_t generateTrailers (folly::IOBufQueue &writeBuf, StreamID stream, const HTTPHeaders &trailers) override
 
size_t generateEOM (folly::IOBufQueue &writeBuf, StreamID stream) override
 
size_t generateRstStream (folly::IOBufQueue &writeBuf, StreamID stream, ErrorCode statusCode) override
 
size_t generateGoaway (folly::IOBufQueue &writeBuf, StreamID lastStream, ErrorCode statusCode, std::unique_ptr< folly::IOBuf > debugData=nullptr) override
 
size_t generatePingRequest (folly::IOBufQueue &writeBuf) override
 
size_t generatePingReply (folly::IOBufQueue &writeBuf, uint64_t uniqueID) override
 
size_t generateSettings (folly::IOBufQueue &writeBuf) override
 
size_t generateSettingsAck (folly::IOBufQueue &writeBuf) override
 
size_t generateWindowUpdate (folly::IOBufQueue &writeBuf, StreamID stream, uint32_t delta) override
 
size_t generatePriority (folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage::HTTPPriority &pri) override
 
size_t generateCertificateRequest (folly::IOBufQueue &writeBuf, uint16_t requestId, std::unique_ptr< folly::IOBuf > certificateRequestData) override
 
size_t generateCertificate (folly::IOBufQueue &writeBuf, uint16_t certId, std::unique_ptr< folly::IOBuf > certData) override
 
const HTTPSettingsgetIngressSettings () const override
 
HTTPSettingsgetEgressSettings () override
 
uint32_t getDefaultWindowSize () const override
 
bool supportsPushTransactions () const override
 
bool peerHasWebsockets () const
 
bool supportsExTransactions () const override
 
void setHeaderCodecStats (HeaderCodec::Stats *hcStats) override
 
bool isRequest (StreamID id) const
 
size_t addPriorityNodes (PriorityQueue &queue, folly::IOBufQueue &writeBuf, uint8_t maxLevel) override
 
HTTPCodec::StreamID mapPriorityToDependency (uint8_t priority) const override
 
HPACKTableInfo getHPACKTableInfo () const override
 
uint64_t getReceivedFrameCount () const
 
void setReuseIOBufHeadroomForData (bool enabled)
 
void setHeaderIndexingStrategy (const HeaderIndexingStrategy *indexingStrat)
 
const HeaderIndexingStrategygetHeaderIndexingStrategy () const
 
- Public Member Functions inherited from proxygen::HTTPParallelCodec
 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 int8_t mapDependencyToPriority (StreamID) const
 

Static Public Member Functions

static void requestUpgrade (HTTPMessage &request)
 

Private Types

enum  FrameState {
  UPSTREAM_CONNECTION_PREFACE = 0, DOWNSTREAM_CONNECTION_PREFACE = 1, FRAME_HEADER = 2, FRAME_DATA = 3,
  DATA_FRAME_DATA = 4
}
 

Private Member Functions

void generateHeaderImpl (folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, const folly::Optional< StreamID > &assocStream, const folly::Optional< ExAttributes > &exAttributes, bool eom, HTTPHeaderSize *size)
 
std::unique_ptr< folly::IOBufencodeHeaders (const HTTPHeaders &headers, std::vector< compress::Header > &allHeaders, HTTPHeaderSize *size)
 
size_t generateHeaderCallbackWrapper (StreamID stream, http2::FrameType type, size_t length)
 
ErrorCode parseFrame (folly::io::Cursor &cursor)
 
ErrorCode parseAllData (folly::io::Cursor &cursor)
 
ErrorCode parseDataFrameData (folly::io::Cursor &cursor, size_t bufLen, size_t &parsed)
 
ErrorCode parseHeaders (folly::io::Cursor &cursor)
 
ErrorCode parseExHeaders (folly::io::Cursor &cursor)
 
ErrorCode parsePriority (folly::io::Cursor &cursor)
 
ErrorCode parseRstStream (folly::io::Cursor &cursor)
 
ErrorCode parseSettings (folly::io::Cursor &cursor)
 
ErrorCode parsePushPromise (folly::io::Cursor &cursor)
 
ErrorCode parsePing (folly::io::Cursor &cursor)
 
ErrorCode parseGoaway (folly::io::Cursor &cursor)
 
ErrorCode parseContinuation (folly::io::Cursor &cursor)
 
ErrorCode parseWindowUpdate (folly::io::Cursor &cursor)
 
ErrorCode parseCertificateRequest (folly::io::Cursor &cursor)
 
ErrorCode parseCertificate (folly::io::Cursor &cursor)
 
ErrorCode parseHeadersImpl (folly::io::Cursor &cursor, std::unique_ptr< folly::IOBuf > headerBuf, const folly::Optional< http2::PriorityUpdate > &priority, const folly::Optional< uint32_t > &promisedStream, const folly::Optional< ExAttributes > &exAttributes)
 
folly::Optional< ErrorCodeparseHeadersDecodeFrames (const folly::Optional< http2::PriorityUpdate > &priority, const folly::Optional< uint32_t > &promisedStream, const folly::Optional< ExAttributes > &exAttributes, std::unique_ptr< HTTPMessage > &msg)
 
folly::Optional< ErrorCodeparseHeadersCheckConcurrentStreams (const folly::Optional< http2::PriorityUpdate > &priority)
 
ErrorCode handleEndStream ()
 
ErrorCode checkNewStream (uint32_t stream, bool trailersAllowed)
 
bool checkConnectionError (ErrorCode, const folly::IOBuf *buf)
 
ErrorCode handleSettings (const std::deque< SettingPair > &settings)
 
size_t maxSendFrameSize () const
 
uint32_t maxRecvFrameSize () const
 
void streamError (const std::string &msg, ErrorCode error, bool newTxn=false)
 
bool parsingTrailers () const
 
- Private Member Functions inherited from proxygen::HPACK::StreamingCallback
virtual ~StreamingCallback ()
 

Private Attributes

HPACKCodec headerCodec_
 
http2::FrameHeader curHeader_
 
StreamID expectedContinuationStream_ {0}
 
bool pendingEndStreamHandling_ {false}
 
bool ingressWebsocketUpgrade_ {false}
 
std::unordered_set< StreamIDupgradedStreams_
 
uint16_t curCertId_ {0}
 
folly::IOBufQueue curAuthenticatorBlock_
 
folly::IOBufQueue curHeaderBlock_ {folly::IOBufQueue::cacheChainLength()}
 
HTTPSettings ingressSettings_
 
HTTPSettings egressSettings_
 
uint64_t receivedFrameCount_ {0}
 
FrameState frameState_:3
 
std::string userAgent_
 
size_t pendingDataFrameBytes_ {0}
 
size_t pendingDataFramePaddingBytes_ {0}
 
HeaderDecodeInfo decodeInfo_
 
std::vector< StreamIDvirtualPriorityNodes_
 
bool reuseIOBufHeadroomForData_ {true}
 
bool parsingDownstreamTrailers_ {false}
 
http2::FrameType headerBlockFrameType_ {http2::FrameType::DATA}
 
- Private Attributes inherited from proxygen::HPACK::StreamingCallback
HeaderCodec::Statsstats {nullptr}
 

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
 
- Protected Types inherited from proxygen::HTTPParallelCodec
enum  ClosingState {
  OPEN = 0, OPEN_WITH_GRACEFUL_DRAIN_ENABLED = 1, FIRST_GOAWAY_SENT = 2, CLOSING = 3,
  CLOSED = 4
}
 
- Protected Member Functions inherited from proxygen::HTTPParallelCodec
template<typename T , typename... Args>
bool deliverCallbackIfAllowed (T callbackFn, char const *cbName, StreamID stream, Args &&...args)
 
- Protected Attributes inherited from proxygen::HTTPParallelCodec
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_
 

Detailed Description

An implementation of the framing layer for HTTP/2. Instances of this class must not be used from multiple threads concurrently.

Definition at line 29 of file HTTP2Codec.h.

Member Enumeration Documentation

Enumerator
UPSTREAM_CONNECTION_PREFACE 
DOWNSTREAM_CONNECTION_PREFACE 
FRAME_HEADER 
FRAME_DATA 
DATA_FRAME_DATA 

Definition at line 269 of file HTTP2Codec.h.

Constructor & Destructor Documentation

proxygen::HTTP2Codec::HTTP2Codec ( TransportDirection  direction)
explicit

Definition at line 42 of file HTTP2Codec.cpp.

References egressSettings_, proxygen::HTTPSettings::getSetting(), proxygen::getTransportDirectionString(), proxygen::HEADER_TABLE_SIZE, headerCodec_, proxygen::MAX_HEADER_LIST_SIZE, proxygen::HPACKCodec::setDecoderHeaderTableMaxSize(), and proxygen::HPACKCodec::setMaxUncompressed().

43  : HTTPParallelCodec(direction),
44  headerCodec_(direction),
46  ? FrameState::UPSTREAM_CONNECTION_PREFACE
47  : FrameState::DOWNSTREAM_CONNECTION_PREFACE) {
48 
49  // Set headerCodec_ settings if specified, else let headerCodec_ utilize
50  // its own defaults
51  const auto decoderHeaderTableMaxSize = egressSettings_.getSetting(
53  if (decoderHeaderTableMaxSize) {
54  headerCodec_.setDecoderHeaderTableMaxSize(decoderHeaderTableMaxSize->value);
55  }
56  const auto maxHeaderListSize = egressSettings_.getSetting(
58  if (maxHeaderListSize) {
59  headerCodec_.setMaxUncompressed(maxHeaderListSize->value);
60  }
61 
62  VLOG(4) << "creating " << getTransportDirectionString(direction)
63  << " HTTP/2 codec";
64 }
void setDecoderHeaderTableMaxSize(uint32_t size)
Definition: HPACKCodec.h:58
FrameState frameState_
Definition: HTTP2Codec.h:276
const char * getTransportDirectionString(TransportDirection dir)
HTTPSettings egressSettings_
Definition: HTTP2Codec.h:260
HPACKCodec headerCodec_
Definition: HTTP2Codec.h:240
HTTPParallelCodec(TransportDirection direction)
void setMaxUncompressed(uint64_t maxUncompressed) override
Definition: HPACKCodec.h:64
const HTTPSetting * getSetting(SettingsId id) const
proxygen::HTTP2Codec::~HTTP2Codec ( )
override

Definition at line 66 of file HTTP2Codec.cpp.

66 {}

Member Function Documentation

size_t proxygen::HTTP2Codec::addPriorityNodes ( PriorityQueue ,
folly::IOBufQueue ,
uint8_t   
)
overridevirtual

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 from proxygen::HTTPCodec.

Definition at line 670 of file HTTP2Codec.cpp.

References proxygen::HTTPCodec::PriorityQueue::addPriorityNode(), proxygen::HTTPParallelCodec::createStream(), generatePriority(), std::tr1::make_tuple(), parent, and virtualPriorityNodes_.

Referenced by isRequest().

673  {
675  size_t bytes = 0;
676  while (maxLevel--) {
677  auto id = createStream();
678  virtualPriorityNodes_.push_back(id);
679  queue.addPriorityNode(id, parent);
680  bytes += generatePriority(writeBuf, id, std::make_tuple(parent, false, 0));
681  parent = id;
682  }
683  return bytes;
684 }
tuple make_tuple()
Definition: gtest-tuple.h:675
size_t generatePriority(folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage::HTTPPriority &pri) override
void writeBuf(const Buf &buf, folly::io::Appender &out)
std::vector< StreamID > virtualPriorityNodes_
Definition: HTTP2Codec.h:283
StreamID createStream() override
uint64_t StreamID
Definition: HTTPCodec.h:49
folly::Function< void()> parent
Definition: AtFork.cpp:34
bool proxygen::HTTP2Codec::checkConnectionError ( ErrorCode  err,
const folly::IOBuf buf 
)
private

Definition at line 1598 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::callback_, proxygen::ERROR, proxygen::getErrorCodeString(), proxygen::HTTPParallelCodec::goawayErrorMessage_, proxygen::HTTPException::INGRESS_AND_EGRESS, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onError(), proxygen::IOBufPrinter::printHexFolly(), proxygen::HTTPException::setCodecStatusCode(), and string.

Referenced by getHeaderIndexingStrategy(), and onIngress().

1598  {
1599  if (err != ErrorCode::NO_ERROR) {
1600  LOG(ERROR) << "Connection error " << getErrorCodeString(err)
1601  << " with ingress=";
1602  VLOG(3) << IOBufPrinter::printHexFolly(buf, true);
1603  if (callback_) {
1604  std::string errorDescription = goawayErrorMessage_.empty() ?
1605  "Connection error" : goawayErrorMessage_;
1607  errorDescription);
1608  ex.setCodecStatusCode(err);
1609  callback_->onError(0, ex, false);
1610  }
1611  return true;
1612  }
1613  return false;
1614 }
virtual void onError(StreamID stream, const HTTPException &error, bool newTxn=false)=0
static std::string printHexFolly(const folly::IOBuf *buf, bool coalesce=false)
Definition: Logging.h:127
HTTPCodec::Callback * callback_
const char * getErrorCodeString(ErrorCode error)
Definition: ErrorCode.cpp:18
const char * string
Definition: Conv.cpp:212
ErrorCode proxygen::HTTP2Codec::checkNewStream ( uint32_t  stream,
bool  trailersAllowed 
)
private

Definition at line 973 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::goawayErrorMessage_, proxygen::HTTPParallelCodec::isInitiatedStream(), proxygen::HTTPParallelCodec::lastStreamID_, proxygen::NO_ERROR, parsingDownstreamTrailers_, proxygen::PROTOCOL_ERROR, and proxygen::HTTPParallelCodec::sessionClosing_.

Referenced by getHeaderIndexingStrategy(), parseExHeaders(), parseHeaders(), and parsePushPromise().

973  {
974  if (streamId == 0) {
975  goawayErrorMessage_ = folly::to<string>(
976  "GOAWAY error: received streamID=", streamId,
977  " as invalid new stream for lastStreamID_=", lastStreamID_);
978  VLOG(4) << goawayErrorMessage_;
980  }
981  parsingDownstreamTrailers_ = trailersAllowed && (streamId <= lastStreamID_);
983  VLOG(4) << "Parsing downstream trailers streamId=" << streamId;
984  }
985 
986  if (sessionClosing_ != ClosingState::CLOSED) {
987  lastStreamID_ = streamId;
988  }
989 
990  if (isInitiatedStream(streamId)) {
991  // this stream should be initiated by us, not by peer
992  goawayErrorMessage_ = folly::to<string>(
993  "GOAWAY error: invalid new stream received with streamID=", streamId);
994  VLOG(4) << goawayErrorMessage_;
996  } else {
997  return ErrorCode::NO_ERROR;
998  }
999 }
bool isInitiatedStream(StreamID stream) const
enum proxygen::HTTPParallelCodec::ClosingState sessionClosing_
bool parsingDownstreamTrailers_
Definition: HTTP2Codec.h:292
std::unique_ptr< folly::IOBuf > proxygen::HTTP2Codec::encodeHeaders ( const HTTPHeaders headers,
std::vector< compress::Header > &  allHeaders,
HTTPHeaderSize size 
)
private

Definition at line 1217 of file HTTP2Codec.cpp.

References proxygen::HPACKCodec::encode(), proxygen::ERROR, proxygen::HTTPHeaders::forEach(), proxygen::HeaderCodec::getEncodedSize(), proxygen::HTTPSettings::getSetting(), headerCodec_, ingressSettings_, proxygen::http2::kFrameHeadersBaseMaxSize, proxygen::http2::kFrameHeaderSize, max, proxygen::MAX_HEADER_LIST_SIZE, name, proxygen::HeaderCodec::setEncodeHeadroom(), proxygen::HTTPHeaders::size(), wangle::HTTPHeaderSize::uncompressed, and value.

Referenced by generateHeaderImpl(), generateTrailers(), and getHeaderIndexingStrategy().

1220  {
1223  auto out = headerCodec_.encode(allHeaders);
1224  if (size) {
1226  }
1227 
1231  // The remote side told us they don't want headers this large...
1232  // but this function has no mechanism to fail
1233  string serializedHeaders;
1234  headers.forEach(
1235  [&serializedHeaders] (const string& name, const string& value) {
1236  serializedHeaders = folly::to<string>(serializedHeaders, "\\n", name,
1237  ":", value);
1238  });
1239  LOG(ERROR) << "generating HEADERS frame larger than peer maximum nHeaders="
1240  << headers.size() << " all headers="
1241  << serializedHeaders;
1242  }
1243  return out;
1244 }
HTTPSettings ingressSettings_
Definition: HTTP2Codec.h:255
LogLevel max
Definition: LogLevel.cpp:31
const uint32_t kFrameHeaderSize
HPACKCodec headerCodec_
Definition: HTTP2Codec.h:240
void setEncodeHeadroom(uint32_t headroom)
Definition: HeaderCodec.h:69
const char * name
Definition: http_parser.c:437
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
const uint32_t kFrameHeadersBaseMaxSize
static const char *const value
Definition: Conv.cpp:50
std::unique_ptr< folly::IOBuf > encode(std::vector< compress::Header > &headers) noexcept
Definition: HPACKCodec.cpp:48
const HTTPHeaderSize & getEncodedSize()
Definition: HeaderCodec.h:62
const HTTPSetting * getSetting(SettingsId id) const
size_t proxygen::HTTP2Codec::generateBody ( folly::IOBufQueue writeBuf,
StreamID  stream,
std::unique_ptr< folly::IOBuf chain,
folly::Optional< uint8_t padding,
bool  eom 
)
overridevirtual

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

Implements proxygen::HTTPCodec.

Definition at line 1257 of file HTTP2Codec.cpp.

References folly::IOBufQueue::append(), folly::IOBufQueue::chainLength(), proxygen::http2::DATA, generateHeaderCallbackWrapper(), proxygen::HTTPParallelCodec::ingressGoawayAck_, proxygen::HTTPParallelCodec::isStreamIngressEgressAllowed(), maxSendFrameSize(), folly::IOBufQueue::move(), folly::gen::move, reuseIOBufHeadroomForData_, folly::IOBufQueue::split(), stream, and proxygen::http2::writeData().

Referenced by getUserAgent().

1261  {
1262  // todo: generate random padding for everything?
1263  size_t written = 0;
1265  VLOG(2) << "Suppressing DATA for stream=" << stream << " ingressGoawayAck_="
1266  << ingressGoawayAck_;
1267  return 0;
1268  }
1269  IOBufQueue queue(IOBufQueue::cacheChainLength());
1270  queue.append(std::move(chain));
1271  size_t maxFrameSize = maxSendFrameSize();
1272  while (queue.chainLength() > maxFrameSize) {
1273  auto chunk = queue.split(maxFrameSize);
1274  written += generateHeaderCallbackWrapper(
1275  stream,
1277  http2::writeData(writeBuf,
1278  std::move(chunk),
1279  stream,
1280  padding,
1281  false,
1283  }
1284 
1285  return written + generateHeaderCallbackWrapper(
1286  stream,
1288  http2::writeData(writeBuf,
1289  queue.move(),
1290  stream,
1291  padding,
1292  eom,
1294 }
StreamCodecFactory stream
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
size_t maxSendFrameSize() const
Definition: HTTP2Codec.h:229
bool isStreamIngressEgressAllowed(StreamID stream) const
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
bool reuseIOBufHeadroomForData_
Definition: HTTP2Codec.h:284
size_t writeData(IOBufQueue &queue, std::unique_ptr< IOBuf > data, uint32_t stream, folly::Optional< uint8_t > padding, bool endStream, bool reuseIOBufHeadroom) noexcept
size_t proxygen::HTTP2Codec::generateCertificate ( folly::IOBufQueue writeBuf,
uint16_t  certId,
std::unique_ptr< folly::IOBuf certData 
)
overridevirtual

Reimplemented from proxygen::HTTPCodec.

Definition at line 1579 of file HTTP2Codec.cpp.

References folly::IOBufQueue::append(), folly::IOBufQueue::chainLength(), maxSendFrameSize(), folly::IOBufQueue::move(), folly::gen::move, folly::IOBufQueue::splitAtMost(), and proxygen::http2::writeCertificate().

Referenced by getUserAgent().

1581  {
1582  size_t written = 0;
1583  VLOG(4) << "sending CERTIFICATE with Cert-ID=" << certId << "for stream=0";
1584  IOBufQueue queue(IOBufQueue::cacheChainLength());
1585  queue.append(std::move(certData));
1586  // The maximum size of an autenticator fragment, combined with the Cert-ID can
1587  // not exceed the maximal allowable size of a sent frame.
1588  size_t maxChunkSize = maxSendFrameSize() - sizeof(certId);
1589  while (queue.chainLength() > maxChunkSize) {
1590  auto chunk = queue.splitAtMost(maxChunkSize);
1591  written +=
1592  http2::writeCertificate(writeBuf, certId, std::move(chunk), true);
1593  }
1594  return written +
1595  http2::writeCertificate(writeBuf, certId, queue.move(), false);
1596 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
size_t maxSendFrameSize() const
Definition: HTTP2Codec.h:229
size_t writeCertificate(folly::IOBufQueue &writeBuf, uint16_t certId, std::unique_ptr< folly::IOBuf > authenticator, bool toBeContinued)
size_t proxygen::HTTP2Codec::generateCertificateRequest ( folly::IOBufQueue writeBuf,
uint16_t  requestId,
std::unique_ptr< folly::IOBuf certificateRequestData 
)
overridevirtual

Reimplemented from proxygen::HTTPCodec.

Definition at line 1570 of file HTTP2Codec.cpp.

References folly::gen::move, and proxygen::http2::writeCertificateRequest().

Referenced by getUserAgent().

1573  {
1574  VLOG(4) << "generating CERTIFICATE_REQUEST with Request-ID=" << requestId;
1576  writeBuf, requestId, std::move(certificateRequestData));
1577 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_t writeCertificateRequest(folly::IOBufQueue &writeBuf, uint16_t requestId, std::unique_ptr< folly::IOBuf > authRequest)
size_t proxygen::HTTP2Codec::generateChunkHeader ( folly::IOBufQueue writeBuf,
StreamID  stream,
size_t  length 
)
overridevirtual

Write a body chunk header, if relevant.

Implements proxygen::HTTPCodec.

Definition at line 1296 of file HTTP2Codec.cpp.

Referenced by getUserAgent().

1298  {
1299  // HTTP/2 has no chunk headers
1300  return 0;
1301 }
size_t proxygen::HTTP2Codec::generateChunkTerminator ( folly::IOBufQueue writeBuf,
StreamID  stream 
)
overridevirtual

Write a body chunk terminator, if relevant.

Implements proxygen::HTTPCodec.

Definition at line 1303 of file HTTP2Codec.cpp.

Referenced by getUserAgent().

1304  {
1305  // HTTP/2 has no chunk terminators
1306  return 0;
1307 }
size_t proxygen::HTTP2Codec::generateConnectionPreface ( folly::IOBufQueue )
overridevirtual

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

Returns
size of the generated message

Reimplemented from proxygen::HTTPCodec.

Definition at line 1001 of file HTTP2Codec.cpp.

References folly::IOBufQueue::append(), proxygen::http2::kConnectionPreface, proxygen::HTTPParallelCodec::transportDirection_, and proxygen::UPSTREAM.

Referenced by getUserAgent().

1001  {
1003  VLOG(4) << "generating connection preface";
1005  return http2::kConnectionPreface.length();
1006  }
1007  return 0;
1008 }
void writeBuf(const Buf &buf, folly::io::Appender &out)
const std::string kConnectionPreface
TransportDirection transportDirection_
void proxygen::HTTP2Codec::generateContinuation ( folly::IOBufQueue writeBuf,
folly::IOBufQueue queue,
StreamID  stream,
size_t  maxFrameSize 
)

Definition at line 1200 of file HTTP2Codec.cpp.

References folly::IOBufQueue::chainLength(), proxygen::http2::CONTINUATION, generateHeaderCallbackWrapper(), min, folly::gen::move, folly::IOBufQueue::split(), stream, and proxygen::http2::writeContinuation().

Referenced by generateHeaderImpl(), generateTrailers(), and getUserAgent().

1203  {
1204  bool endHeaders = false;
1205  while (!endHeaders) {
1206  auto chunk = queue.split(std::min(maxFrameSize, queue.chainLength()));
1207  endHeaders = (queue.chainLength() == 0);
1208  VLOG(4) << "generating CONTINUATION for stream=" << stream;
1210  stream,
1213  writeBuf, stream, endHeaders, std::move(chunk)));
1214  }
1215 }
std::unique_ptr< folly::IOBuf > split(size_t n)
Definition: IOBufQueue.h:420
size_t chainLength() const
Definition: IOBufQueue.h:492
StreamCodecFactory stream
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_t writeContinuation(IOBufQueue &queue, uint32_t stream, bool endHeaders, std::unique_ptr< IOBuf > headers) noexcept
LogLevel min
Definition: LogLevel.cpp:30
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
size_t proxygen::HTTP2Codec::generateEOM ( folly::IOBufQueue writeBuf,
StreamID  stream 
)
overridevirtual

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

Returns
number of bytes written

Implements proxygen::HTTPCodec.

Definition at line 1344 of file HTTP2Codec.cpp.

References proxygen::http2::DATA, generateHeaderCallbackWrapper(), proxygen::HTTPParallelCodec::ingressGoawayAck_, proxygen::HTTPParallelCodec::isStreamIngressEgressAllowed(), proxygen::http2::kNoPadding, reuseIOBufHeadroomForData_, stream, upgradedStreams_, and proxygen::http2::writeData().

Referenced by getUserAgent().

1345  {
1346  VLOG(4) << "sending EOM for stream=" << stream;
1347  upgradedStreams_.erase(stream);
1349  VLOG(2) << "suppressed EOM for stream=" << stream << " ingressGoawayAck_="
1350  << ingressGoawayAck_;
1351  return 0;
1352  }
1354  stream,
1356  http2::writeData(writeBuf,
1357  nullptr,
1358  stream,
1360  true,
1362 }
StreamCodecFactory stream
std::unordered_set< StreamID > upgradedStreams_
Definition: HTTP2Codec.h:248
bool isStreamIngressEgressAllowed(StreamID stream) const
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
bool reuseIOBufHeadroomForData_
Definition: HTTP2Codec.h:284
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
size_t writeData(IOBufQueue &queue, std::unique_ptr< IOBuf > data, uint32_t stream, folly::Optional< uint8_t > padding, bool endStream, bool reuseIOBufHeadroom) noexcept
void proxygen::HTTP2Codec::generateExHeader ( folly::IOBufQueue writeBuf,
StreamID  stream,
const HTTPMessage msg,
const HTTPCodec::ExAttributes exAttributes,
bool  eom = false,
HTTPHeaderSize size = nullptr 
)
overridevirtual

Reimplemented from proxygen::HTTPCodec.

Definition at line 1084 of file HTTP2Codec.cpp.

References generateHeaderImpl(), and folly::none.

Referenced by getUserAgent().

1089  {
1090  generateHeaderImpl(writeBuf,
1091  stream,
1092  msg,
1093  folly::none, /* assocStream */
1094  exAttributes,
1095  eom,
1096  size);
1097 }
void generateHeaderImpl(folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, const folly::Optional< StreamID > &assocStream, const folly::Optional< ExAttributes > &exAttributes, bool eom, HTTPHeaderSize *size)
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
constexpr None none
Definition: Optional.h:87
size_t proxygen::HTTP2Codec::generateGoaway ( folly::IOBufQueue writeBuf,
StreamID  lastStream,
ErrorCode  code,
std::unique_ptr< folly::IOBuf debugData = nullptr 
)
overridevirtual

Generate any protocol framing needed to abort a connection.

Returns
number of bytes written

Implements proxygen::HTTPCodec.

Definition at line 1391 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::egressGoawayAck_, proxygen::http2::errorCodeToGoaway(), folly::FATAL, generateHeaderCallbackWrapper(), proxygen::getErrorCodeString(), proxygen::http2::GOAWAY, max, folly::gen::move, proxygen::NO_ERROR, proxygen::PROTOCOL_ERROR, proxygen::HTTPParallelCodec::sessionClosing_, userAgent_, and proxygen::http2::writeGoaway().

Referenced by getUserAgent().

1394  {
1395  DCHECK_LE(lastStream, egressGoawayAck_) << "Cannot increase last good stream";
1396  egressGoawayAck_ = lastStream;
1397  if (sessionClosing_ == ClosingState::CLOSED) {
1398  VLOG(4) << "Not sending GOAWAY for closed session";
1399  return 0;
1400  }
1401  switch (sessionClosing_) {
1402  case ClosingState::OPEN:
1403  case ClosingState::OPEN_WITH_GRACEFUL_DRAIN_ENABLED:
1404  if (lastStream == std::numeric_limits<int32_t>::max() &&
1406  sessionClosing_ = ClosingState::FIRST_GOAWAY_SENT;
1407  } else {
1408  // The user of this codec decided not to do the double goaway
1409  // drain, or this is not a graceful shutdown
1410  sessionClosing_ = ClosingState::CLOSED;
1411  }
1412  break;
1413  case ClosingState::FIRST_GOAWAY_SENT:
1414  sessionClosing_ = ClosingState::CLOSED;
1415  break;
1416  case ClosingState::CLOSING:
1417  case ClosingState::CLOSED:
1418  LOG(FATAL) << "unreachable";
1419  }
1420 
1421  VLOG(4) << "Sending GOAWAY with last acknowledged stream="
1422  << lastStream << " with code=" << getErrorCodeString(statusCode);
1424  VLOG(2) << "sending GOAWAY with last acknowledged stream=" << lastStream
1425  << " with code=" << getErrorCodeString(statusCode)
1426  << " user-agent=" << userAgent_;
1427  }
1428 
1429  auto code = http2::errorCodeToGoaway(statusCode);
1431  0,
1433  http2::writeGoaway(writeBuf,
1434  lastStream,
1435  code,
1436  std::move(debugData)));
1437 }
spdy::GoawayStatusCode statusCode
Definition: SPDYCodec.cpp:110
LogLevel max
Definition: LogLevel.cpp:31
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
ErrorCode errorCodeToGoaway(ErrorCode code)
enum proxygen::HTTPParallelCodec::ClosingState sessionClosing_
const char * getErrorCodeString(ErrorCode error)
Definition: ErrorCode.cpp:18
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
size_t writeGoaway(IOBufQueue &queue, uint32_t lastStreamID, ErrorCode errorCode, std::unique_ptr< IOBuf > debugData) noexcept
std::string userAgent_
Definition: HTTP2Codec.h:277
void proxygen::HTTP2Codec::generateHeader ( folly::IOBufQueue writeBuf,
StreamID  stream,
const HTTPMessage msg,
bool  eom = false,
HTTPHeaderSize size = nullptr 
)
overridevirtual

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

Implements proxygen::HTTPCodec.

Definition at line 1055 of file HTTP2Codec.cpp.

References generateHeaderImpl(), and folly::none.

Referenced by getUserAgent().

1059  {
1060  generateHeaderImpl(writeBuf,
1061  stream,
1062  msg,
1063  folly::none, /* assocStream */
1064  folly::none, /* controlStream */
1065  eom,
1066  size);
1067 }
void generateHeaderImpl(folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, const folly::Optional< StreamID > &assocStream, const folly::Optional< ExAttributes > &exAttributes, bool eom, HTTPHeaderSize *size)
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
constexpr None none
Definition: Optional.h:87
size_t proxygen::HTTP2Codec::generateHeaderCallbackWrapper ( StreamID  stream,
http2::FrameType  type,
size_t  length 
)
private
void proxygen::HTTP2Codec::generateHeaderImpl ( folly::IOBufQueue writeBuf,
StreamID  stream,
const HTTPMessage msg,
const folly::Optional< StreamID > &  assocStream,
const folly::Optional< ExAttributes > &  exAttributes,
bool  eom,
HTTPHeaderSize size 
)
private

Definition at line 1099 of file HTTP2Codec.cpp.

References wangle::HTTPHeaderSize::compressed, proxygen::DOWNSTREAM, encodeHeaders(), proxygen::http2::EX_HEADERS, generateContinuation(), generateHeaderCallbackWrapper(), proxygen::HTTPMessage::getHeaders(), proxygen::HTTPMessage::getHTTP2Priority(), proxygen::http2::HEADERS, proxygen::HTTPParallelCodec::ingressGoawayAck_, proxygen::HTTPMessage::isEgressWebsocketUpgrade(), proxygen::HTTPMessage::isRequest(), proxygen::HTTPParallelCodec::isStreamIngressEgressAllowed(), proxygen::http2::kFramePrioritySize, proxygen::http2::kNoPadding, maxSendFrameSize(), min, folly::gen::move, proxygen::CodecUtil::prepareMessageForCompression(), proxygen::http2::PUSH_PROMISE, folly::size(), stream, proxygen::HTTPParallelCodec::transportDirection_, wangle::HTTPHeaderSize::uncompressed, upgradedStreams_, proxygen::UPSTREAM, proxygen::http2::writeExHeaders(), proxygen::http2::writeHeaders(), and proxygen::http2::writePushPromise().

Referenced by generateExHeader(), generateHeader(), generatePushPromise(), and getHeaderIndexingStrategy().

1106  {
1107  if (assocStream) {
1108  CHECK(!exAttributes);
1109  VLOG(4) << "generating PUSH_PROMISE for stream=" << stream;
1110  } else if (exAttributes) {
1111  CHECK(!assocStream);
1112  VLOG(4) << "generating ExHEADERS for stream=" << stream
1113  << " with control stream=" << exAttributes->controlStream
1114  << " unidirectional=" << exAttributes->unidirectional;
1115  } else {
1116  VLOG(4) << "generating HEADERS for stream=" << stream;
1117  }
1118 
1120  VLOG(2) << "Suppressing HEADERS/PROMISE for stream=" << stream <<
1121  " ingressGoawayAck_=" << ingressGoawayAck_;
1122  if (size) {
1123  size->uncompressed = 0;
1124  size->compressed = 0;
1125  }
1126  return;
1127  }
1128 
1129  if (msg.isRequest()) {
1131  assocStream || exAttributes);
1132  if (msg.isEgressWebsocketUpgrade()) {
1133  upgradedStreams_.insert(stream);
1134  }
1135  } else {
1137  exAttributes);
1138  }
1139 
1140  std::vector<std::string> temps;
1141  auto allHeaders = CodecUtil::prepareMessageForCompression(msg, temps);
1142  auto out = encodeHeaders(msg.getHeaders(), allHeaders, size);
1143  IOBufQueue queue(IOBufQueue::cacheChainLength());
1144  queue.append(std::move(out));
1145  auto maxFrameSize = maxSendFrameSize();
1146  if (queue.chainLength() > 0) {
1148  auto res = msg.getHTTP2Priority();
1149  auto remainingFrameSize = maxFrameSize;
1150  if (res) {
1151  pri = http2::PriorityUpdate{std::get<0>(*res), std::get<1>(*res),
1152  std::get<2>(*res)};
1153  DCHECK_GE(remainingFrameSize, http2::kFramePrioritySize)
1154  << "no enough space for priority? frameHeadroom=" << remainingFrameSize;
1155  remainingFrameSize -= http2::kFramePrioritySize;
1156  }
1157  auto chunk = queue.split(std::min(remainingFrameSize, queue.chainLength()));
1158 
1159  bool endHeaders = queue.chainLength() == 0;
1160 
1161  if (assocStream) {
1163  DCHECK(!eom);
1165  http2::writePushPromise(writeBuf,
1166  *assocStream,
1167  stream,
1168  std::move(chunk),
1170  endHeaders));
1171  } else if (exAttributes) {
1173  stream,
1175  http2::writeExHeaders(writeBuf,
1176  std::move(chunk),
1177  stream,
1178  *exAttributes,
1179  pri,
1181  eom,
1182  endHeaders));
1183  } else {
1185  http2::writeHeaders(writeBuf,
1186  std::move(chunk),
1187  stream,
1188  pri,
1190  eom,
1191  endHeaders));
1192  }
1193 
1194  if (!endHeaders) {
1195  generateContinuation(writeBuf, queue, stream, maxFrameSize);
1196  }
1197  }
1198 }
static std::vector< compress::Header > prepareMessageForCompression(const HTTPMessage &msg, std::vector< std::string > &temps)
Definition: CodecUtil.cpp:82
void generateContinuation(folly::IOBufQueue &writeBuf, folly::IOBufQueue &queue, StreamID stream, size_t maxFrameSize)
const uint32_t kFramePrioritySize
StreamCodecFactory stream
size_t writeHeaders(IOBufQueue &queue, std::unique_ptr< IOBuf > headers, uint32_t stream, folly::Optional< PriorityUpdate > priority, folly::Optional< uint8_t > padding, bool endStream, bool endHeaders) noexcept
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unordered_set< StreamID > upgradedStreams_
Definition: HTTP2Codec.h:248
size_t writePushPromise(IOBufQueue &queue, uint32_t associatedStream, uint32_t promisedStream, std::unique_ptr< IOBuf > headers, folly::Optional< uint8_t > padding, bool endHeaders) noexcept
size_t maxSendFrameSize() const
Definition: HTTP2Codec.h:229
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
LogLevel min
Definition: LogLevel.cpp:30
bool isStreamIngressEgressAllowed(StreamID stream) const
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
std::unique_ptr< folly::IOBuf > encodeHeaders(const HTTPHeaders &headers, std::vector< compress::Header > &allHeaders, HTTPHeaderSize *size)
size_t writeExHeaders(IOBufQueue &queue, std::unique_ptr< IOBuf > headers, uint32_t stream, const HTTPCodec::ExAttributes &exAttributes, const folly::Optional< PriorityUpdate > &priority, const folly::Optional< uint8_t > &padding, bool endStream, bool endHeaders) noexcept
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
TransportDirection transportDirection_
size_t proxygen::HTTP2Codec::generatePingReply ( folly::IOBufQueue ,
uint64_t   
)
overridevirtual

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

Reimplemented from proxygen::HTTPCodec.

Definition at line 1448 of file HTTP2Codec.cpp.

References generateHeaderCallbackWrapper(), proxygen::http2::PING, and proxygen::http2::writePing().

Referenced by getUserAgent().

1449  {
1450  VLOG(4) << "Generating ping reply with opaqueData=" << uniqueID;
1452  http2::writePing(writeBuf, uniqueID, true /* ack */));
1453 }
size_t writePing(IOBufQueue &queue, uint64_t opaqueData, bool ack) noexcept
void writeBuf(const Buf &buf, folly::io::Appender &out)
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
size_t proxygen::HTTP2Codec::generatePingRequest ( folly::IOBufQueue )
overridevirtual

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

Reimplemented from proxygen::HTTPCodec.

Definition at line 1439 of file HTTP2Codec.cpp.

References generateHeaderCallbackWrapper(), proxygen::http2::PING, folly::Random::rand64(), uint64_t, and proxygen::http2::writePing().

Referenced by getUserAgent().

1439  {
1440  // should probably let the caller specify when integrating with session
1441  // we know HTTPSession sets up events to track ping latency
1442  uint64_t opaqueData = folly::Random::rand64();
1443  VLOG(4) << "Generating ping request with opaqueData=" << opaqueData;
1445  http2::writePing(writeBuf, opaqueData, false /* no ack */));
1446 }
size_t writePing(IOBufQueue &queue, uint64_t opaqueData, bool ack) noexcept
void writeBuf(const Buf &buf, folly::io::Appender &out)
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
static uint64_t rand64()
Definition: Random.h:263
size_t proxygen::HTTP2Codec::generatePriority ( folly::IOBufQueue writeBuf,
StreamID  stream,
const HTTPMessage::HTTPPriority pri 
)
overridevirtual

Reimplemented from proxygen::HTTPCodec.

Definition at line 1552 of file HTTP2Codec.cpp.

References generateHeaderCallbackWrapper(), proxygen::HTTPParallelCodec::ingressGoawayAck_, proxygen::HTTPParallelCodec::isStreamIngressEgressAllowed(), proxygen::http2::PRIORITY, stream, and proxygen::http2::writePriority().

Referenced by addPriorityNodes(), and getUserAgent().

1554  {
1555  VLOG(4) << "generating priority for stream=" << stream;
1557  VLOG(2) << "suppressed PRIORITY for stream=" << stream
1558  << " ingressGoawayAck_=" << ingressGoawayAck_;
1559  return 0;
1560  }
1562  stream,
1564  http2::writePriority(writeBuf, stream,
1565  {std::get<0>(pri),
1566  std::get<1>(pri),
1567  std::get<2>(pri)}));
1568 }
StreamCodecFactory stream
size_t writePriority(IOBufQueue &queue, uint32_t stream, PriorityUpdate priority) noexcept
bool isStreamIngressEgressAllowed(StreamID stream) const
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
void proxygen::HTTP2Codec::generatePushPromise ( folly::IOBufQueue writeBuf,
StreamID  stream,
const HTTPMessage msg,
StreamID  assocStream,
bool  eom = false,
HTTPHeaderSize size = nullptr 
)
overridevirtual

Reimplemented from proxygen::HTTPCodec.

Definition at line 1069 of file HTTP2Codec.cpp.

References generateHeaderImpl(), and folly::none.

Referenced by getUserAgent().

1074  {
1075  generateHeaderImpl(writeBuf,
1076  stream,
1077  msg,
1078  assocStream,
1079  folly::none, /* controlStream */
1080  eom,
1081  size);
1082 }
void generateHeaderImpl(folly::IOBufQueue &writeBuf, StreamID stream, const HTTPMessage &msg, const folly::Optional< StreamID > &assocStream, const folly::Optional< ExAttributes > &exAttributes, bool eom, HTTPHeaderSize *size)
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
constexpr None none
Definition: Optional.h:87
size_t proxygen::HTTP2Codec::generateRstStream ( folly::IOBufQueue writeBuf,
StreamID  stream,
ErrorCode  code 
)
overridevirtual

Generate any protocol framing needed to abort a stream.

Returns
number of bytes written

Implements proxygen::HTTPCodec.

Definition at line 1364 of file HTTP2Codec.cpp.

References curHeader_, proxygen::http2::END_STREAM, proxygen::http2::errorCodeToReset(), proxygen::http2::FrameHeader::flags, generateHeaderCallbackWrapper(), proxygen::getErrorCodeString(), proxygen::HTTPParallelCodec::ingressGoawayAck_, ingressWebsocketUpgrade_, proxygen::HTTPParallelCodec::isStreamIngressEgressAllowed(), pendingEndStreamHandling_, proxygen::PROTOCOL_ERROR, proxygen::http2::RST_STREAM, proxygen::http2::FrameHeader::stream, upgradedStreams_, userAgent_, and proxygen::http2::writeRstStream().

Referenced by getUserAgent().

1366  {
1367  VLOG(4) << "sending RST_STREAM for stream=" << stream
1368  << " with code=" << getErrorCodeString(statusCode);
1370  VLOG(2) << "suppressed RST_STREAM for stream=" << stream
1371  << " ingressGoawayAck_=" << ingressGoawayAck_;
1372  return 0;
1373  }
1374  // Suppress any EOM callback for the current frame.
1375  if (stream == curHeader_.stream) {
1376  curHeader_.flags &= ~http2::END_STREAM;
1377  pendingEndStreamHandling_ = false;
1378  ingressWebsocketUpgrade_ = false;
1379  }
1380  upgradedStreams_.erase(stream);
1381 
1383  VLOG(2) << "sending RST_STREAM with code=" << getErrorCodeString(statusCode)
1384  << " for stream=" << stream << " user-agent=" << userAgent_;
1385  }
1386  auto code = http2::errorCodeToReset(statusCode);
1388  http2::writeRstStream(writeBuf, stream, code));
1389 }
spdy::GoawayStatusCode statusCode
Definition: SPDYCodec.cpp:110
std::unordered_set< StreamID > upgradedStreams_
Definition: HTTP2Codec.h:248
bool pendingEndStreamHandling_
Definition: HTTP2Codec.h:245
ErrorCode errorCodeToReset(ErrorCode code)
const char * getErrorCodeString(ErrorCode error)
Definition: ErrorCode.cpp:18
bool isStreamIngressEgressAllowed(StreamID stream) const
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
size_t writeRstStream(IOBufQueue &queue, uint32_t stream, ErrorCode errorCode) noexcept
std::string userAgent_
Definition: HTTP2Codec.h:277
size_t proxygen::HTTP2Codec::generateSettings ( folly::IOBufQueue )
overridevirtual

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

Reimplemented from proxygen::HTTPCodec.

Definition at line 1455 of file HTTP2Codec.cpp.

References proxygen::DOWNSTREAM, egressSettings_, proxygen::ENABLE_CONNECT_PROTOCOL, proxygen::ENABLE_EX_HEADERS, proxygen::ENABLE_PUSH, proxygen::ERROR, generateHeaderCallbackWrapper(), proxygen::HTTPSettings::getAllSettings(), proxygen::HTTPParallelCodec::getTransportDirection(), proxygen::getTransportDirectionString(), proxygen::HEADER_TABLE_SIZE, headerCodec_, proxygen::INITIAL_WINDOW_SIZE, proxygen::MAX_CONCURRENT_STREAMS, proxygen::MAX_FRAME_SIZE, proxygen::MAX_HEADER_LIST_SIZE, proxygen::HPACKCodec::setDecoderHeaderTableMaxSize(), proxygen::HPACKCodec::setMaxUncompressed(), proxygen::http2::SETTINGS, settings, proxygen::THRIFT_CHANNEL_ID, proxygen::THRIFT_CHANNEL_ID_DEPRECATED, proxygen::HTTPParallelCodec::transportDirection_, type, and proxygen::http2::writeSettings().

Referenced by getUserAgent(), and requestUpgrade().

1455  {
1456  std::deque<SettingPair> settings;
1457  for (auto& setting: egressSettings_.getAllSettings()) {
1458  switch (setting.id) {
1461  break;
1464  // HTTP/2 spec says downstream must not send this flag
1465  // HTTP2Codec uses it to determine if push features are enabled
1466  continue;
1467  } else {
1468  CHECK(setting.value == 0 || setting.value == 1);
1469  }
1470  break;
1474  break;
1476  headerCodec_.setMaxUncompressed(setting.value);
1477  break;
1479  CHECK(setting.value == 0 || setting.value == 1);
1480  if (setting.value == 0) {
1481  continue; // just skip the experimental setting if disabled
1482  } else {
1483  VLOG(4) << "generating ENABLE_EX_HEADERS=" << setting.value;
1484  }
1485  break;
1487  if (setting.value == 0) {
1488  continue;
1489  }
1490  break;
1493  break;
1494  default:
1495  LOG(ERROR) << "ignore unknown settingsId="
1497  << " value=" << setting.value;
1498  continue;
1499  }
1500 
1501  settings.push_back(SettingPair(setting.id, setting.value));
1502  }
1504  << " generating " << (unsigned)settings.size() << " settings";
1506  http2::writeSettings(writeBuf, settings));
1507 }
void setDecoderHeaderTableMaxSize(uint32_t size)
Definition: HPACKCodec.h:58
const char * getTransportDirectionString(TransportDirection dir)
HTTPSettings egressSettings_
Definition: HTTP2Codec.h:260
PskType type
static http_parser_settings settings
Definition: test.c:1529
size_t writeSettings(IOBufQueue &queue, const std::deque< SettingPair > &settings)
HPACKCodec headerCodec_
Definition: HTTP2Codec.h:240
void writeBuf(const Buf &buf, folly::io::Appender &out)
std::pair< SettingsId, uint32_t > SettingPair
Definition: SettingsId.h:58
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
const std::vector< HTTPSetting > & getAllSettings()
Definition: HTTPSettings.h:61
TransportDirection transportDirection_
TransportDirection getTransportDirection() const override
void setMaxUncompressed(uint64_t maxUncompressed) override
Definition: HPACKCodec.h:64
size_t proxygen::HTTP2Codec::generateSettingsAck ( folly::IOBufQueue )
overridevirtual

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

Reimplemented from proxygen::HTTPCodec.

Definition at line 1531 of file HTTP2Codec.cpp.

References generateHeaderCallbackWrapper(), proxygen::HTTPParallelCodec::getTransportDirection(), proxygen::getTransportDirectionString(), proxygen::http2::SETTINGS, and proxygen::http2::writeSettingsAck().

Referenced by getUserAgent().

1531  {
1533  << " generating settings ack";
1536 }
const char * getTransportDirectionString(TransportDirection dir)
void writeBuf(const Buf &buf, folly::io::Appender &out)
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
size_t writeSettingsAck(IOBufQueue &queue)
TransportDirection getTransportDirection() const override
size_t proxygen::HTTP2Codec::generateTrailers ( folly::IOBufQueue writeBuf,
StreamID  stream,
const HTTPHeaders trailers 
)
overridevirtual

Write the message trailers

Returns
number of bytes written

Implements proxygen::HTTPCodec.

Definition at line 1309 of file HTTP2Codec.cpp.

References folly::IOBufQueue::append(), proxygen::CodecUtil::appendHeaders(), folly::IOBufQueue::chainLength(), wangle::HTTPHeaderSize::compressed, encodeHeaders(), generateContinuation(), generateHeaderCallbackWrapper(), proxygen::http2::HEADERS, proxygen::HTTP_HEADER_NONE, proxygen::http2::kNoPadding, maxSendFrameSize(), min, folly::gen::move, folly::size(), folly::IOBufQueue::split(), and proxygen::http2::writeHeaders().

Referenced by getUserAgent().

1311  {
1312  std::vector<compress::Header> allHeaders;
1313  CodecUtil::appendHeaders(trailers, allHeaders, HTTP_HEADER_NONE);
1314 
1316  auto out = encodeHeaders(trailers, allHeaders, &size);
1317 
1318  IOBufQueue queue(IOBufQueue::cacheChainLength());
1319  queue.append(std::move(out));
1320  auto maxFrameSize = maxSendFrameSize();
1321  if (queue.chainLength() > 0) {
1323  auto remainingFrameSize = maxFrameSize;
1324  auto chunk = queue.split(std::min(remainingFrameSize, queue.chainLength()));
1325  bool endHeaders = queue.chainLength() == 0;
1328  http2::writeHeaders(writeBuf,
1329  std::move(chunk),
1330  stream,
1331  pri,
1333  true /*eom*/,
1334  endHeaders));
1335 
1336  if (!endHeaders) {
1337  generateContinuation(writeBuf, queue, stream, maxFrameSize);
1338  }
1339  }
1340 
1341  return size.compressed;
1342 }
void generateContinuation(folly::IOBufQueue &writeBuf, folly::IOBufQueue &queue, StreamID stream, size_t maxFrameSize)
wangle::HTTPHeaderSize HTTPHeaderSize
size_t writeHeaders(IOBufQueue &queue, std::unique_ptr< IOBuf > headers, uint32_t stream, folly::Optional< PriorityUpdate > priority, folly::Optional< uint8_t > padding, bool endStream, bool endHeaders) noexcept
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_t maxSendFrameSize() const
Definition: HTTP2Codec.h:229
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
LogLevel min
Definition: LogLevel.cpp:30
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
std::unique_ptr< folly::IOBuf > encodeHeaders(const HTTPHeaders &headers, std::vector< compress::Header > &allHeaders, HTTPHeaderSize *size)
static bool appendHeaders(const HTTPHeaders &inputHeaders, std::vector< compress::Header > &headers, HTTPHeaderCode headerToCheck)
Definition: CodecUtil.cpp:131
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
size_t proxygen::HTTP2Codec::generateWindowUpdate ( folly::IOBufQueue writeBuf,
StreamID  stream,
uint32_t  delta 
)
overridevirtual

Reimplemented from proxygen::HTTPCodec.

Definition at line 1538 of file HTTP2Codec.cpp.

References generateHeaderCallbackWrapper(), proxygen::HTTPParallelCodec::ingressGoawayAck_, proxygen::HTTPParallelCodec::isStreamIngressEgressAllowed(), proxygen::http2::WINDOW_UPDATE, and proxygen::http2::writeWindowUpdate().

Referenced by getUserAgent().

1540  {
1541  VLOG(4) << "generating window update for stream=" << stream
1542  << ": Processed " << delta << " bytes";
1544  VLOG(2) << "suppressed WINDOW_UPDATE for stream=" << stream
1545  << " ingressGoawayAck_=" << ingressGoawayAck_;
1546  return 0;
1547  }
1549  http2::writeWindowUpdate(writeBuf, stream, delta));
1550 }
bool isStreamIngressEgressAllowed(StreamID stream) const
size_t generateHeaderCallbackWrapper(StreamID stream, http2::FrameType type, size_t length)
size_t writeWindowUpdate(IOBufQueue &queue, uint32_t stream, uint32_t amount) noexcept
uint32_t proxygen::HTTP2Codec::getDefaultWindowSize ( ) const
inlineoverridevirtual

Get the default size of flow control windows for this protocol

Reimplemented from proxygen::HTTPCodec.

Definition at line 117 of file HTTP2Codec.h.

References proxygen::http2::kInitialWindow.

Referenced by TEST_F().

117  {
118  return http2::kInitialWindow;
119  }
const uint32_t kInitialWindow
HTTPSettings* proxygen::HTTP2Codec::getEgressSettings ( )
inlineoverridevirtual

Reimplemented from proxygen::HTTPCodec.

Definition at line 116 of file HTTP2Codec.h.

References egressSettings_.

116 { return &egressSettings_; }
HTTPSettings egressSettings_
Definition: HTTP2Codec.h:260
HPACKTableInfo proxygen::HTTP2Codec::getHPACKTableInfo ( ) const
inlineoverridevirtual

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 from proxygen::HTTPCodec.

Definition at line 151 of file HTTP2Codec.h.

References proxygen::HPACKCodec::getHPACKTableInfo(), headerCodec_, and requestUpgrade().

151  {
153  }
HPACKCodec headerCodec_
Definition: HTTP2Codec.h:240
HPACKTableInfo getHPACKTableInfo() const
Definition: HPACKCodec.h:69
const HTTPSettings* proxygen::HTTP2Codec::getIngressSettings ( ) const
inlineoverridevirtual

Reimplemented from proxygen::HTTPCodec.

Definition at line 113 of file HTTP2Codec.h.

References ingressSettings_.

113  {
114  return &ingressSettings_;
115  }
HTTPSettings ingressSettings_
Definition: HTTP2Codec.h:255
CodecProtocol proxygen::HTTP2Codec::getProtocol ( ) const
inlineoverridevirtual

Gets the session protocol currently used by the codec. This can be mapped to a string for logging and diagnostic use.

Implements proxygen::HTTPCodec.

Definition at line 40 of file HTTP2Codec.h.

References proxygen::HTTP_2.

Referenced by TEST().

uint64_t proxygen::HTTP2Codec::getReceivedFrameCount ( ) const
inline

Definition at line 160 of file HTTP2Codec.h.

References receivedFrameCount_.

160  {
161  return receivedFrameCount_;
162  }
uint64_t receivedFrameCount_
Definition: HTTP2Codec.h:267
const std::string& proxygen::HTTP2Codec::getUserAgent ( ) const
inlineoverridevirtual
ErrorCode proxygen::HTTP2Codec::handleEndStream ( )
private

Definition at line 252 of file HTTP2Codec.cpp.

References proxygen::http2::CONTINUATION, curHeader_, proxygen::http2::DATA, proxygen::HTTPParallelCodec::deliverCallbackIfAllowed(), proxygen::http2::END_STREAM, proxygen::http2::EX_HEADERS, expectedContinuationStream_, proxygen::http2::FrameHeader::flags, proxygen::http2::HEADERS, ingressWebsocketUpgrade_, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onMessageComplete(), pendingEndStreamHandling_, proxygen::http2::FrameHeader::stream, and proxygen::http2::FrameHeader::type.

Referenced by getHeaderIndexingStrategy(), parseAllData(), parseDataFrameData(), and parseHeadersImpl().

252  {
257  return ErrorCode::NO_ERROR;
258  }
259 
260  // do we need to handle case where this stream has already aborted via
261  // another callback (onHeadersComplete/onBody)?
263 
264  // with a websocket upgrade, we need to send message complete cb to
265  // mirror h1x codec's behavior. when the stream closes, we need to
266  // send another callback to clean up the stream's resources.
268  ingressWebsocketUpgrade_ = false;
270  "onMessageComplete", curHeader_.stream, true);
271  }
272 
276  "onMessageComplete", curHeader_.stream, false);
277  }
278  return ErrorCode::NO_ERROR;
279 }
bool deliverCallbackIfAllowed(T callbackFn, char const *cbName, StreamID stream, Args &&...args)
virtual void onMessageComplete(StreamID stream, bool upgrade)=0
bool pendingEndStreamHandling_
Definition: HTTP2Codec.h:245
StreamID expectedContinuationStream_
Definition: HTTP2Codec.h:244
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
ErrorCode proxygen::HTTP2Codec::handleSettings ( const std::deque< SettingPair > &  settings)
private

Definition at line 721 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::callback_, curHeader_, egressSettings_, proxygen::ENABLE_CONNECT_PROTOCOL, proxygen::ENABLE_EX_HEADERS, proxygen::ENABLE_PUSH, proxygen::HTTPSettings::getSetting(), proxygen::HTTPParallelCodec::getTransportDirection(), proxygen::getTransportDirectionString(), proxygen::HTTPParallelCodec::goawayErrorMessage_, proxygen::HEADER_TABLE_SIZE, headerCodec_, ingressSettings_, proxygen::INITIAL_WINDOW_SIZE, proxygen::http2::kMaxFramePayloadLength, proxygen::http2::kMaxFramePayloadLengthMin, proxygen::http2::kMaxHeaderTableSize, proxygen::http2::kMaxWindowUpdateSize, proxygen::MAX_CONCURRENT_STREAMS, proxygen::MAX_FRAME_SIZE, proxygen::MAX_HEADER_LIST_SIZE, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onSettings(), proxygen::PROTOCOL_ERROR, ptr, proxygen::HPACKCodec::setEncoderHeaderTableSize(), proxygen::HTTPSettings::setSetting(), proxygen::SETTINGS_HTTP_CERT_AUTH, proxygen::http2::FrameHeader::stream, proxygen::THRIFT_CHANNEL_ID, proxygen::THRIFT_CHANNEL_ID_DEPRECATED, proxygen::HTTPParallelCodec::transportDirection_, uint32_t, and proxygen::UPSTREAM.

Referenced by getHeaderIndexingStrategy(), onIngressUpgradeMessage(), and parseSettings().

721  {
722  SettingsList settingsList;
723  for (auto& setting: settings) {
724  switch (setting.first) {
726  {
727  uint32_t tableSize = setting.second;
728  if (setting.second > http2::kMaxHeaderTableSize) {
729  VLOG(2) << "Limiting table size from " << tableSize << " to " <<
731  tableSize = http2::kMaxHeaderTableSize;
732  }
734  }
735  break;
737  if ((setting.second != 0 && setting.second != 1) ||
738  (setting.second == 1 &&
740  goawayErrorMessage_ = folly::to<string>(
741  "GOAWAY error: ENABLE_PUSH invalid setting=", setting.second,
742  " for streamID=", curHeader_.stream);
743  VLOG(4) << goawayErrorMessage_;
745  }
746  break;
748  break;
750  if (setting.second > http2::kMaxWindowUpdateSize) {
751  goawayErrorMessage_ = folly::to<string>(
752  "GOAWAY error: INITIAL_WINDOW_SIZE invalid size=", setting.second,
753  " for streamID=", curHeader_.stream);
754  VLOG(4) << goawayErrorMessage_;
756  }
757  break;
759  if (setting.second < http2::kMaxFramePayloadLengthMin ||
760  setting.second > http2::kMaxFramePayloadLength) {
761  goawayErrorMessage_ = folly::to<string>(
762  "GOAWAY error: MAX_FRAME_SIZE invalid size=", setting.second,
763  " for streamID=", curHeader_.stream);
764  VLOG(4) << goawayErrorMessage_;
766  }
768  break;
770  break;
772  {
774  if (ptr && ptr->value > 0) {
776  << " got ENABLE_EX_HEADERS=" << setting.second;
777  if (setting.second != 0 && setting.second != 1) {
778  goawayErrorMessage_ = folly::to<string>(
779  "GOAWAY error: invalid ENABLE_EX_HEADERS=", setting.second,
780  " for streamID=", curHeader_.stream);
781  VLOG(4) << goawayErrorMessage_;
783  }
784  break;
785  } else {
786  // egress ENABLE_EX_HEADERS is disabled, consider the ingress
787  // ENABLE_EX_HEADERS as unknown setting, and ignore it.
788  continue;
789  }
790  }
792  if (setting.second > 1) {
793  goawayErrorMessage_ = folly::to<string>(
794  "GOAWAY error: ENABLE_CONNECT_PROTOCOL invalid number=",
795  setting.second, " for streamID=", curHeader_.stream);
796  VLOG(4) << goawayErrorMessage_;
798  }
799  break;
802  break;
804  break;
805  default:
806  continue; // ignore unknown setting
807  }
808  ingressSettings_.setSetting(setting.first, setting.second);
809  settingsList.push_back(*ingressSettings_.getSetting(setting.first));
810  }
811  if (callback_) {
812  callback_->onSettings(settingsList);
813  }
814  return ErrorCode::NO_ERROR;
815 }
void * ptr
HTTPSettings ingressSettings_
Definition: HTTP2Codec.h:255
virtual void onSettings(const SettingsList &)
Definition: HTTPCodec.h:251
const char * getTransportDirectionString(TransportDirection dir)
HTTPCodec::Callback * callback_
HTTPSettings egressSettings_
Definition: HTTP2Codec.h:260
void setEncoderHeaderTableSize(uint32_t size)
Definition: HPACKCodec.h:54
const uint32_t kMaxFramePayloadLength
HPACKCodec headerCodec_
Definition: HTTP2Codec.h:240
const uint32_t kMaxWindowUpdateSize
const uint32_t kMaxFramePayloadLengthMin
const uint32_t kMaxHeaderTableSize
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
std::vector< HTTPSetting > SettingsList
Definition: HTTPSettings.h:81
TransportDirection transportDirection_
TransportDirection getTransportDirection() const override
const HTTPSetting * getSetting(SettingsId id) const
void setSetting(SettingsId id, SettingsValue val)
HTTPCodec::StreamID proxygen::HTTP2Codec::mapPriorityToDependency ( uint8_t  ) const
overridevirtual

Map the given linear priority to the correct parent node dependency

Reimplemented from proxygen::HTTPCodec.

Definition at line 1627 of file HTTP2Codec.cpp.

References min, uint8_t, and virtualPriorityNodes_.

Referenced by isRequest().

1627  {
1628  // If the priority is out of the maximum index of virtual nodes array, we
1629  // return the lowest level virtual node as a punishment of not setting
1630  // priority correctly.
1631  return virtualPriorityNodes_.empty()
1632  ? 0
1634  std::min(priority, uint8_t(virtualPriorityNodes_.size() - 1))];
1635 }
LogLevel min
Definition: LogLevel.cpp:30
std::vector< StreamID > virtualPriorityNodes_
Definition: HTTP2Codec.h:283
size_t proxygen::HTTP2Codec::maxSendFrameSize ( ) const
inlineprivate
void proxygen::HTTP2Codec::onDecodeError ( HPACK::DecodeError  decodeError)
overridevirtual

Implements proxygen::HPACK::StreamingCallback.

Definition at line 646 of file HTTP2Codec.cpp.

References proxygen::HeaderDecodeInfo::decodeError, and decodeInfo_.

646  {
647  decodeInfo_.decodeError = decodeError;
648 }
HPACK::DecodeError decodeError
HeaderDecodeInfo decodeInfo_
Definition: HTTP2Codec.h:282
void proxygen::HTTP2Codec::onHeader ( const folly::fbstring name,
const folly::fbstring value 
)
overridevirtual

Implements proxygen::HPACK::StreamingCallback.

Definition at line 606 of file HTTP2Codec.cpp.

References decodeInfo_, headerCodec_, proxygen::HeaderDecodeInfo::onHeader(), proxygen::HeaderDecodeInfo::parsingError, folly::basic_fbstring< E, T, A, Storage >::toStdString(), proxygen::HTTPParallelCodec::transportDirection_, uint32_t, and userAgent_.

607  {
608  if (decodeInfo_.onHeader(name, value)) {
609  if (name == "user-agent" && userAgent_.empty()) {
610  userAgent_ = value.toStdString();
611  }
612  } else {
613  VLOG(4) << "dir=" << uint32_t(transportDirection_) <<
614  decodeInfo_.parsingError << " codec=" << headerCodec_;
615  }
616 }
HPACKCodec headerCodec_
Definition: HTTP2Codec.h:240
bool onHeader(const folly::fbstring &name, const folly::fbstring &value)
std::basic_string< E, T, A > toStdString() const
Definition: FBString.h:1227
HeaderDecodeInfo decodeInfo_
Definition: HTTP2Codec.h:282
TransportDirection transportDirection_
std::string userAgent_
Definition: HTTP2Codec.h:277
void proxygen::HTTP2Codec::onHeadersComplete ( HTTPHeaderSize  decodedSize)
overridevirtual

Implements proxygen::HPACK::StreamingCallback.

Definition at line 618 of file HTTP2Codec.cpp.

References proxygen::CONNECT, curHeader_, decodeInfo_, proxygen::DOWNSTREAM, proxygen::HTTPMessage::getMethod(), proxygen::HTTPMessage::getStatusCode(), proxygen::HTTPMessage::getUpgradeProtocol(), proxygen::HTTPRequestVerifier::hasUpgradeProtocol(), ingressWebsocketUpgrade_, proxygen::http2::kProtocolString, proxygen::headers::kWebsocketString, proxygen::HeaderDecodeInfo::msg, proxygen::HeaderDecodeInfo::onHeadersComplete(), proxygen::HeaderDecodeInfo::parsingError, proxygen::HTTPMessage::setIngressWebsocketUpgrade(), proxygen::http2::FrameHeader::stream, proxygen::HTTPParallelCodec::transportDirection_, upgradedStreams_, and proxygen::HeaderDecodeInfo::verifier.

618  {
619  decodeInfo_.onHeadersComplete(decodedSize);
620  decodeInfo_.msg->setAdvancedProtocolString(http2::kProtocolString);
621 
622  HTTPMessage* msg = decodeInfo_.msg.get();
623  HTTPRequestVerifier& verifier = decodeInfo_.verifier;
625  verifier.hasUpgradeProtocol() &&
626  (*msg->getUpgradeProtocol() == headers::kWebsocketString) &&
627  msg->getMethod() == HTTPMethod::CONNECT) {
628  msg->setIngressWebsocketUpgrade();
630  } else {
631  auto it = upgradedStreams_.find(curHeader_.stream);
632  if (it != upgradedStreams_.end()) {
634  // a websocket upgrade was sent on this stream.
635  if (msg->getStatusCode() != 200) {
637  folly::to<string>("Invalid response code to a websocket upgrade: ",
638  msg->getStatusCode());
639  return;
640  }
641  msg->setIngressWebsocketUpgrade();
642  }
643  }
644 }
const std::string kProtocolString
std::unique_ptr< HTTPMessage > msg
std::unordered_set< StreamID > upgradedStreams_
Definition: HTTP2Codec.h:248
HeaderDecodeInfo decodeInfo_
Definition: HTTP2Codec.h:282
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
TransportDirection transportDirection_
const std::string kWebsocketString
void onHeadersComplete(HTTPHeaderSize decodedSize)
HTTPRequestVerifier verifier
size_t proxygen::HTTP2Codec::onIngress ( const folly::IOBuf buf)
overridevirtual

Parse ingress data.

Parameters
bufA single IOBuf of data to parse
Returns
Number of bytes consumed.

Implements proxygen::HTTPCodec.

Definition at line 70 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::callback_, checkConnectionError(), curHeader_, proxygen::http2::DATA, proxygen::http2::FrameHeader::flags, FOLLY_SCOPED_TRACE_SECTION, proxygen::FRAME_SIZE_ERROR, frameState_, proxygen::http2::getFrameTypeString(), proxygen::HTTPParallelCodec::goawayErrorMessage_, proxygen::http2::kConnectionPreface, proxygen::http2::kFrameHeaderSize, proxygen::http2::FrameHeader::length, maxRecvFrameSize(), proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onFrameHeader(), parseDataFrameData(), parseFrame(), proxygen::http2::parseFrameHeader(), pendingDataFrameBytes_, pendingDataFramePaddingBytes_, proxygen::PROTOCOL_ERROR, folly::io::detail::CursorBase< Derived, BufType >::readFixedString(), receivedFrameCount_, proxygen::http2::SETTINGS, proxygen::http2::FrameHeader::stream, folly::io::detail::CursorBase< Derived, BufType >::totalLength(), and proxygen::http2::FrameHeader::type.

Referenced by getUserAgent().

70  {
71  // TODO: ensure only 1 parse at a time on stack.
72  FOLLY_SCOPED_TRACE_SECTION("HTTP2Codec - onIngress");
73 
74  Cursor cursor(&buf);
75  size_t parsed = 0;
76  ErrorCode connError = ErrorCode::NO_ERROR;
77  for (auto bufLen = cursor.totalLength();
78  connError == ErrorCode::NO_ERROR;
79  bufLen = cursor.totalLength()) {
80  if (frameState_ == FrameState::UPSTREAM_CONNECTION_PREFACE) {
81  if (bufLen >= http2::kConnectionPreface.length()) {
82  auto test = cursor.readFixedString(http2::kConnectionPreface.length());
83  parsed += http2::kConnectionPreface.length();
85  goawayErrorMessage_ = "missing connection preface";
86  VLOG(4) << goawayErrorMessage_;
87  connError = ErrorCode::PROTOCOL_ERROR;
88  }
89  frameState_ = FrameState::FRAME_HEADER;
90  } else {
91  break;
92  }
93  } else if (frameState_ == FrameState::FRAME_HEADER ||
94  frameState_ == FrameState::DOWNSTREAM_CONNECTION_PREFACE) {
95  // Waiting to parse the common frame header
96  if (bufLen >= http2::kFrameHeaderSize) {
97  connError = parseFrameHeader(cursor, curHeader_);
98  parsed += http2::kFrameHeaderSize;
99  if (frameState_ == FrameState::DOWNSTREAM_CONNECTION_PREFACE &&
101  goawayErrorMessage_ = folly::to<string>(
102  "GOAWAY error: got invalid connection preface frame type=",
104  " for streamID=", curHeader_.stream);
105  VLOG(4) << goawayErrorMessage_;
106  connError = ErrorCode::PROTOCOL_ERROR;
107  }
109  VLOG(4) << "Excessively large frame len=" << curHeader_.length;
110  connError = ErrorCode::FRAME_SIZE_ERROR;
111  }
112 
113  if (callback_) {
118  static_cast<uint8_t>(curHeader_.type));
119  }
120 
122  FrameState::DATA_FRAME_DATA : FrameState::FRAME_DATA;
125 #ifndef NDEBUG
127 #endif
128  } else {
129  break;
130  }
131  } else if (frameState_ == FrameState::DATA_FRAME_DATA && bufLen > 0 &&
132  (bufLen < curHeader_.length ||
134  // FrameState::DATA_FRAME_DATA with partial data only
135  size_t dataParsed = 0;
136  connError = parseDataFrameData(cursor, bufLen, dataParsed);
137  if (dataParsed == 0 && pendingDataFrameBytes_ > 0) {
138  // We received only the padding byte, we will wait for more
139  break;
140  } else {
141  parsed += dataParsed;
142  if (pendingDataFrameBytes_ == 0) {
143  frameState_ = FrameState::FRAME_HEADER;
144  }
145  }
146  } else { // FrameState::FRAME_DATA
147  // or FrameState::DATA_FRAME_DATA with all data available
148  // Already parsed the common frame header
149  const auto frameLen = curHeader_.length;
150  if (bufLen >= frameLen) {
151  connError = parseFrame(cursor);
152  parsed += curHeader_.length;
153  frameState_ = FrameState::FRAME_HEADER;
154  } else {
155  break;
156  }
157  }
158  }
159  checkConnectionError(connError, &buf);
160  return parsed;
161 }
#define FOLLY_SCOPED_TRACE_SECTION(arg,...)
ErrorCode parseFrame(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:163
ErrorCode parseDataFrameData(folly::io::Cursor &cursor, size_t bufLen, size_t &parsed)
Definition: HTTP2Codec.cpp:299
FrameState frameState_
Definition: HTTP2Codec.h:276
ErrorCode parseFrameHeader(Cursor &cursor, FrameHeader &header) noexcept
HTTPCodec::Callback * callback_
const uint32_t kFrameHeaderSize
size_t pendingDataFrameBytes_
Definition: HTTP2Codec.h:279
uint32_t maxRecvFrameSize() const
Definition: HTTP2Codec.h:233
virtual void onFrameHeader(StreamID, uint8_t, uint64_t, uint8_t, uint16_t=0)
Definition: HTTPCodec.h:206
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
uint64_t receivedFrameCount_
Definition: HTTP2Codec.h:267
size_t pendingDataFramePaddingBytes_
Definition: HTTP2Codec.h:280
bool checkConnectionError(ErrorCode, const folly::IOBuf *buf)
const std::string kConnectionPreface
const char * getFrameTypeString(FrameType type)
bool proxygen::HTTP2Codec::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 1010 of file HTTP2Codec.cpp.

References folly::IOBufQueue::append(), c, proxygen::HTTPMessage::getHeaders(), proxygen::HTTPHeaders::getNumberOfValues(), proxygen::HTTPHeaders::getSingleOrEmpty(), handleSettings(), proxygen::http2::kMaxFramePayloadLength, proxygen::http2::kProtocolSettingsHeader, folly::gen::move, proxygen::NO_ERROR, proxygen::HTTPParallelCodec::onIngressUpgradeMessage(), proxygen::http2::parseSettings(), proxygen::http2::SETTINGS, settings, and uint32_t.

Referenced by getUserAgent().

1010  {
1012  return false;
1013  }
1014  if (msg.getHeaders().getNumberOfValues(http2::kProtocolSettingsHeader) != 1) {
1015  VLOG(4) << __func__ << " with no HTTP2-Settings";
1016  return false;
1017  }
1018 
1019  const auto& settingsHeader = msg.getHeaders().getSingleOrEmpty(
1021  if (settingsHeader.empty()) {
1022  return true;
1023  }
1024 
1025  auto decoded = base64url_decode(settingsHeader);
1026 
1027  // Must be well formed Base64Url and not too large
1028  if (decoded.empty() || decoded.length() > http2::kMaxFramePayloadLength) {
1029  VLOG(4) << __func__ << " failed to decode HTTP2-Settings";
1030  return false;
1031  }
1032  std::unique_ptr<IOBuf> decodedBuf = IOBuf::wrapBuffer(decoded.data(),
1033  decoded.length());
1034  IOBufQueue settingsQueue{IOBufQueue::cacheChainLength()};
1035  settingsQueue.append(std::move(decodedBuf));
1036  Cursor c(settingsQueue.front());
1037  std::deque<SettingPair> settings;
1038  // downcast is ok because of above length check
1039  http2::FrameHeader frameHeader{
1040  (uint32_t)settingsQueue.chainLength(), 0, http2::FrameType::SETTINGS, 0, 0};
1041  auto err = http2::parseSettings(c, frameHeader, settings);
1042  if (err != ErrorCode::NO_ERROR) {
1043  VLOG(4) << __func__ << " bad settings frame";
1044  return false;
1045  }
1046 
1047  if (handleSettings(settings) != ErrorCode::NO_ERROR) {
1048  VLOG(4) << __func__ << " handleSettings failed";
1049  return false;
1050  }
1051 
1052  return true;
1053 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
bool onIngressUpgradeMessage(const HTTPMessage &msg) override
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
ErrorCode parseSettings(Cursor &cursor, const FrameHeader &header, std::deque< SettingPair > &settings) noexcept
const uint32_t kMaxFramePayloadLength
static http_parser_settings settings
Definition: test.c:1529
ErrorCode handleSettings(const std::deque< SettingPair > &settings)
Definition: HTTP2Codec.cpp:721
const std::string kProtocolSettingsHeader
char c
ErrorCode proxygen::HTTP2Codec::parseAllData ( folly::io::Cursor cursor)
private

Definition at line 281 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::callback_, curHeader_, proxygen::HTTPParallelCodec::deliverCallbackIfAllowed(), folly::IOBuf::empty(), handleEndStream(), proxygen::http2::FrameHeader::length, folly::gen::move, proxygen::HTTPCodec::Callback::onBody(), proxygen::http2::parseData(), RETURN_IF_ERROR, proxygen::http2::FrameHeader::stream, and uint16_t.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

281  {
282  std::unique_ptr<IOBuf> outData;
283  uint16_t padding = 0;
284  VLOG(10) << "parsing all frame DATA bytes for stream=" << curHeader_.stream <<
285  " length=" << curHeader_.length;
286  auto ret = http2::parseData(cursor, curHeader_, outData, padding);
287  RETURN_IF_ERROR(ret);
288 
289  if (callback_ && (padding > 0 || (outData && !outData->empty()))) {
290  if (!outData) {
291  outData = std::make_unique<IOBuf>();
292  }
294  curHeader_.stream, std::move(outData), padding);
295  }
296  return handleEndStream();
297 }
bool empty() const
Definition: IOBuf.cpp:482
bool deliverCallbackIfAllowed(T callbackFn, char const *cbName, StreamID stream, Args &&...args)
HTTPCodec::Callback * callback_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
ErrorCode handleEndStream()
Definition: HTTP2Codec.cpp:252
ErrorCode parseData(Cursor &cursor, const FrameHeader &header, std::unique_ptr< IOBuf > &outBuf, uint16_t &outPadding) noexcept
virtual void onBody(StreamID stream, std::unique_ptr< folly::IOBuf > chain, uint16_t padding)=0
ErrorCode proxygen::HTTP2Codec::parseCertificate ( folly::io::Cursor cursor)
private

Definition at line 945 of file HTTP2Codec.cpp.

References folly::IOBufQueue::append(), proxygen::HTTPParallelCodec::callback_, folly::IOBufQueue::chainLength(), folly::IOBufQueue::clear(), curAuthenticatorBlock_, curCertId_, curHeader_, folly::IOBufQueue::empty(), proxygen::http2::FrameHeader::flags, proxygen::http2::kMaxAuthenticatorBufSize, proxygen::http2::FrameHeader::length, folly::IOBufQueue::move(), folly::gen::move, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onCertificate(), proxygen::http2::parseCertificate(), proxygen::PROTOCOL_ERROR, RETURN_IF_ERROR, proxygen::http2::TO_BE_CONTINUED, and uint16_t.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

945  {
946  VLOG(4) << "parsing CERTIFICATE frame length=" << curHeader_.length;
947  uint16_t certId = 0;
948  std::unique_ptr<IOBuf> authData;
949  auto err = http2::parseCertificate(cursor, curHeader_, certId, authData);
950  RETURN_IF_ERROR(err);
952  curCertId_ = certId;
953  } else if (certId != curCertId_) {
954  // Received CERTIFICATE frame with different Cert-ID.
956  }
959  // Received excessively long authenticator.
961  }
963  auto authenticator = curAuthenticatorBlock_.move();
964  if (callback_) {
965  callback_->onCertificate(certId, std::move(authenticator));
966  } else {
968  }
969  }
970  return ErrorCode::NO_ERROR;
971 }
const uint32_t kMaxAuthenticatorBufSize
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
size_t chainLength() const
Definition: IOBufQueue.h:492
HTTPCodec::Callback * callback_
bool empty() const
Definition: IOBufQueue.h:503
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void onCertificate(uint16_t, std::unique_ptr< folly::IOBuf >)
Definition: HTTPCodec.h:310
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
ErrorCode parseCertificate(folly::io::Cursor &cursor, const FrameHeader &header, uint16_t &outCertId, std::unique_ptr< folly::IOBuf > &outAuthenticator) noexcept
folly::IOBufQueue curAuthenticatorBlock_
Definition: HTTP2Codec.h:251
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
ErrorCode proxygen::HTTP2Codec::parseCertificateRequest ( folly::io::Cursor cursor)
private

Definition at line 931 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::callback_, curHeader_, proxygen::http2::FrameHeader::length, folly::gen::move, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onCertificateRequest(), proxygen::http2::parseCertificateRequest(), RETURN_IF_ERROR, and uint16_t.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

931  {
932  VLOG(4) << "parsing CERTIFICATE_REQUEST frame length=" << curHeader_.length;
933  uint16_t requestId = 0;
934  std::unique_ptr<IOBuf> authRequest;
935 
937  cursor, curHeader_, requestId, authRequest);
938  RETURN_IF_ERROR(err);
939  if (callback_) {
940  callback_->onCertificateRequest(requestId, std::move(authRequest));
941  }
942  return ErrorCode::NO_ERROR;
943 }
HTTPCodec::Callback * callback_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
virtual void onCertificateRequest(uint16_t, std::unique_ptr< folly::IOBuf >)
Definition: HTTPCodec.h:297
ErrorCode parseCertificateRequest(folly::io::Cursor &cursor, const FrameHeader &header, uint16_t &outRequestId, std::unique_ptr< folly::IOBuf > &outAuthRequest) noexcept
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
ErrorCode proxygen::HTTP2Codec::parseContinuation ( folly::io::Cursor cursor)
private

Definition at line 413 of file HTTP2Codec.cpp.

References curHeader_, proxygen::http2::FrameHeader::length, folly::gen::move, folly::none, proxygen::http2::parseContinuation(), parseHeadersImpl(), RETURN_IF_ERROR, and proxygen::http2::FrameHeader::stream.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

413  {
414  std::unique_ptr<IOBuf> headerBuf;
415  VLOG(4) << "parsing CONTINUATION frame for stream=" << curHeader_.stream <<
416  " length=" << curHeader_.length;
417  auto err = http2::parseContinuation(cursor, curHeader_, headerBuf);
418  RETURN_IF_ERROR(err);
419  err = parseHeadersImpl(cursor, std::move(headerBuf),
421  return err;
422 }
ErrorCode parseContinuation(Cursor &cursor, const FrameHeader &header, std::unique_ptr< IOBuf > &outBuf) noexcept
ErrorCode parseHeadersImpl(folly::io::Cursor &cursor, std::unique_ptr< folly::IOBuf > headerBuf, const folly::Optional< http2::PriorityUpdate > &priority, const folly::Optional< uint32_t > &promisedStream, const folly::Optional< ExAttributes > &exAttributes)
Definition: HTTP2Codec.cpp:424
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
constexpr None none
Definition: Optional.h:87
ErrorCode proxygen::HTTP2Codec::parseDataFrameData ( folly::io::Cursor cursor,
size_t  bufLen,
size_t &  parsed 
)
private

Definition at line 299 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::callback_, folly::io::detail::CursorBase< Derived, BufType >::clone(), curHeader_, proxygen::HTTPParallelCodec::deliverCallbackIfAllowed(), folly::IOBuf::empty(), FOLLY_SCOPED_TRACE_SECTION, proxygen::http2::frameHasPadding(), handleEndStream(), proxygen::http2::FrameHeader::length, min, folly::gen::move, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onBody(), proxygen::http2::parseDataBegin(), proxygen::http2::parseDataEnd(), pendingDataFrameBytes_, pendingDataFramePaddingBytes_, RETURN_IF_ERROR, proxygen::http2::FrameHeader::stream, and uint16_t.

Referenced by getHeaderIndexingStrategy(), and onIngress().

301  {
302  FOLLY_SCOPED_TRACE_SECTION("HTTP2Codec - parseDataFrameData");
303  if (bufLen == 0) {
304  VLOG(10) << "No data to parse";
305  return ErrorCode::NO_ERROR;
306  }
307 
308  std::unique_ptr<IOBuf> outData;
309  uint16_t padding = 0;
310  VLOG(10) << "parsing DATA frame data for stream=" << curHeader_.stream <<
311  " frame data length=" << curHeader_.length << " pendingDataFrameBytes_=" <<
312  pendingDataFrameBytes_ << " pendingDataFramePaddingBytes_=" <<
313  pendingDataFramePaddingBytes_ << " bufLen=" << bufLen <<
314  " parsed=" << parsed;
315  // Parse the padding information only the first time
318  if (frameHasPadding(curHeader_) && bufLen == 1) {
319  // We need to wait for more bytes otherwise we won't be able to pass
320  // the correct padding to the first onBody call
321  return ErrorCode::NO_ERROR;
322  }
323  const auto ret = http2::parseDataBegin(cursor, curHeader_, parsed, padding);
324  RETURN_IF_ERROR(ret);
325  if (padding > 0) {
326  pendingDataFramePaddingBytes_ = padding - 1;
328  bufLen--;
329  parsed++;
330  }
331  VLOG(10) << "out padding=" << padding << " pendingDataFrameBytes_=" <<
332  pendingDataFrameBytes_ << " pendingDataFramePaddingBytes_=" <<
333  pendingDataFramePaddingBytes_ << " bufLen=" << bufLen <<
334  " parsed=" << parsed;
335  }
336  if (bufLen > 0) {
337  // Check if we have application data to parse
339  const size_t pendingAppData =
341  const size_t toClone = std::min(pendingAppData, bufLen);
342  cursor.clone(outData, toClone);
343  bufLen -= toClone;
344  pendingDataFrameBytes_ -= toClone;
345  parsed += toClone;
346  VLOG(10) << "parsed some app data, pendingDataFrameBytes_=" <<
347  pendingDataFrameBytes_ << " pendingDataFramePaddingBytes_=" <<
348  pendingDataFramePaddingBytes_ << " bufLen=" << bufLen <<
349  " parsed=" << parsed;
350  }
351  // Check if we have padding bytes to parse
352  if (bufLen > 0 && pendingDataFramePaddingBytes_ > 0) {
353  size_t toSkip = 0;
354  auto ret = http2::parseDataEnd(cursor, bufLen,
355  pendingDataFramePaddingBytes_, toSkip);
356  RETURN_IF_ERROR(ret);
357  pendingDataFrameBytes_ -= toSkip;
358  pendingDataFramePaddingBytes_ -= toSkip;
359  parsed += toSkip;
360  VLOG(10) << "parsed some padding, pendingDataFrameBytes_=" <<
361  pendingDataFrameBytes_ << " pendingDataFramePaddingBytes_=" <<
362  pendingDataFramePaddingBytes_ << " bufLen=" << bufLen <<
363  " parsed=" << parsed;
364  }
365  }
366 
367  if (callback_ && (padding > 0 || (outData && !outData->empty()))) {
368  if (!outData) {
369  outData = std::make_unique<IOBuf>();
370  }
372  curHeader_.stream, std::move(outData), padding);
373  }
375 }
#define FOLLY_SCOPED_TRACE_SECTION(arg,...)
bool empty() const
Definition: IOBuf.cpp:482
bool deliverCallbackIfAllowed(T callbackFn, char const *cbName, StreamID stream, Args &&...args)
HTTPCodec::Callback * callback_
void clone(std::unique_ptr< folly::IOBuf > &buf, size_t len)
Definition: Cursor.h:456
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool frameHasPadding(const FrameHeader &header)
size_t pendingDataFrameBytes_
Definition: HTTP2Codec.h:279
LogLevel min
Definition: LogLevel.cpp:30
ErrorCode parseDataBegin(Cursor &cursor, const FrameHeader &header, size_t &, uint16_t &outPadding) noexcept
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
size_t pendingDataFramePaddingBytes_
Definition: HTTP2Codec.h:280
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
ErrorCode handleEndStream()
Definition: HTTP2Codec.cpp:252
virtual void onBody(StreamID stream, std::unique_ptr< folly::IOBuf > chain, uint16_t padding)=0
ErrorCode parseDataEnd(Cursor &cursor, const size_t bufLen, const size_t pendingDataFramePaddingBytes, size_t &toSkip) noexcept
ErrorCode proxygen::HTTP2Codec::parseExHeaders ( folly::io::Cursor cursor)
private

Definition at line 395 of file HTTP2Codec.cpp.

References checkNewStream(), curHeader_, FOLLY_SCOPED_TRACE_SECTION, isRequest(), proxygen::http2::FrameHeader::length, folly::gen::move, folly::none, proxygen::http2::parseExHeaders(), parseHeadersImpl(), RETURN_IF_ERROR, and proxygen::http2::FrameHeader::stream.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

395  {
396  FOLLY_SCOPED_TRACE_SECTION("HTTP2Codec - parseExHeaders");
397  HTTPCodec::ExAttributes exAttributes;
399  std::unique_ptr<IOBuf> headerBuf;
400  VLOG(4) << "parsing ExHEADERS frame for stream=" << curHeader_.stream
401  << " length=" << curHeader_.length;
402  auto err = http2::parseExHeaders(
403  cursor, curHeader_, exAttributes, priority, headerBuf);
404  RETURN_IF_ERROR(err);
405  if (isRequest(curHeader_.stream)) {
407  checkNewStream(curHeader_.stream, false /* trailersAllowed */));
408  }
409  return parseHeadersImpl(cursor, std::move(headerBuf), priority, folly::none,
410  exAttributes);
411 }
#define FOLLY_SCOPED_TRACE_SECTION(arg,...)
ErrorCode parseHeadersImpl(folly::io::Cursor &cursor, std::unique_ptr< folly::IOBuf > headerBuf, const folly::Optional< http2::PriorityUpdate > &priority, const folly::Optional< uint32_t > &promisedStream, const folly::Optional< ExAttributes > &exAttributes)
Definition: HTTP2Codec.cpp:424
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
ErrorCode checkNewStream(uint32_t stream, bool trailersAllowed)
Definition: HTTP2Codec.cpp:973
ErrorCode parseExHeaders(Cursor &cursor, const FrameHeader &header, HTTPCodec::ExAttributes &outExAttributes, folly::Optional< PriorityUpdate > &outPriority, std::unique_ptr< IOBuf > &outBuf) noexcept
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
constexpr None none
Definition: Optional.h:87
bool isRequest(StreamID id) const
Definition: HTTP2Codec.h:138
ErrorCode proxygen::HTTP2Codec::parseFrame ( folly::io::Cursor cursor)
private

Definition at line 163 of file HTTP2Codec.cpp.

References proxygen::http2::ALTSVC, proxygen::http2::CERTIFICATE, proxygen::http2::CERTIFICATE_REQUEST, folly::IOBufQueue::chainLength(), proxygen::http2::CONTINUATION, curHeader_, curHeaderBlock_, proxygen::http2::DATA, egressSettings_, proxygen::ENABLE_EX_HEADERS, proxygen::http2::END_HEADERS, proxygen::ERROR, proxygen::http2::EX_HEADERS, expectedContinuationStream_, proxygen::http2::FrameHeader::flags, FOLLY_SCOPED_TRACE_SECTION, proxygen::http2::frameAffectsCompression(), proxygen::http2::getFrameTypeString(), proxygen::HTTPSettings::getSetting(), proxygen::http2::GOAWAY, proxygen::HTTPParallelCodec::goawayErrorMessage_, proxygen::http2::HEADERS, ingressSettings_, proxygen::http2::FrameHeader::length, proxygen::MAX_HEADER_LIST_SIZE, proxygen::NO_ERROR, parseAllData(), parseCertificate(), parseCertificateRequest(), parseContinuation(), parseExHeaders(), parseGoaway(), parseHeaders(), parsePing(), parsePriority(), parsePushPromise(), parseRstStream(), parseSettings(), parseWindowUpdate(), proxygen::http2::PING, proxygen::http2::PRIORITY, proxygen::PROTOCOL_ERROR, proxygen::http2::PUSH_PROMISE, proxygen::http2::RST_STREAM, proxygen::http2::SETTINGS, folly::io::detail::CursorBase< Derived, BufType >::skip(), proxygen::http2::FrameHeader::stream, proxygen::http2::FrameHeader::type, uint8_t, and proxygen::http2::WINDOW_UPDATE.

Referenced by getHeaderIndexingStrategy(), and onIngress().

163  {
164  FOLLY_SCOPED_TRACE_SECTION("HTTP2Codec - parseFrame");
165  if (expectedContinuationStream_ != 0 &&
168  goawayErrorMessage_ = folly::to<string>(
169  "GOAWAY error: while expected CONTINUATION with stream=",
170  expectedContinuationStream_, ", received streamID=", curHeader_.stream,
171  " of type=", getFrameTypeString(curHeader_.type));
172  VLOG(4) << goawayErrorMessage_;
174  }
175  if (expectedContinuationStream_ == 0 &&
177  goawayErrorMessage_ = folly::to<string>(
178  "GOAWAY error: unexpected CONTINUATION received with streamID=",
180  VLOG(4) << goawayErrorMessage_;
182  }
186  // this may be off by up to the padding length (max 255), but
187  // these numbers are already so generous, and we're comparing the
188  // max-uncompressed to the actual compressed size. Let's fail
189  // before buffering.
190 
191  // TODO(t6513634): it would be nicer to stream-process this header
192  // block to keep the connection state consistent without consuming
193  // memory, and fail just the request per the HTTP/2 spec (section
194  // 10.3)
195  goawayErrorMessage_ = folly::to<string>(
196  "Failing connection due to excessively large headers");
197  LOG(ERROR) << goawayErrorMessage_;
199  }
200 
204 
205  switch (curHeader_.type) {
207  return parseAllData(cursor);
209  return parseHeaders(cursor);
211  return parsePriority(cursor);
213  return parseRstStream(cursor);
215  return parseSettings(cursor);
217  return parsePushPromise(cursor);
220  return parseExHeaders(cursor);
221  } else {
222  VLOG(2) << "EX_HEADERS not enabled, ignoring the frame";
223  break;
224  }
226  return parsePing(cursor);
228  return parseGoaway(cursor);
230  return parseWindowUpdate(cursor);
232  return parseContinuation(cursor);
234  // fall through, unimplemented
235  break;
237  return parseCertificateRequest(cursor);
239  return parseCertificate(cursor);
240  default:
241  // Implementations MUST ignore and discard any frame that has a
242  // type that is unknown
243  break;
244  }
245 
246  // Landing here means unknown, unimplemented or ignored frame.
247  VLOG(2) << "Skipping frame (type=" << (uint8_t)curHeader_.type << ")";
248  cursor.skip(curHeader_.length);
249  return ErrorCode::NO_ERROR;
250 }
#define FOLLY_SCOPED_TRACE_SECTION(arg,...)
ErrorCode parsePushPromise(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:817
size_t chainLength() const
Definition: IOBufQueue.h:492
folly::IOBufQueue curHeaderBlock_
Definition: HTTP2Codec.h:254
ErrorCode parseWindowUpdate(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:898
HTTPSettings ingressSettings_
Definition: HTTP2Codec.h:255
ErrorCode parseContinuation(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:413
ErrorCode parseCertificateRequest(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:931
ErrorCode parseCertificate(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:945
HTTPSettings egressSettings_
Definition: HTTP2Codec.h:260
ErrorCode parseGoaway(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:869
ErrorCode parseAllData(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:281
StreamID expectedContinuationStream_
Definition: HTTP2Codec.h:244
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
ErrorCode parseExHeaders(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:395
void skip(size_t len)
Definition: Cursor.h:371
ErrorCode parseSettings(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:705
ErrorCode parseRstStream(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:686
ErrorCode parsePriority(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:650
bool frameAffectsCompression(FrameType t)
const char * getFrameTypeString(FrameType type)
ErrorCode parsePing(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:854
const HTTPSetting * getSetting(SettingsId id) const
ErrorCode parseHeaders(folly::io::Cursor &cursor)
Definition: HTTP2Codec.cpp:378
ErrorCode proxygen::HTTP2Codec::parseGoaway ( folly::io::Cursor cursor)
private

Definition at line 869 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::callback_, curHeader_, folly::IOBuf::data(), proxygen::empty_string, proxygen::getErrorCodeString(), proxygen::HTTPParallelCodec::ingressGoawayAck_, proxygen::http2::FrameHeader::length, folly::IOBuf::length(), folly::gen::move, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onGoaway(), proxygen::http2::parseGoaway(), RETURN_IF_ERROR, statusCode, uint32_t, userAgent_, and folly::WARNING.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

869  {
870  VLOG(4) << "parsing GOAWAY frame length=" << curHeader_.length;
871  uint32_t lastGoodStream = 0;
873  std::unique_ptr<IOBuf> debugData;
874 
875  auto err = http2::parseGoaway(cursor, curHeader_, lastGoodStream, statusCode,
876  debugData);
877  if (statusCode != ErrorCode::NO_ERROR) {
878  VLOG(2) << "Goaway error statusCode=" << getErrorCodeString(statusCode)
879  << " lastStream=" << lastGoodStream
880  << " user-agent=" << userAgent_ << " debugData=" <<
881  ((debugData) ? string((char*)debugData->data(), debugData->length()):
882  empty_string);
883  }
884  RETURN_IF_ERROR(err);
885  if (lastGoodStream < ingressGoawayAck_) {
886  ingressGoawayAck_ = lastGoodStream;
887  // Drain all streams <= lastGoodStream
888  // and abort streams > lastGoodStream
889  if (callback_) {
890  callback_->onGoaway(lastGoodStream, statusCode, std::move(debugData));
891  }
892  } else {
893  LOG(WARNING) << "Received multiple GOAWAY with increasing ack";
894  }
895  return ErrorCode::NO_ERROR;
896 }
spdy::GoawayStatusCode statusCode
Definition: SPDYCodec.cpp:110
ErrorCode parseGoaway(Cursor &cursor, const FrameHeader &header, uint32_t &outLastStreamID, ErrorCode &outCode, std::unique_ptr< IOBuf > &outDebugData) noexcept
HTTPCodec::Callback * callback_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const char * getErrorCodeString(ErrorCode error)
Definition: ErrorCode.cpp:18
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
if(FOLLY_USE_SYMBOLIZER) add_library(folly_exception_tracer_base ExceptionTracer.cpp StackTrace.cpp) apply_folly_compile_options_to_target(folly_exception_tracer_base) target_link_libraries(folly_exception_tracer_base PUBLIC folly) add_library(folly_exception_tracer ExceptionStackTraceLib.cpp ExceptionTracerLib.cpp) apply_folly_compile_options_to_target(folly_exception_tracer) target_link_libraries(folly_exception_tracer PUBLIC folly_exception_tracer_base) add_library(folly_exception_counter ExceptionCounterLib.cpp) apply_folly_compile_options_to_target(folly_exception_counter) target_link_libraries(folly_exception_counter PUBLIC folly_exception_tracer) install(FILES ExceptionAbi.h ExceptionCounterLib.h ExceptionTracer.h ExceptionTracerLib.h StackTrace.h DESTINATION $
Definition: CMakeLists.txt:1
const std::string empty_string
Definition: HTTPHeaders.cpp:23
virtual void onGoaway(uint64_t, ErrorCode, std::unique_ptr< folly::IOBuf >=nullptr)
Definition: HTTPCodec.h:220
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
std::string userAgent_
Definition: HTTP2Codec.h:277
ErrorCode proxygen::HTTP2Codec::parseHeaders ( folly::io::Cursor cursor)
private

Definition at line 378 of file HTTP2Codec.cpp.

References checkNewStream(), curHeader_, proxygen::DOWNSTREAM, FOLLY_SCOPED_TRACE_SECTION, proxygen::http2::FrameHeader::length, folly::gen::move, folly::none, proxygen::http2::parseHeaders(), parseHeadersImpl(), RETURN_IF_ERROR, proxygen::http2::FrameHeader::stream, and proxygen::HTTPParallelCodec::transportDirection_.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

378  {
379  FOLLY_SCOPED_TRACE_SECTION("HTTP2Codec - parseHeaders");
381  std::unique_ptr<IOBuf> headerBuf;
382  VLOG(4) << "parsing HEADERS frame for stream=" << curHeader_.stream <<
383  " length=" << curHeader_.length;
384  auto err = http2::parseHeaders(cursor, curHeader_, priority, headerBuf);
385  RETURN_IF_ERROR(err);
388  checkNewStream(curHeader_.stream, true /* trailersAllowed */));
389  }
390  err = parseHeadersImpl(cursor, std::move(headerBuf), priority, folly::none,
391  folly::none);
392  return err;
393 }
#define FOLLY_SCOPED_TRACE_SECTION(arg,...)
ErrorCode parseHeadersImpl(folly::io::Cursor &cursor, std::unique_ptr< folly::IOBuf > headerBuf, const folly::Optional< http2::PriorityUpdate > &priority, const folly::Optional< uint32_t > &promisedStream, const folly::Optional< ExAttributes > &exAttributes)
Definition: HTTP2Codec.cpp:424
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
ErrorCode checkNewStream(uint32_t stream, bool trailersAllowed)
Definition: HTTP2Codec.cpp:973
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
ErrorCode parseHeaders(Cursor &cursor, const FrameHeader &header, folly::Optional< PriorityUpdate > &outPriority, std::unique_ptr< IOBuf > &outBuf) noexcept
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
TransportDirection transportDirection_
constexpr None none
Definition: Optional.h:87
folly::Optional< ErrorCode > proxygen::HTTP2Codec::parseHeadersCheckConcurrentStreams ( const folly::Optional< http2::PriorityUpdate > &  priority)
private

Definition at line 585 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::callback_, curHeader_, egressSettings_, proxygen::http2::EX_HEADERS, proxygen::http2::FrameHeader::flags, proxygen::HTTPSettings::getSetting(), proxygen::http2::HEADERS, max, proxygen::MAX_CONCURRENT_STREAMS, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::numIncomingStreams(), proxygen::http2::PRIORITY, proxygen::REFUSED_STREAM, streamError(), and proxygen::http2::FrameHeader::type.

Referenced by getHeaderIndexingStrategy(), and parseHeadersImpl().

586  {
590  DCHECK(priority);
591  // callback_->onPriority(priority.get());
592  }
593 
594  // callback checks total number of streams is smaller than settings max
595  if (callback_->numIncomingStreams() >=
598  streamError(folly::to<string>("Exceeded max_concurrent_streams"),
600  return ErrorCode::NO_ERROR;
601  }
602  }
604 }
LogLevel max
Definition: LogLevel.cpp:31
HTTPCodec::Callback * callback_
HTTPSettings egressSettings_
Definition: HTTP2Codec.h:260
virtual uint32_t numIncomingStreams() const
Definition: HTTPCodec.h:327
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
void streamError(const std::string &msg, ErrorCode error, bool newTxn=false)
const HTTPSetting * getSetting(SettingsId id) const
folly::Optional< ErrorCode > proxygen::HTTP2Codec::parseHeadersDecodeFrames ( const folly::Optional< http2::PriorityUpdate > &  priority,
const folly::Optional< uint32_t > &  promisedStream,
const folly::Optional< ExAttributes > &  exAttributes,
std::unique_ptr< HTTPMessage > &  msg 
)
private

Definition at line 507 of file HTTP2Codec.cpp.

References proxygen::HTTPParallelCodec::callback_, folly::IOBufQueue::chainLength(), proxygen::COMPRESSION_ERROR, curHeader_, curHeaderBlock_, proxygen::HeaderDecodeInfo::decodeError, decodeInfo_, proxygen::HPACKCodec::decodeStreaming(), proxygen::DOWNSTREAM, proxygen::ERROR, folly::IOBufQueue::front(), g(), headerCodec_, proxygen::http2::HEADERS, proxygen::HPACK::HEADERS_TOO_LARGE, proxygen::HTTPException::INGRESS, proxygen::HeaderDecodeInfo::init(), isRequest(), std::tr1::make_tuple(), folly::makeGuard(), folly::IOBufQueue::move(), folly::gen::move, proxygen::HeaderDecodeInfo::msg, proxygen::NO_ERROR, proxygen::HPACK::NONE, proxygen::HTTPCodec::Callback::onError(), parsingDownstreamTrailers_, proxygen::HeaderDecodeInfo::parsingError, proxygen::IOBufPrinter::printHexFolly(), proxygen::PROTOCOL_ERROR, proxygen::http2::FrameHeader::stream, streamError(), string, proxygen::HTTPParallelCodec::transportDirection_, and proxygen::http2::FrameHeader::type.

Referenced by getHeaderIndexingStrategy(), and parseHeadersImpl().

511  {
512  // decompress headers
513  Cursor headerCursor(curHeaderBlock_.front());
514  bool isReq = false;
515  if (promisedStream) {
516  isReq = true;
517  } else if (exAttributes) {
518  isReq = isRequest(curHeader_.stream);
519  } else {
521  }
522 
524  if (priority) {
525  if (curHeader_.stream == priority->streamDependency) {
526  streamError(folly::to<string>("Circular dependency for txn=",
530  return ErrorCode::NO_ERROR;
531  }
532 
533  decodeInfo_.msg->setHTTP2Priority(
534  std::make_tuple(priority->streamDependency,
535  priority->exclusive,
536  priority->weight));
537  }
539  headerCursor, curHeaderBlock_.chainLength(), this);
540  msg = std::move(decodeInfo_.msg);
541  // Saving this in case we need to log it on error
542  auto g = folly::makeGuard([this] { curHeaderBlock_.move(); });
543  // Check decoding error
545  static const std::string decodeErrorMessage =
546  "Failed decoding header block for stream=";
547  // Avoid logging header blocks that have failed decoding due to being
548  // excessively large.
550  LOG(ERROR) << decodeErrorMessage << curHeader_.stream
551  << " header block=";
553  } else {
554  LOG(ERROR) << decodeErrorMessage << curHeader_.stream;
555  }
556 
557  if (msg) {
558  // print the partial message
559  msg->dumpMessage(3);
560  }
562  }
563 
564  // Check parsing error
565  if (decodeInfo_.parsingError != "") {
566  LOG(ERROR) << "Failed parsing header list for stream=" << curHeader_.stream
567  << ", error=" << decodeInfo_.parsingError << ", header block=";
569  HTTPException err(HTTPException::Direction::INGRESS,
570  folly::to<std::string>("HTTP2Codec stream error: ",
571  "stream=",
573  " status=",
574  400,
575  " error: ",
577  err.setHttpStatusCode(400);
578  callback_->onError(curHeader_.stream, err, true);
579  return ErrorCode::NO_ERROR;
580  }
581 
583 }
const folly::IOBuf * front() const
Definition: IOBufQueue.h:476
size_t chainLength() const
Definition: IOBufQueue.h:492
virtual void onError(StreamID stream, const HTTPException &error, bool newTxn=false)=0
folly::IOBufQueue curHeaderBlock_
Definition: HTTP2Codec.h:254
void decodeStreaming(folly::io::Cursor &cursor, uint32_t length, HPACK::StreamingCallback *streamingCb) noexcept
Definition: HPACKCodec.cpp:67
static std::string printHexFolly(const folly::IOBuf *buf, bool coalesce=false)
Definition: Logging.h:127
HTTPCodec::Callback * callback_
std::unique_ptr< HTTPMessage > msg
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
tuple make_tuple()
Definition: gtest-tuple.h:675
HPACK::DecodeError decodeError
HPACKCodec headerCodec_
Definition: HTTP2Codec.h:240
HeaderDecodeInfo decodeInfo_
Definition: HTTP2Codec.h:282
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
FOLLY_NODISCARD detail::ScopeGuardImplDecay< F, true > makeGuard(F &&f) noexcept(noexcept(detail::ScopeGuardImplDecay< F, true >(static_cast< F && >(f))))
Definition: ScopeGuard.h:184
void streamError(const std::string &msg, ErrorCode error, bool newTxn=false)
bool parsingDownstreamTrailers_
Definition: HTTP2Codec.h:292
const char * string
Definition: Conv.cpp:212
g_t g(f_t)
void init(bool isRequestIn, bool isRequestTrailers)
TransportDirection transportDirection_
bool isRequest(StreamID id) const
Definition: HTTP2Codec.h:138
ErrorCode proxygen::HTTP2Codec::parseHeadersImpl ( folly::io::Cursor cursor,
std::unique_ptr< folly::IOBuf headerBuf,
const folly::Optional< http2::PriorityUpdate > &  priority,
const folly::Optional< uint32_t > &  promisedStream,
const folly::Optional< ExAttributes > &  exAttributes 
)
private

Definition at line 424 of file HTTP2Codec.cpp.

References folly::IOBufQueue::append(), proxygen::HTTPParallelCodec::callback_, proxygen::http2::CONTINUATION, proxygen::HTTPCodec::ExAttributes::controlStream, curHeader_, curHeaderBlock_, proxygen::HTTPParallelCodec::deliverCallbackIfAllowed(), proxygen::http2::END_HEADERS, proxygen::http2::END_STREAM, proxygen::http2::EX_HEADERS, proxygen::http2::FrameHeader::flags, handleEndStream(), headerBlockFrameType_, proxygen::http2::HEADERS, folly::gen::move, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onExMessageBegin(), proxygen::HTTPCodec::Callback::onHeadersComplete(), proxygen::HTTPCodec::Callback::onMessageBegin(), proxygen::HTTPCodec::Callback::onPushMessageBegin(), proxygen::HTTPCodec::Callback::onTrailersComplete(), parseHeadersCheckConcurrentStreams(), parseHeadersDecodeFrames(), parsingTrailers(), proxygen::http2::PUSH_PROMISE, proxygen::http2::FrameHeader::stream, proxygen::HTTPParallelCodec::transportDirection_, proxygen::http2::FrameHeader::type, uint32_t, and proxygen::HTTPCodec::ExAttributes::unidirectional.

Referenced by getHeaderIndexingStrategy(), parseContinuation(), parseExHeaders(), parseHeaders(), and parsePushPromise().

429  {
430  curHeaderBlock_.append(std::move(headerBuf));
431  std::unique_ptr<HTTPMessage> msg;
433  auto errorCode =
434  parseHeadersDecodeFrames(priority, promisedStream, exAttributes, msg);
435  if (errorCode.hasValue()) {
436  return errorCode.value();
437  }
438  }
439 
440  // if we're not parsing CONTINUATION, then it's start of new header block
443  }
444 
445  // Report back what we've parsed
446  if (callback_) {
447  auto concurError = parseHeadersCheckConcurrentStreams(priority);
448  if (concurError.hasValue()) {
449  return concurError.value();
450  }
451  uint32_t headersCompleteStream = curHeader_.stream;
452  bool trailers = parsingTrailers();
453  bool allHeaderFramesReceived =
456  if (allHeaderFramesReceived && !trailers) {
457  // Only deliver onMessageBegin once per stream.
458  // For responses with CONTINUATION, this will be delayed until
459  // the frame with the END_HEADERS flag set.
461  "onMessageBegin",
463  msg.get())) {
464  return handleEndStream();
465  }
468  "onExMessageBegin",
470  exAttributes->controlStream,
471  exAttributes->unidirectional,
472  msg.get())) {
473  return handleEndStream();
474  }
476  DCHECK(promisedStream);
478  "onPushMessageBegin", *promisedStream,
479  curHeader_.stream, msg.get())) {
480  return handleEndStream();
481  }
482  headersCompleteStream = *promisedStream;
483  }
484 
485  if (curHeader_.flags & http2::END_HEADERS && msg) {
487  // If it there are DATA frames coming, consider it chunked
488  msg->setIsChunked(true);
489  }
490  if (trailers) {
491  VLOG(4) << "Trailers complete for streamId=" << headersCompleteStream
492  << " direction=" << transportDirection_;
493  auto trailerHeaders =
494  std::make_unique<HTTPHeaders>(msg->extractHeaders());
495  msg.reset();
496  callback_->onTrailersComplete(headersCompleteStream,
497  std::move(trailerHeaders));
498  } else {
499  callback_->onHeadersComplete(headersCompleteStream, std::move(msg));
500  }
501  }
502  return handleEndStream();
503  }
504  return ErrorCode::NO_ERROR;
505 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
virtual void onMessageBegin(StreamID stream, HTTPMessage *msg)=0
folly::IOBufQueue curHeaderBlock_
Definition: HTTP2Codec.h:254
http2::FrameType headerBlockFrameType_
Definition: HTTP2Codec.h:296
bool deliverCallbackIfAllowed(T callbackFn, char const *cbName, StreamID stream, Args &&...args)
virtual void onExMessageBegin(StreamID, StreamID, bool, HTTPMessage *)
Definition: HTTPCodec.h:107
HTTPCodec::Callback * callback_
virtual void onTrailersComplete(StreamID stream, std::unique_ptr< HTTPHeaders > trailers)=0
folly::Optional< ErrorCode > parseHeadersDecodeFrames(const folly::Optional< http2::PriorityUpdate > &priority, const folly::Optional< uint32_t > &promisedStream, const folly::Optional< ExAttributes > &exAttributes, std::unique_ptr< HTTPMessage > &msg)
Definition: HTTP2Codec.cpp:507
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::Optional< ErrorCode > parseHeadersCheckConcurrentStreams(const folly::Optional< http2::PriorityUpdate > &priority)
Definition: HTTP2Codec.cpp:585
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
virtual void onHeadersComplete(StreamID stream, std::unique_ptr< HTTPMessage > msg)=0
virtual void onPushMessageBegin(StreamID, StreamID, HTTPMessage *)
Definition: HTTPCodec.h:95
TransportDirection transportDirection_
ErrorCode handleEndStream()
Definition: HTTP2Codec.cpp:252
bool parsingTrailers() const
ErrorCode proxygen::HTTP2Codec::parsePing ( folly::io::Cursor cursor)
private

Definition at line 854 of file HTTP2Codec.cpp.

References proxygen::http2::ACK, proxygen::HTTPParallelCodec::callback_, curHeader_, proxygen::http2::FrameHeader::flags, proxygen::http2::FrameHeader::length, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onPingReply(), proxygen::HTTPCodec::Callback::onPingRequest(), proxygen::http2::parsePing(), RETURN_IF_ERROR, and uint64_t.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

854  {
855  VLOG(4) << "parsing PING frame length=" << curHeader_.length;
856  uint64_t opaqueData = 0;
857  auto err = http2::parsePing(cursor, curHeader_, opaqueData);
858  RETURN_IF_ERROR(err);
859  if (callback_) {
860  if (curHeader_.flags & http2::ACK) {
861  callback_->onPingReply(opaqueData);
862  } else {
863  callback_->onPingRequest(opaqueData);
864  }
865  }
866  return ErrorCode::NO_ERROR;
867 }
HTTPCodec::Callback * callback_
virtual void onPingReply(uint64_t)
Definition: HTTPCodec.h:237
virtual void onPingRequest(uint64_t)
Definition: HTTPCodec.h:230
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
ErrorCode parsePing(Cursor &cursor, const FrameHeader &header, uint64_t &outOpaqueData) noexcept
ErrorCode proxygen::HTTP2Codec::parsePriority ( folly::io::Cursor cursor)
private

Definition at line 650 of file HTTP2Codec.cpp.

References curHeader_, proxygen::HTTPParallelCodec::deliverCallbackIfAllowed(), proxygen::http2::PriorityUpdate::exclusive, proxygen::http2::FrameHeader::length, std::tr1::make_tuple(), proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onPriority(), proxygen::http2::parsePriority(), proxygen::PROTOCOL_ERROR, RETURN_IF_ERROR, proxygen::http2::FrameHeader::stream, proxygen::http2::PriorityUpdate::streamDependency, streamError(), and proxygen::http2::PriorityUpdate::weight.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

650  {
651  VLOG(4) << "parsing PRIORITY frame for stream=" << curHeader_.stream <<
652  " length=" << curHeader_.length;
653  http2::PriorityUpdate pri;
654  auto err = http2::parsePriority(cursor, curHeader_, pri);
655  RETURN_IF_ERROR(err);
656  if (curHeader_.stream == pri.streamDependency) {
657  streamError(folly::to<string>("Circular dependency for txn=",
660  return ErrorCode::NO_ERROR;
661  }
664  std::make_tuple(pri.streamDependency,
665  pri.exclusive,
666  pri.weight));
667  return ErrorCode::NO_ERROR;
668 }
bool deliverCallbackIfAllowed(T callbackFn, char const *cbName, StreamID stream, Args &&...args)
ErrorCode parsePriority(Cursor &cursor, const FrameHeader &header, PriorityUpdate &outPriority) noexcept
virtual void onPriority(StreamID, const HTTPMessage::HTTPPriority &)
Definition: HTTPCodec.h:263
tuple make_tuple()
Definition: gtest-tuple.h:675
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
void streamError(const std::string &msg, ErrorCode error, bool newTxn=false)
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
ErrorCode proxygen::HTTP2Codec::parsePushPromise ( folly::io::Cursor cursor)
private

Definition at line 817 of file HTTP2Codec.cpp.

References checkNewStream(), curHeader_, egressSettings_, proxygen::ENABLE_PUSH, proxygen::HTTPSettings::getSetting(), proxygen::HTTPParallelCodec::goawayErrorMessage_, proxygen::http2::FrameHeader::length, folly::gen::move, folly::none, parseHeadersImpl(), proxygen::http2::parsePushPromise(), proxygen::PROTOCOL_ERROR, RETURN_IF_ERROR, proxygen::http2::FrameHeader::stream, proxygen::HTTPParallelCodec::transportDirection_, uint32_t, and proxygen::UPSTREAM.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

817  {
818  // stream id must be idle - protocol error
819  // assoc-stream-id=closed/unknown - protocol error, unless rst_stream sent
820 
821  /*
822  * What does "must handle" mean in the following context? I have to
823  * accept this as a valid pushed resource?
824 
825  However, an endpoint that has sent RST_STREAM on the associated
826  stream MUST handle PUSH_PROMISE frames that might have been
827  created before the RST_STREAM frame is received and processed.
828  */
830  goawayErrorMessage_ = folly::to<string>(
831  "Received PUSH_PROMISE on DOWNSTREAM codec");
832  VLOG(2) << goawayErrorMessage_;
834  }
836  goawayErrorMessage_ = folly::to<string>(
837  "Received PUSH_PROMISE on codec with push disabled");
838  VLOG(2) << goawayErrorMessage_;
840  }
841  VLOG(4) << "parsing PUSH_PROMISE frame for stream=" << curHeader_.stream <<
842  " length=" << curHeader_.length;
843  uint32_t promisedStream;
844  std::unique_ptr<IOBuf> headerBlockFragment;
845  auto err = http2::parsePushPromise(cursor, curHeader_, promisedStream,
846  headerBlockFragment);
847  RETURN_IF_ERROR(err);
848  RETURN_IF_ERROR(checkNewStream(promisedStream, false /* trailersAllowed */));
849  err = parseHeadersImpl(cursor, std::move(headerBlockFragment), folly::none,
850  promisedStream, folly::none);
851  return err;
852 }
ErrorCode parsePushPromise(Cursor &cursor, const FrameHeader &header, uint32_t &outPromisedStream, std::unique_ptr< IOBuf > &outBuf) noexcept
ErrorCode parseHeadersImpl(folly::io::Cursor &cursor, std::unique_ptr< folly::IOBuf > headerBuf, const folly::Optional< http2::PriorityUpdate > &priority, const folly::Optional< uint32_t > &promisedStream, const folly::Optional< ExAttributes > &exAttributes)
Definition: HTTP2Codec.cpp:424
HTTPSettings egressSettings_
Definition: HTTP2Codec.h:260
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
ErrorCode checkNewStream(uint32_t stream, bool trailersAllowed)
Definition: HTTP2Codec.cpp:973
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
TransportDirection transportDirection_
constexpr None none
Definition: Optional.h:87
const HTTPSetting * getSetting(SettingsId id) const
ErrorCode proxygen::HTTP2Codec::parseRstStream ( folly::io::Cursor cursor)
private

Definition at line 686 of file HTTP2Codec.cpp.

References curHeader_, proxygen::HTTPParallelCodec::deliverCallbackIfAllowed(), proxygen::getErrorCodeString(), proxygen::HTTPParallelCodec::goawayErrorMessage_, proxygen::http2::FrameHeader::length, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onAbort(), proxygen::http2::parseRstStream(), proxygen::PROTOCOL_ERROR, RETURN_IF_ERROR, statusCode, proxygen::http2::FrameHeader::stream, upgradedStreams_, and userAgent_.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

686  {
687  // rst for stream in idle state - protocol error
688  VLOG(4) << "parsing RST_STREAM frame for stream=" << curHeader_.stream <<
689  " length=" << curHeader_.length;
692  auto err = http2::parseRstStream(cursor, curHeader_, statusCode);
693  RETURN_IF_ERROR(err);
694  if (statusCode == ErrorCode::PROTOCOL_ERROR) {
695  goawayErrorMessage_ = folly::to<string>(
696  "GOAWAY error: RST_STREAM with code=", getErrorCodeString(statusCode),
697  " for streamID=", curHeader_.stream, " user-agent=", userAgent_);
698  VLOG(2) << goawayErrorMessage_;
699  }
701  curHeader_.stream, statusCode);
702  return ErrorCode::NO_ERROR;
703 }
spdy::GoawayStatusCode statusCode
Definition: SPDYCodec.cpp:110
bool deliverCallbackIfAllowed(T callbackFn, char const *cbName, StreamID stream, Args &&...args)
std::unordered_set< StreamID > upgradedStreams_
Definition: HTTP2Codec.h:248
ErrorCode parseRstStream(Cursor &cursor, const FrameHeader &header, ErrorCode &outCode) noexcept
const char * getErrorCodeString(ErrorCode error)
Definition: ErrorCode.cpp:18
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
virtual void onAbort(StreamID, ErrorCode)
Definition: HTTPCodec.h:192
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
std::string userAgent_
Definition: HTTP2Codec.h:277
ErrorCode proxygen::HTTP2Codec::parseSettings ( folly::io::Cursor cursor)
private

Definition at line 705 of file HTTP2Codec.cpp.

References proxygen::http2::ACK, proxygen::HTTPParallelCodec::callback_, curHeader_, proxygen::http2::FrameHeader::flags, handleSettings(), proxygen::http2::FrameHeader::length, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onSettingsAck(), proxygen::http2::parseSettings(), RETURN_IF_ERROR, settings, and proxygen::http2::FrameHeader::stream.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

705  {
706  VLOG(4) << "parsing SETTINGS frame for stream=" << curHeader_.stream <<
707  " length=" << curHeader_.length;
708  std::deque<SettingPair> settings;
709  auto err = http2::parseSettings(cursor, curHeader_, settings);
710  RETURN_IF_ERROR(err);
711  if (curHeader_.flags & http2::ACK) {
712  // for stats
713  if (callback_) {
715  }
716  return ErrorCode::NO_ERROR;
717  }
718  return handleSettings(settings);
719 }
HTTPCodec::Callback * callback_
ErrorCode parseSettings(Cursor &cursor, const FrameHeader &header, std::deque< SettingPair > &settings) noexcept
static http_parser_settings settings
Definition: test.c:1529
ErrorCode handleSettings(const std::deque< SettingPair > &settings)
Definition: HTTP2Codec.cpp:721
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
virtual void onSettingsAck()
Definition: HTTPCodec.h:257
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
ErrorCode proxygen::HTTP2Codec::parseWindowUpdate ( folly::io::Cursor cursor)
private

Definition at line 898 of file HTTP2Codec.cpp.

References curHeader_, proxygen::HTTPParallelCodec::deliverCallbackIfAllowed(), proxygen::HTTPParallelCodec::goawayErrorMessage_, proxygen::http2::FrameHeader::length, proxygen::NO_ERROR, proxygen::HTTPCodec::Callback::onWindowUpdate(), proxygen::http2::parseWindowUpdate(), proxygen::PROTOCOL_ERROR, RETURN_IF_ERROR, proxygen::http2::FrameHeader::stream, streamError(), and uint32_t.

Referenced by getHeaderIndexingStrategy(), and parseFrame().

898  {
899  VLOG(4) << "parsing WINDOW_UPDATE frame for stream=" << curHeader_.stream <<
900  " length=" << curHeader_.length;
901  uint32_t delta = 0;
902  auto err = http2::parseWindowUpdate(cursor, curHeader_, delta);
903  RETURN_IF_ERROR(err);
904  if (delta == 0) {
905  VLOG(4) << "Invalid 0 length delta for stream=" << curHeader_.stream;
906  if (curHeader_.stream == 0) {
907  goawayErrorMessage_ = folly::to<string>(
908  "GOAWAY error: invalid/0 length delta for streamID=",
911  } else {
912  // Parsing a zero delta window update should cause a protocol error
913  // and send a rst stream
914  goawayErrorMessage_ = folly::to<string>(
915  "parseWindowUpdate Invalid 0 length");
916  VLOG(4) << goawayErrorMessage_;
917  streamError(folly::to<std::string>("streamID=", curHeader_.stream,
918  " with HTTP2Codec stream error: ",
919  "window update delta=", delta),
922  }
923  }
924  // if window exceeds 2^31-1, connection/stream error flow control error
925  // must be checked in session/txn
927  "onWindowUpdate", curHeader_.stream, delta);
928  return ErrorCode::NO_ERROR;
929 }
bool deliverCallbackIfAllowed(T callbackFn, char const *cbName, StreamID stream, Args &&...args)
ErrorCode parseWindowUpdate(Cursor &cursor, const FrameHeader &header, uint32_t &outAmount) noexcept
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
void streamError(const std::string &msg, ErrorCode error, bool newTxn=false)
virtual void onWindowUpdate(StreamID, uint32_t)
Definition: HTTPCodec.h:243
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
bool proxygen::HTTP2Codec::parsingTrailers ( ) const
private

Definition at line 1637 of file HTTP2Codec.cpp.

References proxygen::http2::CONTINUATION, curHeader_, decodeInfo_, proxygen::DOWNSTREAM, proxygen::HeaderDecodeInfo::hasStatus(), proxygen::http2::HEADERS, parsingDownstreamTrailers_, proxygen::HTTPParallelCodec::transportDirection_, and proxygen::http2::FrameHeader::type.

Referenced by maxRecvFrameSize(), and parseHeadersImpl().

1637  {
1638  // HEADERS frame is used for request/response headers and trailers.
1639  // Per spec, specific role of HEADERS frame is determined by it's postion
1640  // within the stream. We don't keep full stream state in this codec,
1641  // thus using heuristics to distinguish between headers/trailers.
1642  // For DOWNSTREAM case, request headers HEADERS frame would be creating
1643  // new stream, thus HEADERS on existing stream ID are considered trailers
1644  // (see checkNewStream).
1645  // For UPSTREAM case, response headers are required to have status code,
1646  // thus if no status code we consider that trailers.
1651  } else {
1652  return !decodeInfo_.hasStatus();
1653  }
1654  }
1655  return false;
1656 }
HeaderDecodeInfo decodeInfo_
Definition: HTTP2Codec.h:282
http2::FrameHeader curHeader_
Definition: HTTP2Codec.h:243
bool parsingDownstreamTrailers_
Definition: HTTP2Codec.h:292
TransportDirection transportDirection_
bool proxygen::HTTP2Codec::peerHasWebsockets ( ) const
inline
void proxygen::HTTP2Codec::requestUpgrade ( HTTPMessage request)
static

Definition at line 1509 of file HTTP2Codec.cpp.

References proxygen::HTTPMessage::checkForHeaderToken(), generateSettings(), proxygen::HTTPMessage::getHeaders(), proxygen::HTTP_HEADER_CONNECTION, proxygen::HTTP_HEADER_UPGRADE, proxygen::http2::kFrameHeaderSize, proxygen::http2::kProtocolCleartextString, proxygen::http2::kProtocolSettingsHeader, proxygen::HTTPHeaders::set(), proxygen::UPSTREAM, and fizz::detail::writeBuf().

Referenced by getHPACKTableInfo(), and TEST_F().

1509  {
1510  static HTTP2Codec defaultCodec(TransportDirection::UPSTREAM);
1511 
1512  auto& headers = request.getHeaders();
1514  if (!request.checkForHeaderToken(HTTP_HEADER_CONNECTION, "Upgrade", false)) {
1515  headers.add(HTTP_HEADER_CONNECTION, "Upgrade");
1516  }
1517  IOBufQueue writeBuf{IOBufQueue::cacheChainLength()};
1518  defaultCodec.generateSettings(writeBuf);
1519  writeBuf.trimStart(http2::kFrameHeaderSize);
1520  auto buf = writeBuf.move();
1521  buf->coalesce();
1522  headers.set(http2::kProtocolSettingsHeader,
1523  base64url_encode(folly::ByteRange(buf->data(), buf->length())));
1524  if (!request.checkForHeaderToken(HTTP_HEADER_CONNECTION,
1526  false)) {
1528  }
1529 }
HTTP2Codec(TransportDirection direction)
Definition: HTTP2Codec.cpp:42
const uint32_t kFrameHeaderSize
const std::string kProtocolCleartextString
void writeBuf(const Buf &buf, folly::io::Appender &out)
const std::string kProtocolSettingsHeader
void proxygen::HTTP2Codec::setHeaderCodecStats ( HeaderCodec::Stats )
inlineoverridevirtual

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

Reimplemented from proxygen::HTTPCodec.

Definition at line 134 of file HTTP2Codec.h.

References headerCodec_, and proxygen::HeaderCodec::setStats().

134  {
135  headerCodec_.setStats(hcStats);
136  }
HPACKCodec headerCodec_
Definition: HTTP2Codec.h:240
void setStats(Stats *stats)
Definition: HeaderCodec.h:84
void proxygen::HTTP2Codec::setHeaderIndexingStrategy ( const HeaderIndexingStrategy indexingStrat)
inline

Definition at line 171 of file HTTP2Codec.h.

References headerCodec_, and proxygen::HPACKCodec::setHeaderIndexingStrategy().

Referenced by proxygen::HTTPSessionBase::initCodecHeaderIndexingStrategy().

171  {
173  }
HPACKCodec headerCodec_
Definition: HTTP2Codec.h:240
void setHeaderIndexingStrategy(const HeaderIndexingStrategy *indexingStrat)
Definition: HPACKCodec.h:78
void proxygen::HTTP2Codec::setReuseIOBufHeadroomForData ( bool  enabled)
inline

Definition at line 167 of file HTTP2Codec.h.

References reuseIOBufHeadroomForData_.

167  {
168  reuseIOBufHeadroomForData_ = enabled;
169  }
bool reuseIOBufHeadroomForData_
Definition: HTTP2Codec.h:284
void proxygen::HTTP2Codec::streamError ( const std::string msg,
ErrorCode  error,
bool  newTxn = false 
)
private
bool proxygen::HTTP2Codec::supportsExTransactions ( ) const
inlineoverridevirtual

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

Reimplemented from proxygen::HTTPCodec.

Definition at line 130 of file HTTP2Codec.h.

References egressSettings_, proxygen::ENABLE_EX_HEADERS, proxygen::HTTPSettings::getSetting(), and ingressSettings_.

bool proxygen::HTTP2Codec::supportsPushTransactions ( ) const
inlineoverridevirtual

Member Data Documentation

folly::IOBufQueue proxygen::HTTP2Codec::curAuthenticatorBlock_
private
Initial value:

Definition at line 251 of file HTTP2Codec.h.

Referenced by parseCertificate().

uint16_t proxygen::HTTP2Codec::curCertId_ {0}
private

Definition at line 250 of file HTTP2Codec.h.

Referenced by parseCertificate().

folly::IOBufQueue proxygen::HTTP2Codec::curHeaderBlock_ {folly::IOBufQueue::cacheChainLength()}
private

Definition at line 254 of file HTTP2Codec.h.

Referenced by parseFrame(), parseHeadersDecodeFrames(), and parseHeadersImpl().

HeaderDecodeInfo proxygen::HTTP2Codec::decodeInfo_
private
StreamID proxygen::HTTP2Codec::expectedContinuationStream_ {0}
private

Definition at line 244 of file HTTP2Codec.h.

Referenced by handleEndStream(), and parseFrame().

FrameState proxygen::HTTP2Codec::frameState_
private

Definition at line 276 of file HTTP2Codec.h.

Referenced by onIngress().

http2::FrameType proxygen::HTTP2Codec::headerBlockFrameType_ {http2::FrameType::DATA}
private

Definition at line 296 of file HTTP2Codec.h.

Referenced by parseHeadersImpl().

bool proxygen::HTTP2Codec::ingressWebsocketUpgrade_ {false}
private

Definition at line 246 of file HTTP2Codec.h.

Referenced by generateRstStream(), handleEndStream(), and onHeadersComplete().

bool proxygen::HTTP2Codec::parsingDownstreamTrailers_ {false}
private

Definition at line 292 of file HTTP2Codec.h.

Referenced by checkNewStream(), parseHeadersDecodeFrames(), and parsingTrailers().

size_t proxygen::HTTP2Codec::pendingDataFrameBytes_ {0}
private

Definition at line 279 of file HTTP2Codec.h.

Referenced by onIngress(), and parseDataFrameData().

size_t proxygen::HTTP2Codec::pendingDataFramePaddingBytes_ {0}
private

Definition at line 280 of file HTTP2Codec.h.

Referenced by onIngress(), and parseDataFrameData().

bool proxygen::HTTP2Codec::pendingEndStreamHandling_ {false}
private

Definition at line 245 of file HTTP2Codec.h.

Referenced by generateRstStream(), and handleEndStream().

uint64_t proxygen::HTTP2Codec::receivedFrameCount_ {0}
private

Definition at line 267 of file HTTP2Codec.h.

Referenced by getReceivedFrameCount(), and onIngress().

bool proxygen::HTTP2Codec::reuseIOBufHeadroomForData_ {true}
private

Definition at line 284 of file HTTP2Codec.h.

Referenced by generateBody(), generateEOM(), and setReuseIOBufHeadroomForData().

std::unordered_set<StreamID> proxygen::HTTP2Codec::upgradedStreams_
private
std::string proxygen::HTTP2Codec::userAgent_
private
std::vector<StreamID> proxygen::HTTP2Codec::virtualPriorityNodes_
private

Definition at line 283 of file HTTP2Codec.h.

Referenced by addPriorityNodes(), and mapPriorityToDependency().


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