diff --git a/src/net/spdy/spdy_session.cc b/src/net/spdy/spdy_session.cc index 86a17485f1..c5c4df3126 100644 --- a/src/net/spdy/spdy_session.cc +++ b/src/net/spdy/spdy_session.cc @@ -2315,6 +2315,25 @@ void SpdySession::EnqueueResetStreamFrame(spdy::SpdyStreamId stream_id, DCHECK(buffered_spdy_framer_.get()); std::unique_ptr rst_frame( buffered_spdy_framer_->CreateRstStream(stream_id, error_code)); + // Can't send padding if the send window is very tight. + if (session_send_window_size_ >= 72) { + constexpr int kNonPaddingSize = + spdy::kDataFrameMinimumSize + spdy::kRstStreamFrameSize; + uint8_t padding_length = base::RandInt(48, 72) - kNonPaddingSize; + size_t expected_length = kNonPaddingSize + padding_length; + spdy::SpdyFrameBuilder builder(expected_length); + builder.BeginNewFrame(spdy::SpdyFrameType::DATA, + spdy::DATA_FLAG_FIN | spdy::DATA_FLAG_PADDED, + stream_id, padding_length); + builder.WriteUInt8(padding_length - 1); + std::string padding(padding_length - 1, 0); + builder.WriteBytes(padding.data(), padding.size()); + builder.BeginNewFrame(spdy::SpdyFrameType::RST_STREAM, 0, stream_id, 4); + builder.WriteUInt32(error_code); + DCHECK_EQ(expected_length, builder.length()); + rst_frame = std::make_unique(builder.take()); + DecreaseSendWindowSize(padding_length); + } EnqueueSessionWrite(priority, spdy::SpdyFrameType::RST_STREAM, std::move(rst_frame));