22 using namespace folly;
40 template<
typename ParseFunc,
typename...
Args>
42 parse(queue_.front(), parseFn, outHeader, std::forward<Args>(outArgs)...);
45 template<
typename ParseFunc,
typename...
Args>
51 auto ret2 = (*parseFn)(cursor, outHeader, std::forward<Args>(outArgs)...);
57 dataFrameTest(body.get(), dataLen, padLen);
64 frameLen += 1 + *padLen;
73 std::unique_ptr<IOBuf> outBuf;
78 EXPECT_EQ(padding, padLen ? (*padLen + 1) : 0);
102 dataFrameTest(body.get(), dataLen,
Padding(0));
103 dataFrameTest(0,
Padding(dataLen));
104 for (
uint8_t padding = 1; padding != 0; padding <<= 1) {
105 dataFrameTest(body.get(), dataLen,
Padding(padding));
112 static_cast<uint8_t>(FrameType::DATA),
115 std::unique_ptr<IOBuf> outBuf;
117 Cursor cursor(queue_.front());
120 ErrorCode::PROTOCOL_ERROR);
128 std::deque<SettingPair> outSettings;
129 Cursor cursor(queue_.front());
132 ErrorCode::PROTOCOL_ERROR);
139 queue_.append(
string(
"abcde"));
142 std::unique_ptr<IOBuf> outBuf;
144 Cursor cursor(queue_.front());
147 ErrorCode::PROTOCOL_ERROR);
155 buf->advance(headRoomSize);
159 auto queueHead = queue_.front();
162 auto queueNode = queueHead->prev();
165 EXPECT_EQ(headRoomSize, queueNode->headroom());
174 buf->advance(headRoomSize);
179 auto queueNode = queue_.front();
182 EXPECT_LT(queueNode->headroom(), headRoomSize);
188 static_cast<uint32_t>(-1),
189 ErrorCode::PROTOCOL_ERROR),
".*");
207 writeGoaway(queue_, 0, ErrorCode::FLOW_CONTROL_ERROR);
212 std::unique_ptr<IOBuf> outDebugData;
219 ASSERT_EQ(ErrorCode::FLOW_CONTROL_ERROR, outCode);
225 string data(
"abcde");
227 memcpy(debugData->writableData(), data.data(), data.length());
233 std::unique_ptr<IOBuf> outDebugData;
240 ASSERT_EQ(ErrorCode::FLOW_CONTROL_ERROR, outCode);
263 std::unique_ptr<IOBuf> outDebugData;
265 Cursor cursor(queue_.front());
270 auto ret2 =
parseGoaway(cursor, outHeader, outLastStreamID,
271 outCode, outDebugData);
272 ASSERT_EQ(ErrorCode::PROTOCOL_ERROR, ret2);
292 writeHeaders(queue_, body->clone(), 1, {{0,
true, 12}}, 200,
297 std::unique_ptr<IOBuf> outBuf;
339 string data(
"abcdef");
341 memcpy(authRequest->writableData(), data.data(), data.length());
347 std::unique_ptr<IOBuf> outAuthRequest;
365 std::unique_ptr<IOBuf> outAuthRequest;
379 queue_, 1, static_cast<uint8_t>(FrameType::CERTIFICATE_REQUEST), 0, 0);
383 Cursor cursor(queue_.front());
386 std::unique_ptr<IOBuf> outAuthRequest;
390 ASSERT_EQ(ErrorCode::FRAME_SIZE_ERROR, ret);
396 queue_, 2, static_cast<uint8_t>(FrameType::CERTIFICATE_REQUEST), 0, 1);
400 Cursor cursor(queue_.front());
403 std::unique_ptr<IOBuf> outAuthRequest;
407 ASSERT_EQ(ErrorCode::PROTOCOL_ERROR, ret);
411 string data(
"abcdef");
412 auto authenticator =
makeBuf(6);
413 memcpy(authenticator->writableData(), data.data(), data.length());
420 std::unique_ptr<IOBuf> outAuthenticator;
433 string data(
"abcdef");
434 auto authenticator =
makeBuf(6);
435 memcpy(authenticator->writableData(), data.data(), data.length());
443 std::unique_ptr<IOBuf> outAuthenticator;
461 std::unique_ptr<IOBuf> outAuthenticator;
475 queue_, 1, static_cast<uint8_t>(FrameType::CERTIFICATE), 0, 0);
479 Cursor cursor(queue_.front());
482 std::unique_ptr<IOBuf> outAuthenticator;
485 ASSERT_EQ(ErrorCode::FRAME_SIZE_ERROR, ret);
491 queue_, 2, static_cast<uint8_t>(FrameType::CERTIFICATE), 0, 1);
495 Cursor cursor(queue_.front());
498 std::unique_ptr<IOBuf> outAuthenticator;
501 ASSERT_EQ(ErrorCode::PROTOCOL_ERROR, ret);
511 Cursor cursor(queue_.front());
516 ASSERT_EQ(ErrorCode::FRAME_SIZE_ERROR, ret2);
520 const uint32_t uint31Max = 0x7fffffff;
522 auto buf = queue_.move();
525 for (
unsigned i = 0;
i < 4; ++
i) {
541 string protocol =
"special-proto";
542 string host =
"special-host";
543 string origin =
"special-origin";
544 writeAltSvc(queue_, 2, 150, 8080, protocol, host, origin);
566 const deque<SettingPair>
settings = {{SettingsId::HEADER_TABLE_SIZE, 3},
567 {SettingsId::MAX_CONCURRENT_STREAMS, 4}};
571 std::deque<SettingPair> outSettings;
584 Cursor cursor(queue_.front());
593 std::deque<SettingPair> outSettings;
601 memcpy(((
IOBuf*)queue_.front())->writableData(), &lengthAndType, 4);
604 Cursor cursor(queue_.front());
612 std::deque<SettingPair> outSettings;
614 ErrorCode::FRAME_SIZE_ERROR);
623 std::deque<SettingPair> outSettings;
639 std::unique_ptr<IOBuf> outBuf;
642 ASSERT_EQ(FrameType::PUSH_PROMISE, header.type);
653 std::unique_ptr<IOBuf> outBuf;
656 ASSERT_EQ(FrameType::CONTINUATION, header.type);
666 uint32_t controlStream = streamID - 2;
669 {{0,
true, 12}}, 200,
false,
false);
674 std::unique_ptr<IOBuf> outBuf;
677 ASSERT_EQ(FrameType::EX_HEADERS, header.type);
694 uint32_t controlStream = streamID - 2;
702 std::unique_ptr<IOBuf> outBuf;
705 ASSERT_EQ(FrameType::EX_HEADERS, header.type);
size_t parse(const char *buf, size_t len)
ErrorCode parseAltSvc(Cursor &cursor, const FrameHeader &header, uint32_t &outMaxAge, uint32_t &outPort, std::string &outProtocol, std::string &outHost, std::string &outOrigin) noexcept
ErrorCode parseContinuation(Cursor &cursor, const FrameHeader &header, std::unique_ptr< IOBuf > &outBuf) noexcept
size_t writePing(IOBufQueue &queue, uint64_t opaqueData, bool ack) noexcept
ErrorCode parsePushPromise(Cursor &cursor, const FrameHeader &header, uint32_t &outPromisedStream, std::unique_ptr< IOBuf > &outBuf) noexcept
ErrorCode parseFrameHeader(Cursor &cursor, FrameHeader &header) noexcept
const uint32_t kFramePrioritySize
uint32_t streamDependency
#define ASSERT_EQ(val1, val2)
ErrorCode parseGoaway(Cursor &cursor, const FrameHeader &header, uint32_t &outLastStreamID, ErrorCode &outCode, std::unique_ptr< IOBuf > &outDebugData) noexcept
static std::unique_ptr< IOBuf > create(std::size_t capacity)
void writeFrameHeaderManual(IOBufQueue &queue, uint32_t length, uint8_t type, uint8_t flags, uint32_t stream)
const uint32_t kFrameHeaderSize
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
#define EXPECT_DEATH_NO_CORE(token, regex)
#define EXPECT_EQ(val1, val2)
fbstring moveToFbString()
constexpr detail::Map< Move > move
ErrorCode parsePriority(Cursor &cursor, const FrameHeader &header, PriorityUpdate &outPriority) noexcept
ErrorCode parseSettings(Cursor &cursor, const FrameHeader &header, std::deque< SettingPair > &settings) noexcept
const uint32_t kMaxFramePayloadLength
size_t writePushPromise(IOBufQueue &queue, uint32_t associatedStream, uint32_t promisedStream, std::unique_ptr< IOBuf > headers, folly::Optional< uint8_t > padding, bool endHeaders) noexcept
static http_parser_settings settings
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
—— Concurrent Priority Queue Implementation ——
std::unique_ptr< IOBuf > clone() const
ErrorCode parseWindowUpdate(Cursor &cursor, const FrameHeader &header, uint32_t &outAmount) noexcept
size_t writeContinuation(IOBufQueue &queue, uint32_t stream, bool endHeaders, std::unique_ptr< IOBuf > headers) noexcept
ErrorCode parseCertificateRequest(folly::io::Cursor &cursor, const FrameHeader &header, uint16_t &outRequestId, std::unique_ptr< folly::IOBuf > &outAuthRequest) noexcept
size_t writeSettings(IOBufQueue &queue, const std::deque< SettingPair > &settings)
const uint32_t kFrameCertificateSizeBase
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
folly::Optional< uint8_t > Padding
static Options cacheChainLength()
ErrorCode parseExHeaders(Cursor &cursor, const FrameHeader &header, HTTPCodec::ExAttributes &outExAttributes, folly::Optional< PriorityUpdate > &outPriority, std::unique_ptr< IOBuf > &outBuf) noexcept
const uint32_t kFrameCertificateRequestSizeBase
size_t writePriority(IOBufQueue &queue, uint32_t stream, PriorityUpdate priority) noexcept
void parse(ParseFunc &&parseFn, FrameHeader &outHeader, Args &&...outArgs)
const uint32_t kFrameGoawaySize
size_t writeCertificate(folly::IOBufQueue &writeBuf, uint16_t certId, std::unique_ptr< folly::IOBuf > authenticator, bool toBeContinued)
ErrorCode parseRstStream(Cursor &cursor, const FrameHeader &header, ErrorCode &outCode) noexcept
constexpr auto data(C &c) -> decltype(c.data())
void parse(const IOBuf *data, ParseFunc &&parseFn, FrameHeader &outHeader, Args &&...outArgs)
ErrorCode parseCertificate(folly::io::Cursor &cursor, const FrameHeader &header, uint16_t &outCertId, std::unique_ptr< folly::IOBuf > &outAuthenticator) 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)
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
ErrorCode parseHeaders(Cursor &cursor, const FrameHeader &header, folly::Optional< PriorityUpdate > &outPriority, std::unique_ptr< IOBuf > &outBuf) noexcept
size_t writeSettingsAck(IOBufQueue &queue)
std::size_t computeChainDataLength() const
void dataFrameTest(IOBuf *body, uint32_t dataLen, folly::Optional< uint8_t > padLen)
size_t writeRstStream(IOBufQueue &queue, uint32_t stream, ErrorCode errorCode) noexcept
#define EXPECT_TRUE(condition)
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 writeGoaway(IOBufQueue &queue, uint32_t lastStreamID, ErrorCode errorCode, std::unique_ptr< IOBuf > debugData) noexcept
#define ASSERT_FALSE(condition)
#define EXPECT_FALSE(condition)
void dataFrameTest(uint32_t dataLen, folly::Optional< uint8_t > padLen)
#define EXPECT_LT(val1, val2)
ErrorCode parseData(Cursor &cursor, const FrameHeader &header, std::unique_ptr< IOBuf > &outBuf, uint16_t &outPadding) noexcept
size_t writeData(IOBufQueue &queue, std::unique_ptr< IOBuf > data, uint32_t stream, folly::Optional< uint8_t > padding, bool endStream, bool reuseIOBufHeadroom) noexcept
#define ASSERT_TRUE(condition)
size_t writeWindowUpdate(IOBufQueue &queue, uint32_t stream, uint32_t amount) noexcept
const uint32_t kFrameRstStreamSize
ErrorCode parsePing(Cursor &cursor, const FrameHeader &header, uint64_t &outOpaqueData) noexcept