proxygen
proxygen::hpack Namespace Reference

Classes

class  TestHeaderCodecStats
 

Functions

void dumpToFile (const string &filename, const IOBuf *buf)
 
void verifyHeaders (vector< HPACKHeader > &headers, vector< HPACKHeader > &decodedHeaders)
 
unique_ptr< IOBufencodeDecode (vector< HPACKHeader > &headers, HPACKEncoder &encoder, HPACKDecoder &decoder)
 
void encodeDecode (vector< HPACKHeader > &headers, QPACKEncoder &encoder, QPACKDecoder &decoder)
 
unique_ptr< HPACKDecoder::headers_tdecode (HPACKDecoder &decoder, const IOBuf *buffer)
 
vector< compress::HeaderheadersFromArray (vector< vector< string >> &a)
 
vector< compress::HeaderbasicHeaders ()
 

Function Documentation

std::vector< compress::Header > proxygen::hpack::basicHeaders ( )

Definition at line 116 of file TestUtil.cpp.

References headersFromArray().

Referenced by TEST_F(), and TEST_P().

116  {
117  static vector<vector<string>> headersStrings = {
118  {":path", "/index.php"},
119  {":authority", "www.facebook.com"},
120  {":method", "GET"},
121  {":scheme", "https"},
122  {"Host", "www.facebook.com"},
123  {"accept-encoding", "gzip"}
124  };
125  static vector<compress::Header> headers = headersFromArray(headersStrings);
126  return headers;
127 }
vector< compress::Header > headersFromArray(vector< vector< string >> &a)
Definition: TestUtil.cpp:108
std::unique_ptr< HPACKDecoder::headers_t > proxygen::hpack::decode ( HPACKDecoder decoder,
const IOBuf buffer 
)

Definition at line 95 of file TestUtil.cpp.

References proxygen::HPACKDecoder::decodeStreaming(), proxygen::TestStreamingCallback::hasError(), proxygen::TestStreamingCallback::hpackHeaders(), and uint32_t.

Referenced by checkError(), encodeDecode(), TEST_F(), and TEST_P().

96  {
97  auto headers = std::make_unique<HPACKDecoder::headers_t>();
98  folly::io::Cursor cursor(buffer);
99  uint32_t totalBytes = buffer ? cursor.totalLength() : 0;
100  TestStreamingCallback cb;
101  decoder.decodeStreaming(cursor, totalBytes, &cb);
102  if (cb.hasError()) {
103  return headers;
104  }
105  return cb.hpackHeaders();
106 }
void proxygen::hpack::dumpToFile ( const string filename,
const IOBuf buf 
)

Definition at line 27 of file TestUtil.cpp.

References folly::IOBuf::data(), folly::IOBuf::length(), and folly::IOBuf::next().

27  {
28  ofstream outfile(filename, ofstream::binary);
29  if (buf) {
30  const IOBuf* p = buf;
31  do {
32  outfile.write((const char *)p->data(), p->length());
33  p = p->next();
34  } while (p->next() != buf);
35  }
36  outfile.close();
37 }
const uint8_t * data() const
Definition: IOBuf.h:499
std::size_t length() const
Definition: IOBuf.h:533
IOBuf * next()
Definition: IOBuf.h:600
std::unique_ptr< folly::IOBuf > proxygen::hpack::encodeDecode ( vector< HPACKHeader > &  headers,
HPACKEncoder encoder,
HPACKDecoder decoder 
)

Definition at line 55 of file TestUtil.cpp.

References decode(), proxygen::HPACKEncoder::encode(), EXPECT_EQ, proxygen::HPACKContext::getTable(), proxygen::HPACKDecoderBase::hasError(), and verifyHeaders().

58  {
59  unique_ptr<IOBuf> encoded = encoder.encode(headers);
60  auto decodedHeaders = hpack::decode(decoder, encoded.get());
61  CHECK(!decoder.hasError());
62 
63  verifyHeaders(headers, *decodedHeaders);
64 
65  // header tables should look the same
66  CHECK(encoder.getTable() == decoder.getTable());
67  EXPECT_EQ(encoder.getTable(), decoder.getTable());
68 
69  return encoded;
70 }
void verifyHeaders(vector< HPACKHeader > &headers, vector< HPACKHeader > &decodedHeaders)
Definition: TestUtil.cpp:39
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
unique_ptr< HPACKDecoder::headers_t > decode(HPACKDecoder &decoder, const IOBuf *buffer)
Definition: TestUtil.cpp:95
void proxygen::hpack::encodeDecode ( vector< HPACKHeader > &  headers,
QPACKEncoder encoder,
QPACKDecoder decoder 
)

Definition at line 72 of file TestUtil.cpp.

References proxygen::QPACKEncoder::decodeDecoderStream(), proxygen::QPACKDecoder::decodeEncoderStream(), proxygen::QPACKDecoder::decodeStreaming(), proxygen::QPACKEncoder::encode(), proxygen::QPACKDecoder::encodeHeaderAck(), proxygen::QPACKDecoder::encodeTableStateSync(), EXPECT_EQ, proxygen::QPACKContext::getTable(), proxygen::TestStreamingCallback::hasError(), proxygen::TestStreamingCallback::hpackHeaders(), folly::gen::move, and verifyHeaders().

75  {
76  auto encoded = encoder.encode(headers, 0, 1);
77  TestStreamingCallback cb;
78  if (encoded.control) {
79  decoder.decodeEncoderStream(std::move(encoded.control));
80  encoder.decodeDecoderStream(decoder.encodeTableStateSync());
81  }
82  CHECK(encoded.stream);
83  auto length = encoded.stream->computeChainDataLength();
84  decoder.decodeStreaming(1, std::move(encoded.stream), length, &cb);
85  CHECK(!cb.hasError());
86  auto decodedHeaders = cb.hpackHeaders();
87  verifyHeaders(headers, *decodedHeaders);
88  encoder.decodeDecoderStream(decoder.encodeHeaderAck(1));
89 
90  // header tables should look the same
91  CHECK(encoder.getTable() == decoder.getTable());
92  EXPECT_EQ(encoder.getTable(), decoder.getTable());
93 }
void verifyHeaders(vector< HPACKHeader > &headers, vector< HPACKHeader > &decodedHeaders)
Definition: TestUtil.cpp:39
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::vector< compress::Header > proxygen::hpack::headersFromArray ( vector< vector< string >> &  a)

Definition at line 108 of file TestUtil.cpp.

References a, and proxygen::compress::Header::makeHeaderForTest().

Referenced by basicHeaders(), and TEST_F().

108  {
109  vector<compress::Header> headers;
110  for (auto& ha : a) {
111  headers.push_back(compress::Header::makeHeaderForTest(ha[0], ha[1]));
112  }
113  return headers;
114 }
void proxygen::hpack::verifyHeaders ( vector< HPACKHeader > &  headers,
vector< HPACKHeader > &  decodedHeaders 
)

Definition at line 39 of file TestUtil.cpp.

References EXPECT_EQ, and proxygen::printDelta().

Referenced by encodeDecode().

40  {
41  EXPECT_EQ(headers.size(), decodedHeaders.size());
42  std::sort(decodedHeaders.begin(), decodedHeaders.end());
43  std::sort(headers.begin(), headers.end());
44  if (headers.size() != decodedHeaders.size()) {
45  std::cerr << printDelta(decodedHeaders, headers);
46  CHECK(false) << "Mismatched headers size";
47  }
48  EXPECT_EQ(headers, decodedHeaders);
49  if (headers != decodedHeaders) {
50  std::cerr << printDelta(headers, decodedHeaders);
51  CHECK(false) << "Mismatched headers";
52  }
53 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
string printDelta(const vector< HPACKHeader > &v1, const vector< HPACKHeader > &v2)
Definition: Logging.cpp:38