proxygen
proxygen::http2 Namespace Reference

Classes

struct  FrameHeader
 
struct  PriorityUpdate
 

Typedefs

using Padding = folly::Optional< uint8_t >
 

Enumerations

enum  FrameType : uint8_t {
  FrameType::DATA = 0, FrameType::HEADERS = 1, PRIORITY = 2, FrameType::RST_STREAM = 3,
  FrameType::SETTINGS = 4, FrameType::PUSH_PROMISE = 5, FrameType::PING = 6, FrameType::GOAWAY = 7,
  FrameType::WINDOW_UPDATE = 8, FrameType::CONTINUATION = 9, FrameType::ALTSVC = 10, FrameType::EX_HEADERS = 0xfb,
  FrameType::CERTIFICATE_REQUEST = 0xf0, FrameType::CERTIFICATE = 0xf1, FrameType::CERTIFICATE_NEEDED = 0xf2, FrameType::USE_CERTIFICATE = 0xf3
}
 
enum  Flags {
  ACK = 0x1, END_STREAM = 0x1, END_HEADERS = 0x4, PADDED = 0x8,
  PRIORITY = 0x20, PRIORITY = 2, UNIDIRECTIONAL = 0x40, UNSOLICITED = 0x1,
  TO_BE_CONTINUED = 0x1
}
 

Functions

ErrorCode filterInvalidStream (ErrorCode code)
 
ErrorCode errorCodeToGoaway (ErrorCode code)
 
ErrorCode errorCodeToReset (ErrorCode code)
 
const std::string kConnectionPreface ("PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n")
 
const std::string kProtocolString ("h2")
 
const std::string kProtocolDraftString ("h2-14")
 
const std::string kProtocolExperimentalString ("h2-fb")
 
const std::string kProtocolCleartextString ("h2c")
 
const std::string kProtocolSettingsHeader ("HTTP2-Settings")
 
bool isValidFrameType (FrameType type)
 
bool frameAffectsCompression (FrameType t)
 
bool frameHasPadding (const FrameHeader &header)
 
ErrorCode parseFrameHeader (Cursor &cursor, FrameHeader &header) noexcept
 
ErrorCode parseData (Cursor &cursor, const FrameHeader &header, std::unique_ptr< IOBuf > &outBuf, uint16_t &outPadding) noexcept
 
ErrorCode parseDataBegin (Cursor &cursor, const FrameHeader &header, size_t &, uint16_t &outPadding) noexcept
 
ErrorCode parseDataEnd (Cursor &cursor, const size_t bufLen, const size_t pendingDataFramePaddingBytes, size_t &toSkip) noexcept
 
ErrorCode parseHeaders (Cursor &cursor, const FrameHeader &header, folly::Optional< PriorityUpdate > &outPriority, std::unique_ptr< IOBuf > &outBuf) noexcept
 
ErrorCode parseExHeaders (Cursor &cursor, const FrameHeader &header, HTTPCodec::ExAttributes &outExAttributes, folly::Optional< PriorityUpdate > &outPriority, std::unique_ptr< IOBuf > &outBuf) noexcept
 
ErrorCode parsePriority (Cursor &cursor, const FrameHeader &header, PriorityUpdate &outPriority) noexcept
 
ErrorCode parseRstStream (Cursor &cursor, const FrameHeader &header, ErrorCode &outCode) noexcept
 
ErrorCode parseSettings (Cursor &cursor, const FrameHeader &header, std::deque< SettingPair > &settings) noexcept
 
ErrorCode parsePushPromise (Cursor &cursor, const FrameHeader &header, uint32_t &outPromisedStream, std::unique_ptr< IOBuf > &outBuf) noexcept
 
ErrorCode parsePing (Cursor &cursor, const FrameHeader &header, uint64_t &outOpaqueData) noexcept
 
ErrorCode parseGoaway (Cursor &cursor, const FrameHeader &header, uint32_t &outLastStreamID, ErrorCode &outCode, std::unique_ptr< IOBuf > &outDebugData) noexcept
 
ErrorCode parseWindowUpdate (Cursor &cursor, const FrameHeader &header, uint32_t &outAmount) noexcept
 
ErrorCode parseContinuation (Cursor &cursor, const FrameHeader &header, std::unique_ptr< IOBuf > &outBuf) noexcept
 
ErrorCode parseAltSvc (Cursor &cursor, const FrameHeader &header, uint32_t &outMaxAge, uint32_t &outPort, std::string &outProtocol, std::string &outHost, std::string &outOrigin) noexcept
 
ErrorCode parseCertificateRequest (folly::io::Cursor &cursor, const FrameHeader &header, uint16_t &outRequestId, std::unique_ptr< folly::IOBuf > &outAuthRequest) noexcept
 
ErrorCode parseCertificate (folly::io::Cursor &cursor, const FrameHeader &header, uint16_t &outCertId, std::unique_ptr< folly::IOBuf > &outAuthenticator) noexcept
 
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 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
 
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
 
size_t writePriority (IOBufQueue &queue, uint32_t stream, PriorityUpdate priority) noexcept
 
size_t writeRstStream (IOBufQueue &queue, uint32_t stream, ErrorCode errorCode) noexcept
 
size_t writeSettings (IOBufQueue &queue, const std::deque< SettingPair > &settings)
 
size_t writeSettingsAck (IOBufQueue &queue)
 
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 writePing (IOBufQueue &queue, uint64_t opaqueData, bool ack) noexcept
 
size_t writeGoaway (IOBufQueue &queue, uint32_t lastStreamID, ErrorCode errorCode, std::unique_ptr< IOBuf > debugData) noexcept
 
size_t writeWindowUpdate (IOBufQueue &queue, uint32_t stream, uint32_t amount) noexcept
 
size_t writeContinuation (IOBufQueue &queue, uint32_t stream, bool endHeaders, std::unique_ptr< IOBuf > headers) noexcept
 
size_t writeAltSvc (IOBufQueue &queue, uint32_t stream, uint32_t maxAge, uint16_t port, StringPiece protocol, StringPiece host, StringPiece origin) noexcept
 
size_t writeCertificateRequest (folly::IOBufQueue &writeBuf, uint16_t requestId, std::unique_ptr< folly::IOBuf > authRequest)
 
size_t writeCertificate (folly::IOBufQueue &writeBuf, uint16_t certId, std::unique_ptr< folly::IOBuf > authenticator, bool toBeContinued)
 
const char * getFrameTypeString (FrameType type)
 

Variables

const uint32_t kFrameHeaderSize = 9
 
const uint32_t kFrameHeadersBaseMaxSize = kFramePrioritySize + 1
 
const uint32_t kFramePrioritySize = 5
 
const uint32_t kFrameStreamIDSize = 4
 
const uint32_t kFrameRstStreamSize = 4
 
const uint32_t kFramePushPromiseSize = 4
 
const uint32_t kFramePingSize = 8
 
const uint32_t kFrameGoawaySize = 8
 
const uint32_t kFrameWindowUpdateSize = 4
 
const uint32_t kFrameCertificateRequestSizeBase = 2
 
const uint32_t kFrameCertificateSizeBase = 2
 
const uint32_t kFrameAltSvcSizeBase = 8
 
const uint32_t kMaxFramePayloadLengthMin = (1u << 14)
 
const uint32_t kMaxFramePayloadLength = (1u << 24) - 1
 
const uint32_t kMaxStreamID = (1u << 31) - 1
 
const uint32_t kInitialWindow = (1u << 16) - 1
 
const uint32_t kMaxWindowUpdateSize = (1u << 31) - 1
 
const uint32_t kMaxHeaderTableSize = (1u << 16)
 
const uint32_t kMaxAuthenticatorBufSize = 0x20000
 
const std::string kConnectionPreface
 
const std::string kProtocolString
 
const std::string kProtocolDraftString
 
const std::string kProtocolExperimentalString
 
const std::string kProtocolCleartextString
 
const std::string kProtocolSettingsHeader
 
const uint8_t kMinExperimentalFrameType = 0xf0
 
const Padding kNoPadding = folly::none
 
const PriorityUpdate DefaultPriority {0, false, 15}
 

Typedef Documentation

Definition at line 30 of file HTTP2Framer.h.

Enumeration Type Documentation

Enumerator
ACK 
END_STREAM 
END_HEADERS 
PADDED 
PRIORITY 
PRIORITY 
UNIDIRECTIONAL 
UNSOLICITED 
TO_BE_CONTINUED 

Definition at line 59 of file HTTP2Framer.h.

59  {
60  ACK = 0x1,
61  END_STREAM = 0x1,
62  END_HEADERS = 0x4,
63  PADDED = 0x8,
64  PRIORITY = 0x20,
65  // experimental flag for EX stream only
66  UNIDIRECTIONAL = 0x40,
67 
68  // for secondary certificate authentication frames
69  UNSOLICITED = 0x1,
70  TO_BE_CONTINUED = 0x1,
71 };
Enumerator
DATA 
HEADERS 
PRIORITY 
RST_STREAM 
SETTINGS 
PUSH_PROMISE 
PING 
GOAWAY 
WINDOW_UPDATE 
CONTINUATION 
ALTSVC 
EX_HEADERS 
CERTIFICATE_REQUEST 
CERTIFICATE 
CERTIFICATE_NEEDED 
USE_CERTIFICATE 

Definition at line 35 of file HTTP2Framer.h.

Function Documentation

ErrorCode proxygen::http2::errorCodeToGoaway ( ErrorCode  code)

Definition at line 22 of file HTTP2Constants.cpp.

References filterInvalidStream().

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

22  {
23  return filterInvalidStream(code);
24 }
ErrorCode filterInvalidStream(ErrorCode code)
ErrorCode proxygen::http2::errorCodeToReset ( ErrorCode  code)

Definition at line 26 of file HTTP2Constants.cpp.

References filterInvalidStream().

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

26  {
27  return filterInvalidStream(code);
28 }
ErrorCode filterInvalidStream(ErrorCode code)
ErrorCode proxygen::http2::filterInvalidStream ( ErrorCode  code)

Definition at line 14 of file HTTP2Constants.cpp.

References proxygen::_SPDY_INVALID_STREAM, and proxygen::STREAM_CLOSED.

Referenced by errorCodeToGoaway(), and errorCodeToReset().

14  {
15  // _SPDY_INVALID_STREAM is SPDY specific, filter it out
16  if (code == ErrorCode::_SPDY_INVALID_STREAM) {
17  return ErrorCode::STREAM_CLOSED;
18  }
19  return code;
20 }
bool proxygen::http2::frameAffectsCompression ( FrameType  t)

Definition at line 244 of file HTTP2Framer.cpp.

References proxygen::spdy::HEADERS.

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

244  {
245  return t == FrameType::HEADERS ||
246  t == FrameType::PUSH_PROMISE ||
247  t == FrameType::CONTINUATION;
248 }
bool proxygen::http2::frameHasPadding ( const FrameHeader header)

This function returns true if the padding bit is set in the header

Parameters
headerThe frame header.
Returns
true if the padding bit is set, false otherwise.

Definition at line 250 of file HTTP2Framer.cpp.

References proxygen::http2::FrameHeader::flags, and PADDED.

Referenced by parseData(), parseDataBegin(), and proxygen::HTTP2Codec::parseDataFrameData().

250  {
251  return header.flags & PADDED;
252  }
const char * proxygen::http2::getFrameTypeString ( FrameType  type)

Get the string representation of the given FrameType

Parameters
typeframe type
Returns
string representation of the frame type

Definition at line 963 of file HTTP2Framer.cpp.

References folly::FATAL, proxygen::spdy::GOAWAY, proxygen::spdy::HEADERS, proxygen::spdy::PING, PRIORITY, proxygen::spdy::RST_STREAM, proxygen::spdy::SETTINGS, and proxygen::spdy::WINDOW_UPDATE.

Referenced by proxygen::HTTP2Codec::onIngress(), and proxygen::HTTP2Codec::parseFrame().

963  {
964  switch (type) {
965  case FrameType::DATA: return "DATA";
966  case FrameType::HEADERS: return "HEADERS";
967  case FrameType::PRIORITY: return "PRIORITY";
968  case FrameType::RST_STREAM: return "RST_STREAM";
969  case FrameType::SETTINGS: return "SETTINGS";
970  case FrameType::PUSH_PROMISE: return "PUSH_PROMISE";
971  case FrameType::PING: return "PING";
972  case FrameType::GOAWAY: return "GOAWAY";
973  case FrameType::WINDOW_UPDATE: return "WINDOW_UPDATE";
974  case FrameType::CONTINUATION: return "CONTINUATION";
975  case FrameType::ALTSVC: return "ALTSVC";
976  case FrameType::CERTIFICATE_REQUEST: return "CERTIFICATE_REQUEST";
977  case FrameType::CERTIFICATE: return "CERTIFICATE";
978  default:
979  // can happen when type was cast from uint8_t
980  return "Unknown";
981  }
982  LOG(FATAL) << "Unreachable";
983  return "";
984 }
PskType type
bool proxygen::http2::isValidFrameType ( FrameType  type)

Definition at line 226 of file HTTP2Framer.cpp.

References type, uint8_t, and val.

226  {
227  auto val = static_cast<uint8_t>(type);
229  return val <= static_cast<uint8_t>(FrameType::ALTSVC);
230  } else {
231  switch (type) {
232  case FrameType::EX_HEADERS:
233  // Include the frame types added into FrameType enum for secondary
234  // authentication.
235  case FrameType::CERTIFICATE_REQUEST:
236  case FrameType::CERTIFICATE:
237  return true;
238  default:
239  return false;
240  }
241  }
242 }
PskType type
double val
Definition: String.cpp:273
const uint8_t kMinExperimentalFrameType
Definition: HTTP2Framer.cpp:19
const std::string proxygen::http2::kConnectionPreface ( "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"  )
const std::string proxygen::http2::kProtocolCleartextString ( "h2c"  )
const std::string proxygen::http2::kProtocolDraftString ( "h2-14"  )
const std::string proxygen::http2::kProtocolExperimentalString ( "h2-fb"  )
const std::string proxygen::http2::kProtocolSettingsHeader ( "HTTP2-Settings"  )
const std::string proxygen::http2::kProtocolString ( "h2"  )
ErrorCode proxygen::http2::parseAltSvc ( folly::io::Cursor cursor,
const FrameHeader header,
uint32_t outMaxAge,
uint32_t outPort,
std::string outProtocol,
std::string outHost,
std::string outOrigin 
)
noexcept

This function parses the section of the ALTSVC frame after the common frame header. The caller must ensure there is header.length bytes available in the cursor.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outMaxAgeThe max age field.
outPortThe port the alternative service is on.
outProtocolThe alternative service protocol string.
outHostThe alternative service host name.
outOriginThe origin the alternative service is applicable to.
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 533 of file HTTP2Framer.cpp.

References kFrameAltSvcSizeBase, uint16_t, uint32_t, and uint8_t.

Referenced by TEST_F().

539  {
540  DCHECK_LE(header.length, cursor.totalLength());
541  if (header.length < kFrameAltSvcSizeBase) {
542  return ErrorCode::FRAME_SIZE_ERROR;
543  }
544  std::unique_ptr<IOBuf> tmpBuf;
545 
546  outMaxAge = cursor.readBE<uint32_t>();
547  outPort = cursor.readBE<uint16_t>();
548  const auto protoLen = cursor.readBE<uint8_t>();
549  if (header.length < kFrameAltSvcSizeBase + protoLen) {
550  return ErrorCode::FRAME_SIZE_ERROR;
551  }
552  outProtocol = cursor.readFixedString(protoLen);
553  const auto hostLen = cursor.readBE<uint8_t>();
554  if (header.length < kFrameAltSvcSizeBase + protoLen + hostLen) {
555  return ErrorCode::FRAME_SIZE_ERROR;
556  }
557  outHost = cursor.readFixedString(hostLen);
558  const auto originLen = (header.length - kFrameAltSvcSizeBase -
559  protoLen - hostLen);
560  outOrigin = cursor.readFixedString(originLen);
561 
562  return ErrorCode::NO_ERROR;
563 }
const uint32_t kFrameAltSvcSizeBase
std::string readFixedString(size_t len)
Definition: Cursor.h:309
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parseCertificate ( folly::io::Cursor cursor,
const FrameHeader header,
uint16_t outCertId,
std::unique_ptr< folly::IOBuf > &  outAuthenticator 
)
noexcept

This function parses the section of the CERTIFICATE frame after the common frame header. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outCertIdThe Cert-ID identifying the frame.
outAuthenticatorAuthenticator fragment in the frame, if any.
Returns
NO_ERROR for successful parse. The connection error code to return in a CERTIFICATE frame if failure.

Definition at line 586 of file HTTP2Framer.cpp.

References kFrameCertificateSizeBase, and uint16_t.

Referenced by proxygen::HTTP2Codec::parseCertificate(), and TEST_F().

590  {
591  DCHECK_LE(header.length, cursor.totalLength());
592  if (header.length < kFrameCertificateSizeBase) {
593  return ErrorCode::FRAME_SIZE_ERROR;
594  }
595  if (header.stream != 0) {
596  return ErrorCode::PROTOCOL_ERROR;
597  }
598  outCertId = cursor.readBE<uint16_t>();
599  auto length = header.length;
600  length -= kFrameCertificateSizeBase;
601  if (length > 0) {
602  cursor.clone(outAuthenticator, length);
603  }
604  return ErrorCode::NO_ERROR;
605 }
void clone(std::unique_ptr< folly::IOBuf > &buf, size_t len)
Definition: Cursor.h:456
const uint32_t kFrameCertificateSizeBase
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parseCertificateRequest ( folly::io::Cursor cursor,
const FrameHeader header,
uint16_t outRequestId,
std::unique_ptr< folly::IOBuf > &  outAuthRequest 
)
noexcept

This function parses the section of the CERTIFICATE_REQUEST frame after the common frame header. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outRequestIdThe Request-ID identifying this certificate request.
outAuthRequestAuthenticator request in the frame, if any.
Returns
NO_ERROR for successful parse. The connection error code to return in a CERTIFICATE_REQUEST frame if failure.

Definition at line 565 of file HTTP2Framer.cpp.

References kFrameCertificateRequestSizeBase, and uint16_t.

Referenced by proxygen::HTTP2Codec::parseCertificateRequest(), and TEST_F().

569  {
570  DCHECK_LE(header.length, cursor.totalLength());
571  if (header.length < kFrameCertificateRequestSizeBase) {
572  return ErrorCode::FRAME_SIZE_ERROR;
573  }
574  if (header.stream != 0) {
575  return ErrorCode::PROTOCOL_ERROR;
576  }
577  outRequestId = cursor.readBE<uint16_t>();
578  auto length = header.length;
580  if (length > 0) {
581  cursor.clone(outAuthRequest, length);
582  }
583  return ErrorCode::NO_ERROR;
584 }
void clone(std::unique_ptr< folly::IOBuf > &buf, size_t len)
Definition: Cursor.h:456
const uint32_t kFrameCertificateRequestSizeBase
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parseContinuation ( folly::io::Cursor cursor,
const FrameHeader header,
std::unique_ptr< folly::IOBuf > &  outBuf 
)
noexcept

This function parses the section of the CONTINUATION frame after the common frame header. The caller must ensure there is header.length bytes available in the cursor.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outBufThe buffer to fill with header data.
outAmountThe amount to increment the stream's window by.
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 520 of file HTTP2Framer.cpp.

Referenced by proxygen::HTTP2Codec::parseContinuation(), and TEST_F().

522  {
523  DCHECK(header.type == FrameType::CONTINUATION);
524  DCHECK_LE(header.length, cursor.totalLength());
525  if (header.stream == 0) {
526  return ErrorCode::PROTOCOL_ERROR;
527  }
528  cursor.clone(outBuf, header.length);
529  return ErrorCode::NO_ERROR;
530 }
void clone(std::unique_ptr< folly::IOBuf > &buf, size_t len)
Definition: Cursor.h:456
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parseData ( folly::io::Cursor cursor,
const FrameHeader header,
std::unique_ptr< folly::IOBuf > &  outBuf,
uint16_t padding 
)
noexcept

This function parses the section of the DATA frame after the common frame header. It discards any padding and returns the body data in outBuf. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outBufThe buf to fill with body data.
paddingThe number of padding bytes in this data frame
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 270 of file HTTP2Framer.cpp.

References frameHasPadding(), RETURN_IF_ERROR, uint32_t, and uint8_t.

Referenced by HTTP2FramerTest::dataFrameTest(), proxygen::HTTP2Codec::parseAllData(), and TEST_F().

273  {
274  DCHECK_LE(header.length, cursor.totalLength());
275  if (header.stream == 0) {
276  return ErrorCode::PROTOCOL_ERROR;
277  }
278 
279  uint8_t padding;
280  uint32_t lefttoparse;
281  const auto err = parsePadding(cursor, header, padding, lefttoparse);
282  RETURN_IF_ERROR(err);
283  // outPadding is the total number of flow-controlled pad bytes, which
284  // includes the length byte, if present.
285  outPadding = padding + ((frameHasPadding(header)) ? 1 : 0);
286  cursor.clone(outBuf, lefttoparse);
287  return skipPadding(cursor, padding, kStrictPadding);
288  }
void clone(std::unique_ptr< folly::IOBuf > &buf, size_t len)
Definition: Cursor.h:456
bool frameHasPadding(const FrameHeader &header)
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parseDataBegin ( Cursor cursor,
const FrameHeader header,
size_t &  ,
uint16_t outPadding 
)
noexcept

Definition at line 290 of file HTTP2Framer.cpp.

References frameHasPadding(), RETURN_IF_ERROR, uint32_t, and uint8_t.

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

293  {
294  uint8_t padding;
295  uint32_t lefttoparse;
296  const auto err = http2::parsePadding(cursor, header, padding, lefttoparse);
297  RETURN_IF_ERROR(err);
298  // outPadding is the total number of flow-controlled pad bytes, which
299  // includes the length byte, if present.
300  outPadding = padding + ((frameHasPadding(header)) ? 1 : 0);
301  return ErrorCode::NO_ERROR;
302  }
bool frameHasPadding(const FrameHeader &header)
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
ErrorCode proxygen::http2::parseDataEnd ( Cursor cursor,
const size_t  bufLen,
const size_t  pendingDataFramePaddingBytes,
size_t &  toSkip 
)
noexcept

Definition at line 304 of file HTTP2Framer.cpp.

References min.

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

307  {
308  toSkip = std::min(pendingDataFramePaddingBytes, bufLen);
309  return skipPadding(cursor, toSkip, kStrictPadding);
310 }
LogLevel min
Definition: LogLevel.cpp:30
ErrorCode proxygen::http2::parseExHeaders ( Cursor cursor,
const FrameHeader header,
HTTPCodec::ExAttributes outExAttributes,
folly::Optional< PriorityUpdate > &  outPriority,
std::unique_ptr< IOBuf > &  outBuf 
)
noexcept

Definition at line 339 of file HTTP2Framer.cpp.

References kFramePrioritySize, kFrameStreamIDSize, folly::none, PRIORITY, RETURN_IF_ERROR, uint32_t, uint8_t, and UNIDIRECTIONAL.

Referenced by proxygen::HTTP2Codec::parseExHeaders(), and TEST_F().

343  {
344  DCHECK_LE(header.length, cursor.totalLength());
345  if (header.stream == 0) {
346  return ErrorCode::PROTOCOL_ERROR;
347  }
348 
349  uint8_t padding;
350  uint32_t lefttoparse;
351  auto err = parsePadding(cursor, header, padding, lefttoparse);
352  RETURN_IF_ERROR(err);
353 
354  // the regular HEADERS frame starts from here
355  if (header.flags & PRIORITY) {
356  if (lefttoparse < kFramePrioritySize) {
357  return ErrorCode::FRAME_SIZE_ERROR;
358  }
359  outPriority = parsePriorityCommon(cursor);
360  lefttoparse -= kFramePrioritySize;
361  } else {
362  outPriority = folly::none;
363  }
364  outExAttributes.unidirectional = header.flags & UNIDIRECTIONAL;
365 
366  if (lefttoparse < kFrameStreamIDSize) {
367  return ErrorCode::FRAME_SIZE_ERROR;
368  }
369  outExAttributes.controlStream = parseUint31(cursor);
370  lefttoparse -= kFrameStreamIDSize;
371  if (!(outExAttributes.controlStream & 0x1)) {
372  // control stream ID should be odd because it is initiated by client
373  return ErrorCode::PROTOCOL_ERROR;
374  }
375 
376  cursor.clone(outBuf, lefttoparse);
377  return skipPadding(cursor, padding, kStrictPadding);
378 }
const uint32_t kFramePrioritySize
void clone(std::unique_ptr< folly::IOBuf > &buf, size_t len)
Definition: Cursor.h:456
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
const uint32_t kFrameStreamIDSize
size_t totalLength() const
Definition: Cursor.h:126
constexpr None none
Definition: Optional.h:87
ErrorCode proxygen::http2::parseFrameHeader ( folly::io::Cursor cursor,
FrameHeader header 
)
noexcept

This function parses the common HTTP/2 frame header. This function pulls kFrameHeaderSize bytes from the cursor, so the caller must check that that amount is available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header struct to populate.
Returns
Nothing if success. The connection error code if failure.

Definition at line 256 of file HTTP2Framer.cpp.

References FOLLY_SCOPED_TRACE_SECTION, kFrameHeaderSize, type, uint32_t, and uint8_t.

Referenced by proxygen::HTTP2Codec::onIngress(), HTTP2FramerTest::parse(), and TEST_F().

256  {
257  FOLLY_SCOPED_TRACE_SECTION("HTTP2Framer - parseFrameHeader");
258  DCHECK_LE(kFrameHeaderSize, cursor.totalLength());
259 
260  // MUST ignore the 2 bits before the length
261  uint32_t lengthAndType = cursor.readBE<uint32_t>();
262  header.length = kLengthMask & (lengthAndType >> 8);
263  uint8_t type = lengthAndType & 0xff;
264  header.type = FrameType(type);
265  header.flags = cursor.readBE<uint8_t>();
266  header.stream = parseUint31(cursor);
267  return ErrorCode::NO_ERROR;
268  }
#define FOLLY_SCOPED_TRACE_SECTION(arg,...)
const uint32_t kFrameHeaderSize
PskType type
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parseGoaway ( folly::io::Cursor cursor,
const FrameHeader header,
uint32_t outLastStreamID,
ErrorCode outCode,
std::unique_ptr< folly::IOBuf > &  outDebugData 
)
noexcept

This function parses the section of the GOAWAY frame after the common frame header. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outLastStreamIDThe last stream id accepted by the remote.
outCodeThe error code received in the frame.
outDebugDataAdditional debug-data in the frame, if any
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 484 of file HTTP2Framer.cpp.

References kFrameGoawaySize, and RETURN_IF_ERROR.

Referenced by proxygen::HTTP2Codec::parseGoaway(), and TEST_F().

488  {
489  DCHECK_LE(header.length, cursor.totalLength());
490  if (header.length < kFrameGoawaySize) {
491  return ErrorCode::FRAME_SIZE_ERROR;
492  }
493  if (header.stream != 0) {
494  return ErrorCode::PROTOCOL_ERROR;
495  }
496  outLastStreamID = parseUint31(cursor);
497  auto err = parseErrorCode(cursor, outCode);
498  RETURN_IF_ERROR(err);
499  auto length = header.length;
500  length -= kFrameGoawaySize;
501  if (length > 0) {
502  cursor.clone(outDebugData, length);
503  }
504  return ErrorCode::NO_ERROR;
505 }
void clone(std::unique_ptr< folly::IOBuf > &buf, size_t len)
Definition: Cursor.h:456
const uint32_t kFrameGoawaySize
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parseHeaders ( folly::io::Cursor cursor,
const FrameHeader header,
folly::Optional< PriorityUpdate > &  outPriority,
std::unique_ptr< folly::IOBuf > &  outBuf 
)
noexcept

This function parses the section of the HEADERS frame after the common frame header. It discards any padding and returns the header data in outBuf. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outPriorityIf PRIORITY flag is set, this will be filled with the priority information from this frame.
outBufThe buf to fill with header data.
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 313 of file HTTP2Framer.cpp.

References kFramePrioritySize, folly::none, PRIORITY, RETURN_IF_ERROR, uint32_t, and uint8_t.

Referenced by proxygen::HTTP2Codec::parseHeaders(), and TEST_F().

316  {
317  DCHECK_LE(header.length, cursor.totalLength());
318  if (header.stream == 0) {
319  return ErrorCode::PROTOCOL_ERROR;
320  }
321  uint8_t padding;
322  uint32_t lefttoparse;
323  auto err = parsePadding(cursor, header, padding, lefttoparse);
324  RETURN_IF_ERROR(err);
325  if (header.flags & PRIORITY) {
326  if (lefttoparse < kFramePrioritySize) {
327  return ErrorCode::FRAME_SIZE_ERROR;
328  }
329  outPriority = parsePriorityCommon(cursor);
330  lefttoparse -= kFramePrioritySize;
331  } else {
332  outPriority = folly::none;
333  }
334  cursor.clone(outBuf, lefttoparse);
335  return skipPadding(cursor, padding, kStrictPadding);
336 }
const uint32_t kFramePrioritySize
void clone(std::unique_ptr< folly::IOBuf > &buf, size_t len)
Definition: Cursor.h:456
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
size_t totalLength() const
Definition: Cursor.h:126
constexpr None none
Definition: Optional.h:87
ErrorCode proxygen::http2::parsePing ( folly::io::Cursor cursor,
const FrameHeader header,
uint64_t outData 
)
noexcept

This function parses the section of the PING frame after the common frame header. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outDataThe opaque data from the ping frame
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 467 of file HTTP2Framer.cpp.

References kFramePingSize.

Referenced by proxygen::HTTP2Codec::parsePing(), and TEST_F().

469  {
470  DCHECK_LE(header.length, cursor.totalLength());
471 
472  if (header.length != kFramePingSize) {
473  return ErrorCode::FRAME_SIZE_ERROR;
474  }
475  if (header.stream != 0) {
476  return ErrorCode::PROTOCOL_ERROR;
477  }
478 
479  cursor.pull(&outOpaqueData, sizeof(outOpaqueData));
480  return ErrorCode::NO_ERROR;
481 }
void pull(void *buf, size_t len)
Definition: Cursor.h:418
const uint32_t kFramePingSize
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parsePriority ( folly::io::Cursor cursor,
const FrameHeader header,
PriorityUpdate outPriority 
)
noexcept

This function parses the section of the PRIORITY frame after the common frame header. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outPriorityOn success, filled with the priority information from this frame.
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 381 of file HTTP2Framer.cpp.

References kFramePrioritySize.

Referenced by proxygen::HTTP2Codec::parsePriority(), and TEST_F().

383  {
384  DCHECK_LE(header.length, cursor.totalLength());
385  if (header.length != kFramePrioritySize) {
386  return ErrorCode::FRAME_SIZE_ERROR;
387  }
388  if (header.stream == 0) {
389  return ErrorCode::PROTOCOL_ERROR;
390  }
391  outPriority = parsePriorityCommon(cursor);
392  return ErrorCode::NO_ERROR;
393 }
const uint32_t kFramePrioritySize
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parsePushPromise ( folly::io::Cursor cursor,
const FrameHeader header,
uint32_t outPromisedStream,
std::unique_ptr< folly::IOBuf > &  outBuf 
)
noexcept

This function parses the section of the PUSH_PROMISE frame after the common frame header. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outPromisedStreamThe id of the stream promised by the remote.
outBufThe buffer to fill with header data.
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 436 of file HTTP2Framer.cpp.

References kFramePushPromiseSize, RETURN_IF_ERROR, uint32_t, and uint8_t.

Referenced by proxygen::HTTP2Codec::parsePushPromise(), and TEST_F().

439  {
440  DCHECK_LE(header.length, cursor.totalLength());
441  if (header.stream == 0) {
442  return ErrorCode::PROTOCOL_ERROR;
443  }
444 
445  uint8_t padding;
446  uint32_t lefttoparse;
447  auto err = parsePadding(cursor, header, padding, lefttoparse);
448  RETURN_IF_ERROR(err);
449  if (lefttoparse < kFramePushPromiseSize) {
450  return ErrorCode::FRAME_SIZE_ERROR;
451  }
452  lefttoparse -= kFramePushPromiseSize;
453  outPromisedStream = parseUint31(cursor);
454  if (outPromisedStream == 0 ||
455  outPromisedStream & 0x1) {
456  // client MUST reserve an even stream id greater than 0
457  return ErrorCode::PROTOCOL_ERROR;
458  }
459  if (lefttoparse < padding) {
460  return ErrorCode::PROTOCOL_ERROR;
461  }
462  cursor.clone(outBuf, lefttoparse);
463  return skipPadding(cursor, padding, kStrictPadding);
464 }
void clone(std::unique_ptr< folly::IOBuf > &buf, size_t len)
Definition: Cursor.h:456
const uint32_t kFramePushPromiseSize
#define RETURN_IF_ERROR(err)
Definition: ErrorCode.h:14
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parseRstStream ( folly::io::Cursor cursor,
const FrameHeader header,
ErrorCode outCode 
)
noexcept

This function parses the section of the RST_STREAM frame after the common frame header. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outCodeThe error code received in the frame.
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 396 of file HTTP2Framer.cpp.

References kFrameRstStreamSize.

Referenced by proxygen::HTTP2Codec::parseRstStream(), and TEST_F().

398  {
399  DCHECK_LE(header.length, cursor.totalLength());
400  if (header.length != kFrameRstStreamSize) {
401  return ErrorCode::FRAME_SIZE_ERROR;
402  }
403  if (header.stream == 0) {
404  return ErrorCode::PROTOCOL_ERROR;
405  }
406  return parseErrorCode(cursor, outCode);
407 }
size_t totalLength() const
Definition: Cursor.h:126
const uint32_t kFrameRstStreamSize
ErrorCode proxygen::http2::parseSettings ( folly::io::Cursor cursor,
const FrameHeader header,
std::deque< SettingPair > &  settings 
)
noexcept

This function parses the section of the SETTINGS frame after the common frame header. It pulls header.length bytes from the cursor, so it is the caller's responsibility to ensure there is enough data available.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
settingsThe settings received in this frame.
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 410 of file HTTP2Framer.cpp.

References ACK, settings, uint16_t, uint32_t, and val.

Referenced by proxygen::HTTP2Codec::onIngressUpgradeMessage(), proxygen::HTTP2Codec::parseSettings(), and TEST_F().

412  {
413  DCHECK_LE(header.length, cursor.totalLength());
414  if (header.stream != 0) {
415  return ErrorCode::PROTOCOL_ERROR;
416  }
417  if (header.flags & ACK) {
418  if (header.length != 0) {
419  return ErrorCode::FRAME_SIZE_ERROR;
420  }
421  return ErrorCode::NO_ERROR;
422  }
423 
424  if (header.length % 6 != 0) {
425  return ErrorCode::FRAME_SIZE_ERROR;
426  }
427  for (auto length = header.length; length > 0; length -= 6) {
428  uint16_t id = cursor.readBE<uint16_t>();
429  uint32_t val = cursor.readBE<uint32_t>();
430  settings.push_back(std::make_pair(SettingsId(id), val));
431  }
432  return ErrorCode::NO_ERROR;
433 }
double val
Definition: String.cpp:273
size_t totalLength() const
Definition: Cursor.h:126
ErrorCode proxygen::http2::parseWindowUpdate ( folly::io::Cursor cursor,
const FrameHeader header,
uint32_t outAmount 
)
noexcept

This function parses the section of the WINDOW_UPDATE frame after the common frame header. The caller must ensure there is header.length bytes available in the cursor.

Parameters
cursorThe cursor to pull data from.
headerThe frame header for the frame being parsed.
outAmountThe amount to increment the stream's window by.
Returns
NO_ERROR for successful parse. The connection error code to return in a GOAWAY frame if failure.

Definition at line 508 of file HTTP2Framer.cpp.

References kFrameWindowUpdateSize.

Referenced by proxygen::HTTP2Codec::parseWindowUpdate(), and TEST_F().

510  {
511  DCHECK_LE(header.length, cursor.totalLength());
512  if (header.length != kFrameWindowUpdateSize) {
513  return ErrorCode::FRAME_SIZE_ERROR;
514  }
515  outAmount = parseUint31(cursor);
516  return ErrorCode::NO_ERROR;
517 }
const uint32_t kFrameWindowUpdateSize
size_t totalLength() const
Definition: Cursor.h:126
size_t proxygen::http2::writeAltSvc ( folly::IOBufQueue writeBuf,
uint32_t  stream,
uint32_t  maxAge,
uint16_t  port,
folly::StringPiece  protocol,
folly::StringPiece  host,
folly::StringPiece  origin 
)
noexcept

Generate an entire ALTSVC frame, including the common frame header.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
streamThe stream to do Alt-Svc on. May be zero.
maxAgeThe max age field.
portThe port the alternative service is on.
protocolThe alternative service protocol string.
hostThe alternative service host name.
originThe origin the alternative service is applicable to.
Returns
The number of bytes written to writeBuf.

Definition at line 890 of file HTTP2Framer.cpp.

References kFrameAltSvcSizeBase, kFrameHeaderSize, folly::none, folly::io::detail::Writable< Derived >::push(), uint16_t, uint32_t, uint8_t, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by TEST_F().

896  {
897  const auto protoLen = protocol.size();
898  const auto hostLen = host.size();
899  const auto originLen = origin.size();
900  const auto frameLen = protoLen + hostLen + originLen + kFrameAltSvcSizeBase;
901 
902  writeFrameHeader(queue, frameLen, FrameType::ALTSVC, 0, stream, kNoPadding,
903  folly::none, nullptr);
904  QueueAppender appender(&queue, frameLen);
905  appender.writeBE<uint32_t>(maxAge);
906  appender.writeBE<uint16_t>(port);
907  appender.writeBE<uint8_t>(protoLen);
908  appender.push(reinterpret_cast<const uint8_t*>(protocol.data()), protoLen);
909  appender.writeBE<uint8_t>(hostLen);
910  appender.push(reinterpret_cast<const uint8_t*>(host.data()), hostLen);
911  appender.push(reinterpret_cast<const uint8_t*>(origin.data()), originLen);
912  return kFrameHeaderSize + frameLen;
913 }
const uint32_t kFrameHeaderSize
const uint32_t kFrameAltSvcSizeBase
constexpr size_type size() const
Definition: Range.h:431
constexpr Iter data() const
Definition: Range.h:446
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeCertificate ( folly::IOBufQueue writeBuf,
uint16_t  certId,
std::unique_ptr< folly::IOBuf authenticator,
bool  toBeContinued 
)

Generate an entire CERTIFICATE frame, including the common frame header.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
certIdThe opaque Cert-ID of this frame which is used to correlate subsequent certificate-related frames with this certificate.
authenticatorThe encoded authenticator fragment.
toBeContinuedIndicates whether there is additional authenticator fragment.
Returns
The number of bytes written to writeBuf.

Definition at line 936 of file HTTP2Framer.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::computeChainDataLength(), kFrameCertificateSizeBase, kFrameHeaderSize, folly::gen::move, folly::none, TO_BE_CONTINUED, uint16_t, uint8_t, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by proxygen::HTTP2Codec::generateCertificate(), and TEST_F().

939  {
940  uint8_t flags = 0;
941  if (toBeContinued) {
942  flags |= TO_BE_CONTINUED;
943  }
944  const auto dataLen =
945  authenticator
948  // The CERTIFICATE_REQUEST frame must be sent on stream 0.
949  const auto frameLen = writeFrameHeader(writeBuf,
950  dataLen,
951  FrameType::CERTIFICATE,
952  flags,
953  0,
954  kNoPadding,
955  folly::none,
956  nullptr);
957  QueueAppender appender(&writeBuf, frameLen);
958  appender.writeBE<uint16_t>(certId);
959  writeBuf.append(std::move(authenticator));
960  return kFrameHeaderSize + frameLen;
961 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
flags
Definition: http_parser.h:127
const uint32_t kFrameHeaderSize
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const uint32_t kFrameCertificateSizeBase
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeCertificateRequest ( folly::IOBufQueue writeBuf,
uint16_t  requestId,
std::unique_ptr< folly::IOBuf authRequest 
)

Generate an entire CERTIFICATE_REQUEST frame, including the common frame header.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
requestIdThe opaque Request-ID of this used to correlate subsequent certificate-related frames with this request.
authRequestThe encoded authenticator request.
Returns
The number of bytes written to writeBuf.

Definition at line 915 of file HTTP2Framer.cpp.

References folly::IOBufQueue::append(), folly::IOBuf::computeChainDataLength(), kFrameCertificateRequestSizeBase, kFrameHeaderSize, folly::gen::move, folly::none, uint16_t, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by proxygen::HTTP2Codec::generateCertificateRequest(), and TEST_F().

917  {
918  const auto dataLen = authRequest ? kFrameCertificateRequestSizeBase +
919  authRequest->computeChainDataLength()
921  // The CERTIFICATE_REQUEST frame must be sent on stream 0.
922  const auto frameLen = writeFrameHeader(writeBuf,
923  dataLen,
924  FrameType::CERTIFICATE_REQUEST,
925  0,
926  0,
927  kNoPadding,
928  folly::none,
929  nullptr);
930  QueueAppender appender(&writeBuf, frameLen);
931  appender.writeBE<uint16_t>(requestId);
932  writeBuf.append(std::move(authRequest));
933  return kFrameHeaderSize + frameLen;
934 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
const uint32_t kFrameHeaderSize
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const uint32_t kFrameCertificateRequestSizeBase
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeContinuation ( folly::IOBufQueue queue,
uint32_t  stream,
bool  endHeaders,
std::unique_ptr< folly::IOBuf headers 
)
noexcept

Generate an entire CONTINUATION frame, including the common frame header. The combined length of the data buffer and the padding MUST NOT exceed 2^14 - 3, which is kMaxFramePayloadLength minus the two bytes to encode the length of the padding.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
streamThe stream identifier of the DATA frame.
endHeadersTrue iff more CONTINUATION frames will follow.
headersThe encoded headers data to write out.
Returns
The number of bytes written to writeBuf.

Definition at line 872 of file HTTP2Framer.cpp.

References END_HEADERS, kFrameHeaderSize, folly::gen::move, and folly::none.

Referenced by proxygen::HTTP2Codec::generateContinuation(), and TEST_F().

875  {
876  DCHECK_NE(0, stream);
877  const auto dataLen = headers->computeChainDataLength();
878  const auto frameLen = writeFrameHeader(queue,
879  dataLen,
880  FrameType::CONTINUATION,
881  endHeaders ? END_HEADERS : 0,
882  stream,
883  kNoPadding,
884  folly::none,
885  std::move(headers));
886  return kFrameHeaderSize + frameLen;
887 }
const uint32_t kFrameHeaderSize
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeData ( folly::IOBufQueue writeBuf,
std::unique_ptr< folly::IOBuf data,
uint32_t  stream,
folly::Optional< uint8_t padding,
bool  endStream,
bool  reuseIOBufHeadroom 
)
noexcept

Generate an entire DATA frame, including the common frame header. The combined length of the data buffer, the padding, and the padding length MUST NOT exceed 2^14 - 1, which is kMaxFramePayloadLength.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
dataThe body data to write out, can be nullptr for 0 length
streamThe stream identifier of the DATA frame.
paddingIf not kNoPadding, adds 1 byte pad len and pad bytes
endStreamTrue iff this frame ends the stream.
reuseIOBufHeadroomIf HTTP2Framer should reuse headroom in data if headroom is enough for frame header
Returns
The number of bytes written to writeBuf.

Definition at line 610 of file HTTP2Framer.cpp.

References folly::data(), END_STREAM, kFrameHeaderSize, folly::gen::move, folly::none, uint64_t, and uint8_t.

Referenced by HTTP2FramerTest::dataFrameTest(), proxygen::HTTP2Codec::generateBody(), proxygen::HTTP2Codec::generateEOM(), and TEST_F().

615  {
616  DCHECK_NE(0, stream);
617  uint8_t flags = 0;
618  if (endStream) {
619  flags |= END_STREAM;
620  }
621  const uint64_t dataLen = data ? data->computeChainDataLength() : 0;
622  // Caller must not exceed peer setting for MAX_FRAME_SIZE
623  // TODO: look into using headroom from data to hold the frame header
624  const auto frameLen = writeFrameHeader(queue,
625  dataLen,
626  FrameType::DATA,
627  flags,
628  stream,
629  padding,
630  folly::none,
631  std::move(data),
632  reuseIOBufHeadroom);
633  writePadding(queue, padding);
634  return kFrameHeaderSize + frameLen;
635 }
flags
Definition: http_parser.h:127
const uint32_t kFrameHeaderSize
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeExHeaders ( folly::IOBufQueue writeBuf,
std::unique_ptr< folly::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

Generate an experimental ExHEADERS frame, including the common frame header. The combined length of the data buffer and the padding and priority fields MUST NOT exceed 2^14 - 1, which is kMaxFramePayloadLength.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
headersThe encoded headers data to write out.
streamThe stream identifier of the ExHEADERS frame.
exAttributesAttributes specific to ExHEADERS frame.
priorityIf present, the priority depedency information to update the stream with.
paddingIf not kNoPadding, adds 1 byte pad len and pad bytes
endStreamTrue iff this frame ends the stream.
endHeadersTrue iff no CONTINUATION frames will follow this frame.
Returns
The number of bytes written to writeBuf.

Definition at line 671 of file HTTP2Framer.cpp.

References END_HEADERS, END_STREAM, kFrameHeaderSize, kFrameStreamIDSize, folly::gen::move, PRIORITY, uint32_t, UNIDIRECTIONAL, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by proxygen::HTTP2Codec::generateHeaderImpl(), and TEST_F().

678  {
679  DCHECK_NE(0, stream);
680  DCHECK_NE(0, exAttributes.controlStream);
681  DCHECK_EQ(0, ~kUint31Mask & stream);
682  DCHECK_EQ(0, ~kUint31Mask & exAttributes.controlStream);
683  DCHECK(0x1 & exAttributes.controlStream) <<
684  "controlStream should be initiated by client";
685 
686  const auto dataLen = (headers) ? headers->computeChainDataLength() : 0;
687  uint32_t flags = 0;
688  if (priority) {
689  flags |= PRIORITY;
690  }
691  if (endStream) {
692  flags |= END_STREAM;
693  }
694  if (endHeaders) {
695  flags |= END_HEADERS;
696  }
697  if (exAttributes.unidirectional) {
698  flags |= UNIDIRECTIONAL;
699  }
700 
701  const auto frameLen = writeFrameHeader(queue,
702  dataLen + kFrameStreamIDSize,
703  FrameType::EX_HEADERS,
704  flags,
705  stream,
706  padding,
707  priority,
708  nullptr);
709  QueueAppender appender(&queue, frameLen);
710  appender.writeBE<uint32_t>(exAttributes.controlStream);
711  queue.append(std::move(headers));
712  writePadding(queue, padding);
713  return kFrameHeaderSize + frameLen;
714 }
flags
Definition: http_parser.h:127
const uint32_t kFrameHeaderSize
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
const uint32_t kFrameStreamIDSize
size_t proxygen::http2::writeGoaway ( folly::IOBufQueue writeBuf,
uint32_t  lastStreamID,
ErrorCode  errorCode,
std::unique_ptr< folly::IOBuf debugData = nullptr 
)
noexcept

Generate an entire GOAWAY frame, including the common frame header. We do not implement the optional opaque data.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
lastStreamIDThe identifier of the last stream accepted.
errorCodeThe error code returned in the frame.
debugDataOptional debug information to add to the frame
Returns
The number of bytes written to writeBuf.

Definition at line 831 of file HTTP2Framer.cpp.

References proxygen::spdy::GOAWAY, kFrameGoawaySize, kFrameHeaderSize, folly::gen::move, folly::none, uint32_t, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by proxygen::HTTP2Codec::generateGoaway(), and TEST_F().

834  {
835  uint32_t debugLen = debugData ? debugData->computeChainDataLength() : 0;
836  DCHECK_EQ(0, ~kLengthMask & debugLen);
837  const auto frameLen = writeFrameHeader(queue,
838  kFrameGoawaySize + debugLen,
840  0,
841  0,
842  kNoPadding,
843  folly::none,
844  nullptr);
845  QueueAppender appender(&queue, frameLen);
846  appender.writeBE<uint32_t>(lastStreamID);
847  appender.writeBE<uint32_t>(static_cast<uint32_t>(errorCode));
848  queue.append(std::move(debugData));
849  return kFrameHeaderSize + frameLen;
850 }
const uint32_t kFrameHeaderSize
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const uint32_t kFrameGoawaySize
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeHeaders ( folly::IOBufQueue writeBuf,
std::unique_ptr< folly::IOBuf headers,
uint32_t  stream,
folly::Optional< PriorityUpdate priority,
folly::Optional< uint8_t padding,
bool  endStream,
bool  endHeaders 
)
noexcept

Generate an entire HEADERS frame, including the common frame header. The combined length of the data buffer and the padding and priority fields MUST NOT exceed 2^14 - 1, which is kMaxFramePayloadLength.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
headersThe encoded headers data to write out.
streamThe stream identifier of the HEADERS frame.
priorityIf present, the priority depedency information to update the stream with.
paddingIf not kNoPadding, adds 1 byte pad len and pad bytes
endStreamTrue iff this frame ends the stream.
endHeadersTrue iff no CONTINUATION frames will follow this frame.
Returns
The number of bytes written to writeBuf.

Definition at line 638 of file HTTP2Framer.cpp.

References END_HEADERS, END_STREAM, proxygen::spdy::HEADERS, kFrameHeaderSize, folly::gen::move, PRIORITY, and uint32_t.

Referenced by proxygen::HTTP2Codec::generateHeaderImpl(), proxygen::HTTP2Codec::generateTrailers(), and TEST_F().

644  {
645  DCHECK_NE(0, stream);
646  const auto dataLen = (headers) ? headers->computeChainDataLength() : 0;
647  uint32_t flags = 0;
648  if (priority) {
649  flags |= PRIORITY;
650  }
651  if (endStream) {
652  flags |= END_STREAM;
653  }
654  if (endHeaders) {
655  flags |= END_HEADERS;
656  }
657  // padding flags handled directly inside writeFrameHeader()
658  const auto frameLen = writeFrameHeader(queue,
659  dataLen,
661  flags,
662  stream,
663  padding,
664  priority,
665  std::move(headers));
666  writePadding(queue, padding);
667  return kFrameHeaderSize + frameLen;
668 }
flags
Definition: http_parser.h:127
const uint32_t kFrameHeaderSize
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
size_t proxygen::http2::writePing ( folly::IOBufQueue writeBuf,
uint64_t  data,
bool  ack 
)
noexcept

Generate an entire PING frame, including the common frame header.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
dataThe opaque data to include.
ackTrue iff this is a ping response.
Returns
The number of bytes written to writeBuf.

Definition at line 815 of file HTTP2Framer.cpp.

References ACK, kFrameHeaderSize, kFramePingSize, folly::none, and proxygen::spdy::PING.

Referenced by proxygen::HTTP2Codec::generatePingReply(), proxygen::HTTP2Codec::generatePingRequest(), UDPClient::sendPing(), and TEST_F().

817  {
818  const auto frameLen = writeFrameHeader(queue,
821  ack ? ACK : 0,
822  0,
823  kNoPadding,
824  folly::none,
825  nullptr);
826  queue.append(&opaqueData, sizeof(opaqueData));
827  return kFrameHeaderSize + frameLen;
828 }
const uint32_t kFrameHeaderSize
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
const uint32_t kFramePingSize
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writePriority ( folly::IOBufQueue writeBuf,
uint32_t  stream,
PriorityUpdate  priority 
)
noexcept

Generate an entire PRIORITY frame, including the common frame header.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
streamThe stream identifier of the DATA frame.
priorityThe priority depedency information to update the stream with.
Returns
The number of bytes written to writeBuf.

Definition at line 717 of file HTTP2Framer.cpp.

References kFrameHeaderSize, kFramePrioritySize, and PRIORITY.

Referenced by proxygen::HTTP2Codec::generatePriority(), and TEST_F().

719  {
720  DCHECK_NE(0, stream);
721  const auto frameLen = writeFrameHeader(queue,
724  0,
725  stream,
726  kNoPadding,
727  priority,
728  nullptr);
729  return kFrameHeaderSize + frameLen;
730 }
const uint32_t kFramePrioritySize
const uint32_t kFrameHeaderSize
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
size_t proxygen::http2::writePushPromise ( folly::IOBufQueue writeBuf,
uint32_t  associatedStream,
uint32_t  promisedStream,
std::unique_ptr< folly::IOBuf headers,
folly::Optional< uint8_t padding,
bool  endHeaders 
)
noexcept

Writes an entire PUSH_PROMISE frame, including the common frame header.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
associatedStreamThe identifier of the stream the promised stream is associated with.
promisedStreamThe identifier of the promised stream.
headersThe encoded headers to include in the push promise frame.
paddingIf not kNoPadding, adds 1 byte pad len and pad bytes
endHeadersTrue iff no CONTINUATION frames will follow this frame.
Returns
The number of bytes written to writeBuf/

Definition at line 786 of file HTTP2Framer.cpp.

References END_HEADERS, kFrameHeaderSize, kFramePushPromiseSize, folly::gen::move, folly::none, uint32_t, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by proxygen::HTTP2Codec::generateHeaderImpl(), and TEST_F().

791  {
792  DCHECK_NE(0, promisedStream);
793  DCHECK_NE(0, associatedStream);
794  DCHECK_EQ(0, 0x1 & promisedStream);
795  DCHECK_EQ(1, 0x1 & associatedStream);
796  DCHECK_EQ(0, ~kUint31Mask & promisedStream);
797 
798  const auto dataLen = headers->computeChainDataLength();
799  const auto frameLen = writeFrameHeader(queue,
800  dataLen + kFramePushPromiseSize,
801  FrameType::PUSH_PROMISE,
802  endHeaders ? END_HEADERS : 0,
803  associatedStream,
804  padding,
805  folly::none,
806  nullptr);
807  QueueAppender appender(&queue, frameLen);
808  appender.writeBE<uint32_t>(promisedStream);
809  queue.append(std::move(headers));
810  writePadding(queue, padding);
811  return kFrameHeaderSize + frameLen;
812 }
const uint32_t kFrameHeaderSize
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
const uint32_t kFramePushPromiseSize
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeRstStream ( folly::IOBufQueue writeBuf,
uint32_t  stream,
ErrorCode  errorCode 
)
noexcept

Generate an entire RST_STREAM frame, including the common frame header.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
streamThe identifier of the stream to reset.
errorCodeThe error code returned in the frame.
Returns
The number of bytes written to writeBuf.

Definition at line 733 of file HTTP2Framer.cpp.

References kFrameHeaderSize, kFrameRstStreamSize, folly::none, proxygen::spdy::RST_STREAM, uint32_t, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by proxygen::HTTP2Codec::generateRstStream(), and TEST_F().

735  {
736  DCHECK_NE(0, stream);
737  const auto frameLen = writeFrameHeader(queue,
740  0,
741  stream,
742  kNoPadding,
743  folly::none,
744  nullptr);
745  QueueAppender appender(&queue, frameLen);
746  appender.writeBE<uint32_t>(static_cast<uint32_t>(errorCode));
747  return kFrameHeaderSize + frameLen;
748 }
const uint32_t kFrameHeaderSize
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
const uint32_t kFrameRstStreamSize
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeSettings ( folly::IOBufQueue writeBuf,
const std::deque< SettingPair > &  settings 
)

Generate an entire SETTINGS frame, including the common frame header.

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
settingsThe settings to send
Returns
The number of bytes written to writeBuf.

Definition at line 751 of file HTTP2Framer.cpp.

References kFrameHeaderSize, max, folly::none, proxygen::spdy::SETTINGS, uint16_t, uint32_t, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by proxygen::HTTP2Codec::generateSettings(), and TEST_F().

752  {
753  const auto settingsSize = settings.size() * 6;
754  const auto frameLen = writeFrameHeader(queue,
755  settingsSize,
757  0,
758  0,
759  kNoPadding,
760  folly::none,
761  nullptr);
762  QueueAppender appender(&queue, settingsSize);
763  for (const auto& setting: settings) {
764  DCHECK_LE(static_cast<uint32_t>(setting.first),
766  appender.writeBE<uint16_t>(static_cast<uint16_t>(setting.first));
767  appender.writeBE<uint32_t>(setting.second);
768  }
769  return kFrameHeaderSize + frameLen;
770 }
LogLevel max
Definition: LogLevel.cpp:31
const uint32_t kFrameHeaderSize
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeSettingsAck ( folly::IOBufQueue writeBuf)

Writes an entire empty SETTINGS frame, including the common frame header. No settings can be transmitted with this frame.

Definition at line 773 of file HTTP2Framer.cpp.

References ACK, kFrameHeaderSize, folly::none, and proxygen::spdy::SETTINGS.

Referenced by proxygen::HTTP2Codec::generateSettingsAck(), and TEST_F().

773  {
774  writeFrameHeader(queue,
775  0,
777  ACK,
778  0,
779  kNoPadding,
780  folly::none,
781  nullptr);
782  return kFrameHeaderSize;
783 }
const uint32_t kFrameHeaderSize
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
constexpr None none
Definition: Optional.h:87
size_t proxygen::http2::writeWindowUpdate ( folly::IOBufQueue writeBuf,
uint32_t  stream,
uint32_t  amount 
)
noexcept

Generate an entire WINDOW_UPDATE frame, including the common frame header. |amount| MUST be between 1 to 2^31 - 1 inclusive

Parameters
writeBufThe output queue to write to. It may grow or add underlying buffers inside this function.
streamThe stream to send a WINDOW_UPDATE on
amountThe number of bytes to AK
Returns
The number of bytes written to writeBuf.

Definition at line 853 of file HTTP2Framer.cpp.

References kFrameHeaderSize, kFrameWindowUpdateSize, folly::none, uint32_t, proxygen::spdy::WINDOW_UPDATE, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by proxygen::HTTP2Codec::generateWindowUpdate(), and TEST_F().

855  {
856  const auto frameLen = writeFrameHeader(queue,
859  0,
860  stream,
861  kNoPadding,
862  folly::none,
863  nullptr);
864  DCHECK_EQ(0, ~kUint31Mask & amount);
865  DCHECK_LT(0, amount);
866  QueueAppender appender(&queue, kFrameWindowUpdateSize);
867  appender.writeBE<uint32_t>(amount);
868  return kFrameHeaderSize + frameLen;
869 }
const uint32_t kFrameHeaderSize
const uint32_t kFrameWindowUpdateSize
const Padding kNoPadding
Definition: HTTP2Framer.cpp:20
constexpr None none
Definition: Optional.h:87

Variable Documentation

const std::string proxygen::http2::kConnectionPreface
const uint32_t proxygen::http2::kFrameAltSvcSizeBase = 8

Definition at line 43 of file HTTP2Constants.cpp.

Referenced by parseAltSvc(), and writeAltSvc().

const uint32_t proxygen::http2::kFrameCertificateRequestSizeBase = 2

Definition at line 40 of file HTTP2Constants.cpp.

Referenced by parseCertificateRequest(), TEST_F(), and writeCertificateRequest().

const uint32_t proxygen::http2::kFrameCertificateSizeBase = 2

Definition at line 41 of file HTTP2Constants.cpp.

Referenced by parseCertificate(), TEST_F(), and writeCertificate().

const uint32_t proxygen::http2::kFrameGoawaySize = 8

Definition at line 38 of file HTTP2Constants.cpp.

Referenced by parseGoaway(), TEST_F(), and writeGoaway().

const uint32_t proxygen::http2::kFrameHeadersBaseMaxSize = kFramePrioritySize + 1

Definition at line 32 of file HTTP2Constants.cpp.

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

const uint32_t proxygen::http2::kFramePingSize = 8

Definition at line 37 of file HTTP2Constants.cpp.

Referenced by parsePing(), and writePing().

const uint32_t proxygen::http2::kFramePrioritySize = 5
const uint32_t proxygen::http2::kFramePushPromiseSize = 4

Definition at line 36 of file HTTP2Constants.cpp.

Referenced by parsePushPromise(), and writePushPromise().

const uint32_t proxygen::http2::kFrameRstStreamSize = 4

Definition at line 35 of file HTTP2Constants.cpp.

Referenced by parseRstStream(), TEST_F(), and writeRstStream().

const uint32_t proxygen::http2::kFrameStreamIDSize = 4

Definition at line 34 of file HTTP2Constants.cpp.

Referenced by parseExHeaders(), and writeExHeaders().

const uint32_t proxygen::http2::kFrameWindowUpdateSize = 4

Definition at line 39 of file HTTP2Constants.cpp.

Referenced by parseWindowUpdate(), TEST_F(), and writeWindowUpdate().

const uint32_t proxygen::http2::kMaxAuthenticatorBufSize = 0x20000

Definition at line 52 of file HTTP2Constants.cpp.

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

const uint32_t proxygen::http2::kMaxFramePayloadLength = (1u << 24) - 1
const uint32_t proxygen::http2::kMaxHeaderTableSize = (1u << 16)

Definition at line 50 of file HTTP2Constants.cpp.

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

const uint32_t proxygen::http2::kMaxStreamID = (1u << 31) - 1

Definition at line 47 of file HTTP2Constants.cpp.

const uint32_t proxygen::http2::kMaxWindowUpdateSize = (1u << 31) - 1

Definition at line 49 of file HTTP2Constants.cpp.

Referenced by proxygen::HTTP2Codec::handleSettings(), and TEST_F().

const uint8_t proxygen::http2::kMinExperimentalFrameType = 0xf0

Definition at line 19 of file HTTP2Framer.cpp.

const std::string proxygen::http2::kProtocolExperimentalString
const std::string proxygen::http2::kProtocolSettingsHeader