Adds support for METADATA frames to TestFrameSequence.
This will make it easier to test metadata handling behavior in adapter unit tests.
PiperOrigin-RevId: 381314900
diff --git a/http2/adapter/test_frame_sequence.cc b/http2/adapter/test_frame_sequence.cc
index 7be368e..a64f915 100644
--- a/http2/adapter/test_frame_sequence.cc
+++ b/http2/adapter/test_frame_sequence.cc
@@ -2,6 +2,7 @@
#include "http2/adapter/http2_util.h"
#include "http2/adapter/oghttp2_util.h"
+#include "spdy/core/hpack/hpack_encoder.h"
#include "spdy/core/spdy_framer.h"
namespace http2 {
@@ -124,6 +125,21 @@
return *this;
}
+TestFrameSequence& TestFrameSequence::Metadata(Http2StreamId stream_id,
+ absl::string_view payload) {
+ // Encode the payload using a header block.
+ spdy::SpdyHeaderBlock block;
+ block["example-payload"] = payload;
+ spdy::HpackEncoder encoder;
+ encoder.DisableCompression();
+ std::string encoded_payload;
+ encoder.EncodeHeaderSet(block, &encoded_payload);
+ frames_.push_back(absl::make_unique<spdy::SpdyUnknownIR>(
+ stream_id, kMetadataFrameType, kMetadataEndFlag,
+ std::move(encoded_payload)));
+ return *this;
+}
+
std::string TestFrameSequence::Serialize() {
std::string result;
if (!preface_.empty()) {