Removes DataFrameSource-based DATA frame manipulation from NgHttp2Adapter.
Also removes associated utilities that are no longer necessary.
The `DataFrameSource` parts of the API are no longer used.
PiperOrigin-RevId: 699944678
diff --git a/quiche/http2/adapter/nghttp2_adapter.cc b/quiche/http2/adapter/nghttp2_adapter.cc
index 6e653f5..fd889c4 100644
--- a/quiche/http2/adapter/nghttp2_adapter.cc
+++ b/quiche/http2/adapter/nghttp2_adapter.cc
@@ -304,10 +304,11 @@
absl::Span<const Header> headers,
std::unique_ptr<DataFrameSource> data_source, bool end_stream,
void* stream_user_data) {
+ QUICHE_DCHECK(data_source == nullptr);
auto nvs = GetNghttp2Nvs(headers);
std::unique_ptr<nghttp2_data_provider> provider;
- if (data_source != nullptr || !end_stream) {
+ if (!end_stream) {
provider = std::make_unique<nghttp2_data_provider>();
provider->source.ptr = this;
provider->read_callback = &DataFrameReadCallback;
@@ -316,9 +317,6 @@
int32_t stream_id =
nghttp2_submit_request(session_->raw_ptr(), nullptr, nvs.data(),
nvs.size(), provider.get(), stream_user_data);
- if (data_source != nullptr) {
- sources_.emplace(stream_id, std::move(data_source));
- }
QUICHE_VLOG(1) << "Submitted request with " << nvs.size()
<< " request headers and user data " << stream_user_data
<< "; resulted in stream " << stream_id;
@@ -329,16 +327,14 @@
absl::Span<const Header> headers,
std::unique_ptr<DataFrameSource> data_source,
bool end_stream) {
+ QUICHE_DCHECK(data_source == nullptr);
auto nvs = GetNghttp2Nvs(headers);
std::unique_ptr<nghttp2_data_provider> provider;
- if (data_source != nullptr || !end_stream) {
+ if (!end_stream) {
provider = std::make_unique<nghttp2_data_provider>();
provider->source.ptr = this;
provider->read_callback = &DataFrameReadCallback;
}
- if (data_source != nullptr) {
- sources_.emplace(stream_id, std::move(data_source));
- }
int result = nghttp2_submit_response(session_->raw_ptr(), stream_id,
nvs.data(), nvs.size(), provider.get());
@@ -377,39 +373,22 @@
}
}
-void NgHttp2Adapter::RemoveStream(Http2StreamId stream_id) {
- sources_.erase(stream_id);
-}
+void NgHttp2Adapter::RemoveStream(Http2StreamId /*stream_id*/) {}
ssize_t NgHttp2Adapter::DelegateReadCallback(int32_t stream_id,
size_t max_length,
uint32_t* data_flags) {
- auto it = sources_.find(stream_id);
- if (it == sources_.end()) {
- // A DataFrameSource is not available for this stream; forward to the
- // visitor.
- return callbacks::VisitorReadCallback(visitor_, stream_id, max_length,
- data_flags);
- } else {
- // A DataFrameSource is available for this stream.
- return callbacks::DataFrameSourceReadCallback(*it->second, max_length,
- data_flags);
- }
+ // Forward to the visitor.
+ return callbacks::VisitorReadCallback(visitor_, stream_id, max_length,
+ data_flags);
}
int NgHttp2Adapter::DelegateSendCallback(int32_t stream_id,
const uint8_t* framehd,
size_t length) {
- auto it = sources_.find(stream_id);
- if (it == sources_.end()) {
- // A DataFrameSource is not available for this stream; forward to the
- // visitor.
- visitor_.SendDataFrame(stream_id, ToStringView(framehd, kFrameHeaderSize),
- length);
- } else {
- // A DataFrameSource is available for this stream.
- it->second->Send(ToStringView(framehd, kFrameHeaderSize), length);
- }
+ // Forward to the visitor.
+ visitor_.SendDataFrame(stream_id, ToStringView(framehd, kFrameHeaderSize),
+ length);
return 0;
}
diff --git a/quiche/http2/adapter/nghttp2_adapter.h b/quiche/http2/adapter/nghttp2_adapter.h
index c2e18be..69f5805 100644
--- a/quiche/http2/adapter/nghttp2_adapter.h
+++ b/quiche/http2/adapter/nghttp2_adapter.h
@@ -97,7 +97,7 @@
void RemoveStream(Http2StreamId stream_id);
// Accessor for testing.
- size_t sources_size() const { return sources_.size(); }
+ size_t sources_size() const { return 0; }
size_t stream_metadata_size() const { return stream_metadata_.size(); }
size_t pending_metadata_count(Http2StreamId stream_id) const {
if (auto it = stream_metadata_.find(stream_id);
@@ -139,8 +139,6 @@
absl::InlinedVector<std::unique_ptr<MetadataSource>, 2>;
using MetadataMap = absl::flat_hash_map<Http2StreamId, MetadataSourceVec>;
MetadataMap stream_metadata_;
-
- absl::flat_hash_map<int32_t, std::unique_ptr<DataFrameSource>> sources_;
};
} // namespace adapter
diff --git a/quiche/http2/adapter/nghttp2_data_provider.cc b/quiche/http2/adapter/nghttp2_data_provider.cc
index 3475210..a775982 100644
--- a/quiche/http2/adapter/nghttp2_data_provider.cc
+++ b/quiche/http2/adapter/nghttp2_data_provider.cc
@@ -28,24 +28,6 @@
return payload_length;
}
-ssize_t DataFrameSourceReadCallback(DataFrameSource& source, size_t length,
- uint32_t* data_flags) {
- *data_flags |= NGHTTP2_DATA_FLAG_NO_COPY;
- auto [result_length, done] = source.SelectPayloadLength(length);
- if (result_length == 0 && !done) {
- return NGHTTP2_ERR_DEFERRED;
- } else if (result_length == DataFrameSource::kError) {
- return NGHTTP2_ERR_TEMPORAL_CALLBACK_FAILURE;
- }
- if (done) {
- *data_flags |= NGHTTP2_DATA_FLAG_EOF;
- }
- if (!source.send_fin()) {
- *data_flags |= NGHTTP2_DATA_FLAG_NO_END_STREAM;
- }
- return result_length;
-}
-
} // namespace callbacks
} // namespace adapter
} // namespace http2
diff --git a/quiche/http2/adapter/nghttp2_data_provider.h b/quiche/http2/adapter/nghttp2_data_provider.h
index a0c9cd9..0686391 100644
--- a/quiche/http2/adapter/nghttp2_data_provider.h
+++ b/quiche/http2/adapter/nghttp2_data_provider.h
@@ -17,11 +17,6 @@
ssize_t VisitorReadCallback(Http2VisitorInterface& visitor, int32_t stream_id,
size_t max_length, uint32_t* data_flags);
-// A callback that returns DATA frame payload size and associated flags, given a
-// DataFrameSource.
-ssize_t DataFrameSourceReadCallback(DataFrameSource& source, size_t length,
- uint32_t* data_flags);
-
} // namespace callbacks
} // namespace adapter
} // namespace http2
diff --git a/quiche/http2/adapter/nghttp2_data_provider_test.cc b/quiche/http2/adapter/nghttp2_data_provider_test.cc
index 6ebc8b9..dc5c128 100644
--- a/quiche/http2/adapter/nghttp2_data_provider_test.cc
+++ b/quiche/http2/adapter/nghttp2_data_provider_test.cc
@@ -10,31 +10,6 @@
const size_t kFrameHeaderSize = 9;
-// Verifies that the DataFrameSource read callback works correctly when the
-// amount of data read is less than what the source provides.
-TEST(DataFrameSourceTest, ReadLessThanSourceProvides) {
- const int32_t kStreamId = 1;
- TestVisitor visitor;
- visitor.AppendPayloadForStream(kStreamId, "Example payload");
- visitor.SetEndData(kStreamId, true);
- VisitorDataSource source(visitor, kStreamId);
- uint32_t data_flags = 0;
- const size_t kReadLength = 10;
- // Read callback selects a payload length given an upper bound.
- ssize_t result =
- callbacks::DataFrameSourceReadCallback(source, kReadLength, &data_flags);
- ASSERT_EQ(kReadLength, result);
- EXPECT_EQ(NGHTTP2_DATA_FLAG_NO_COPY | NGHTTP2_DATA_FLAG_NO_END_STREAM,
- data_flags);
-
- const uint8_t framehd[kFrameHeaderSize] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
- // Sends the frame header and some payload bytes.
- source.Send(ToStringView(framehd, kFrameHeaderSize), result);
- // Data accepted by the visitor includes a frame header and kReadLength bytes
- // of payload.
- EXPECT_EQ(visitor.data().size(), kFrameHeaderSize + kReadLength);
-}
-
// Verifies that the Visitor read callback works correctly when the amount of
// data read is less than what the source provides.
TEST(VisitorTest, ReadLessThanSourceProvides) {
@@ -60,31 +35,6 @@
EXPECT_EQ(visitor.data().size(), kFrameHeaderSize + kReadLength);
}
-// Verifies that the DataFrameSource read callback works correctly when the
-// amount of data read is more than what the source provides.
-TEST(DataFrameSourceTest, ReadMoreThanSourceProvides) {
- const int32_t kStreamId = 1;
- const absl::string_view kPayload = "Example payload";
- TestVisitor visitor;
- visitor.AppendPayloadForStream(kStreamId, kPayload);
- visitor.SetEndData(kStreamId, true);
- VisitorDataSource source(visitor, kStreamId);
- uint32_t data_flags = 0;
- const size_t kReadLength = 30;
- // Read callback selects a payload length given an upper bound.
- ssize_t result =
- callbacks::DataFrameSourceReadCallback(source, kReadLength, &data_flags);
- ASSERT_EQ(kPayload.size(), result);
- EXPECT_EQ(NGHTTP2_DATA_FLAG_NO_COPY | NGHTTP2_DATA_FLAG_EOF, data_flags);
-
- const uint8_t framehd[kFrameHeaderSize] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
- // Sends the frame header and some payload bytes.
- source.Send(ToStringView(framehd, kFrameHeaderSize), result);
- // Data accepted by the visitor includes a frame header and the entire
- // payload.
- EXPECT_EQ(visitor.data().size(), kFrameHeaderSize + kPayload.size());
-}
-
// Verifies that the Visitor read callback works correctly when the amount of
// data read is more than what the source provides.
TEST(VisitorTest, ReadMoreThanSourceProvides) {
@@ -93,7 +43,6 @@
TestVisitor visitor;
visitor.AppendPayloadForStream(kStreamId, kPayload);
visitor.SetEndData(kStreamId, true);
- VisitorDataSource source(visitor, kStreamId);
uint32_t data_flags = 0;
const size_t kReadLength = 30;
// Read callback selects a payload length given an upper bound.
@@ -111,21 +60,6 @@
EXPECT_EQ(visitor.data().size(), kFrameHeaderSize + kPayload.size());
}
-// Verifies that the DataFrameSource read callback works correctly when the
-// source is blocked.
-TEST(DataFrameSourceTest, ReadFromBlockedSource) {
- const int32_t kStreamId = 1;
- TestVisitor visitor;
- // Source has no payload, but also no fin, so it's blocked.
- VisitorDataSource source(visitor, kStreamId);
- uint32_t data_flags = 0;
- const size_t kReadLength = 10;
- ssize_t result =
- callbacks::DataFrameSourceReadCallback(source, kReadLength, &data_flags);
- // Read operation is deferred, since the source is blocked.
- EXPECT_EQ(NGHTTP2_ERR_DEFERRED, result);
-}
-
// Verifies that the Visitor read callback works correctly when the source is
// blocked.
TEST(VisitorTest, ReadFromBlockedSource) {
@@ -140,28 +74,6 @@
EXPECT_EQ(NGHTTP2_ERR_DEFERRED, result);
}
-// Verifies that the DataFrameSource read callback works correctly when the
-// source provides only fin and no data.
-TEST(DataFrameSourceTest, ReadFromZeroLengthSource) {
- const int32_t kStreamId = 1;
- TestVisitor visitor;
- visitor.SetEndData(kStreamId, true);
- // Empty payload and fin=true indicates the source is done.
- VisitorDataSource source(visitor, kStreamId);
- uint32_t data_flags = 0;
- const size_t kReadLength = 10;
- ssize_t result =
- callbacks::DataFrameSourceReadCallback(source, kReadLength, &data_flags);
- ASSERT_EQ(0, result);
- EXPECT_EQ(NGHTTP2_DATA_FLAG_NO_COPY | NGHTTP2_DATA_FLAG_EOF, data_flags);
-
- const uint8_t framehd[kFrameHeaderSize] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
- source.Send(ToStringView(framehd, kFrameHeaderSize), result);
- // Data accepted by the visitor includes a frame header with fin and zero
- // bytes of payload.
- EXPECT_EQ(visitor.data().size(), kFrameHeaderSize);
-}
-
// Verifies that the Visitor read callback works correctly when the source
// provides only fin and no data.
TEST(VisitorTest, ReadFromZeroLengthSource) {