QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_stream.h" |
| 6 | |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 7 | #include <limits> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 8 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | #include <utility> |
| 10 | |
bnc | 3fc60df | 2019-07-17 11:55:10 -0700 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/quic/core/http/http_constants.h" |
renjietang | 7d4f913 | 2019-06-20 15:04:34 -0700 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/core/http/http_decoder.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_session.h" |
| 14 | #include "net/third_party/quiche/src/quic/core/http/spdy_utils.h" |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 15 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_decoder.h" |
| 16 | #include "net/third_party/quiche/src/quic/core/qpack/qpack_encoder.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 18 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 19 | #include "net/third_party/quiche/src/quic/core/quic_write_blocked_list.h" |
| 20 | #include "net/third_party/quiche/src/quic/platform/api/quic_bug_tracker.h" |
| 21 | #include "net/third_party/quiche/src/quic/platform/api/quic_flag_utils.h" |
| 22 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 23 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 24 | #include "net/third_party/quiche/src/quic/platform/api/quic_mem_slice_storage.h" |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 25 | #include "net/third_party/quiche/src/common/platform/api/quiche_arraysize.h" |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 26 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
| 27 | #include "net/third_party/quiche/src/common/platform/api/quiche_text_utils.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 28 | #include "net/third_party/quiche/src/spdy/core/spdy_protocol.h" |
| 29 | |
| 30 | using spdy::SpdyHeaderBlock; |
| 31 | using spdy::SpdyPriority; |
| 32 | |
| 33 | namespace quic { |
| 34 | |
| 35 | // Visitor of HttpDecoder that passes data frame to QuicSpdyStream and closes |
| 36 | // the connection on unexpected frames. |
| 37 | class QuicSpdyStream::HttpDecoderVisitor : public HttpDecoder::Visitor { |
| 38 | public: |
| 39 | explicit HttpDecoderVisitor(QuicSpdyStream* stream) : stream_(stream) {} |
| 40 | HttpDecoderVisitor(const HttpDecoderVisitor&) = delete; |
| 41 | HttpDecoderVisitor& operator=(const HttpDecoderVisitor&) = delete; |
| 42 | |
bnc | dfabdfb | 2020-01-17 17:46:40 -0800 | [diff] [blame] | 43 | void OnError(HttpDecoder* decoder) override { |
renjietang | 87df0d0 | 2020-02-13 11:53:52 -0800 | [diff] [blame] | 44 | stream_->OnUnrecoverableError(decoder->error(), decoder->error_detail()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 45 | } |
| 46 | |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 47 | bool OnCancelPushFrame(const CancelPushFrame& /*frame*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | CloseConnectionOnWrongFrame("Cancel Push"); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 49 | return false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 50 | } |
| 51 | |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 52 | bool OnMaxPushIdFrame(const MaxPushIdFrame& /*frame*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 53 | CloseConnectionOnWrongFrame("Max Push Id"); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 54 | return false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 55 | } |
| 56 | |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 57 | bool OnGoAwayFrame(const GoAwayFrame& /*frame*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 58 | CloseConnectionOnWrongFrame("Goaway"); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 59 | return false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 60 | } |
| 61 | |
bnc | a2b13be | 2019-07-31 12:04:20 -0700 | [diff] [blame] | 62 | bool OnSettingsFrameStart(QuicByteCount /*header_length*/) override { |
renjietang | f41bf64 | 2019-04-02 11:45:34 -0700 | [diff] [blame] | 63 | CloseConnectionOnWrongFrame("Settings"); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 64 | return false; |
renjietang | f41bf64 | 2019-04-02 11:45:34 -0700 | [diff] [blame] | 65 | } |
| 66 | |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 67 | bool OnSettingsFrame(const SettingsFrame& /*frame*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 68 | CloseConnectionOnWrongFrame("Settings"); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 69 | return false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 70 | } |
| 71 | |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 72 | bool OnDataFrameStart(QuicByteCount header_length, |
| 73 | QuicByteCount payload_length) override { |
| 74 | return stream_->OnDataFrameStart(header_length, payload_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 75 | } |
| 76 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 77 | bool OnDataFramePayload(quiche::QuicheStringPiece payload) override { |
bnc | 7091426 | 2019-03-16 12:49:50 -0700 | [diff] [blame] | 78 | DCHECK(!payload.empty()); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 79 | return stream_->OnDataFramePayload(payload); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 80 | } |
| 81 | |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 82 | bool OnDataFrameEnd() override { return stream_->OnDataFrameEnd(); } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 83 | |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 84 | bool OnHeadersFrameStart(QuicByteCount header_length, |
| 85 | QuicByteCount payload_length) override { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 86 | if (!VersionUsesHttp3(stream_->transport_version())) { |
bnc | 62446bc | 2019-03-14 06:11:25 -0700 | [diff] [blame] | 87 | CloseConnectionOnWrongFrame("Headers"); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 88 | return false; |
bnc | 62446bc | 2019-03-14 06:11:25 -0700 | [diff] [blame] | 89 | } |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 90 | return stream_->OnHeadersFrameStart(header_length, payload_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 91 | } |
| 92 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 93 | bool OnHeadersFramePayload(quiche::QuicheStringPiece payload) override { |
bnc | 7091426 | 2019-03-16 12:49:50 -0700 | [diff] [blame] | 94 | DCHECK(!payload.empty()); |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 95 | if (!VersionUsesHttp3(stream_->transport_version())) { |
bnc | 62446bc | 2019-03-14 06:11:25 -0700 | [diff] [blame] | 96 | CloseConnectionOnWrongFrame("Headers"); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 97 | return false; |
bnc | 62446bc | 2019-03-14 06:11:25 -0700 | [diff] [blame] | 98 | } |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 99 | return stream_->OnHeadersFramePayload(payload); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 100 | } |
| 101 | |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 102 | bool OnHeadersFrameEnd() override { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 103 | if (!VersionUsesHttp3(stream_->transport_version())) { |
bnc | 62446bc | 2019-03-14 06:11:25 -0700 | [diff] [blame] | 104 | CloseConnectionOnWrongFrame("Headers"); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 105 | return false; |
bnc | 62446bc | 2019-03-14 06:11:25 -0700 | [diff] [blame] | 106 | } |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 107 | return stream_->OnHeadersFrameEnd(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 108 | } |
| 109 | |
bnc | f0db654 | 2019-09-23 11:18:28 -0700 | [diff] [blame] | 110 | bool OnPushPromiseFrameStart(QuicByteCount header_length) override { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 111 | if (!VersionUsesHttp3(stream_->transport_version())) { |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 112 | CloseConnectionOnWrongFrame("Push Promise"); |
| 113 | return false; |
| 114 | } |
bnc | f0db654 | 2019-09-23 11:18:28 -0700 | [diff] [blame] | 115 | return stream_->OnPushPromiseFrameStart(header_length); |
| 116 | } |
| 117 | |
| 118 | bool OnPushPromiseFramePushId(PushId push_id, |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 119 | QuicByteCount push_id_length, |
| 120 | QuicByteCount header_block_length) override { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 121 | if (!VersionUsesHttp3(stream_->transport_version())) { |
bnc | f0db654 | 2019-09-23 11:18:28 -0700 | [diff] [blame] | 122 | CloseConnectionOnWrongFrame("Push Promise"); |
| 123 | return false; |
| 124 | } |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 125 | return stream_->OnPushPromiseFramePushId(push_id, push_id_length, |
| 126 | header_block_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 127 | } |
| 128 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 129 | bool OnPushPromiseFramePayload(quiche::QuicheStringPiece payload) override { |
bnc | 7091426 | 2019-03-16 12:49:50 -0700 | [diff] [blame] | 130 | DCHECK(!payload.empty()); |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 131 | if (!VersionUsesHttp3(stream_->transport_version())) { |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 132 | CloseConnectionOnWrongFrame("Push Promise"); |
| 133 | return false; |
| 134 | } |
| 135 | return stream_->OnPushPromiseFramePayload(payload); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 136 | } |
| 137 | |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 138 | bool OnPushPromiseFrameEnd() override { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 139 | if (!VersionUsesHttp3(stream_->transport_version())) { |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 140 | CloseConnectionOnWrongFrame("Push Promise"); |
| 141 | return false; |
| 142 | } |
| 143 | return stream_->OnPushPromiseFrameEnd(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 144 | } |
| 145 | |
bnc | 51e8962 | 2020-01-10 10:40:32 -0800 | [diff] [blame] | 146 | bool OnPriorityUpdateFrameStart(QuicByteCount /*header_length*/) override { |
| 147 | CloseConnectionOnWrongFrame("Priority update"); |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | bool OnPriorityUpdateFrame(const PriorityUpdateFrame& /*frame*/) override { |
| 152 | CloseConnectionOnWrongFrame("Priority update"); |
| 153 | return false; |
| 154 | } |
| 155 | |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 156 | bool OnUnknownFrameStart(uint64_t frame_type, |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 157 | QuicByteCount header_length, |
| 158 | QuicByteCount payload_length) override { |
| 159 | return stream_->OnUnknownFrameStart(frame_type, header_length, |
| 160 | payload_length); |
bnc | bf3dbe5 | 2019-07-17 05:17:41 -0700 | [diff] [blame] | 161 | } |
| 162 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 163 | bool OnUnknownFramePayload(quiche::QuicheStringPiece payload) override { |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 164 | return stream_->OnUnknownFramePayload(payload); |
bnc | bf3dbe5 | 2019-07-17 05:17:41 -0700 | [diff] [blame] | 165 | } |
| 166 | |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 167 | bool OnUnknownFrameEnd() override { return stream_->OnUnknownFrameEnd(); } |
bnc | bf3dbe5 | 2019-07-17 05:17:41 -0700 | [diff] [blame] | 168 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 169 | private: |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 170 | void CloseConnectionOnWrongFrame(quiche::QuicheStringPiece frame_type) { |
renjietang | 87df0d0 | 2020-02-13 11:53:52 -0800 | [diff] [blame] | 171 | stream_->OnUnrecoverableError( |
bnc | dfabdfb | 2020-01-17 17:46:40 -0800 | [diff] [blame] | 172 | QUIC_HTTP_FRAME_UNEXPECTED_ON_SPDY_STREAM, |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 173 | quiche::QuicheStrCat(frame_type, " frame received on data stream")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | QuicSpdyStream* stream_; |
| 177 | }; |
| 178 | |
| 179 | #define ENDPOINT \ |
| 180 | (session()->perspective() == Perspective::IS_SERVER ? "Server: " \ |
| 181 | : "Client:" \ |
| 182 | " ") |
| 183 | |
| 184 | QuicSpdyStream::QuicSpdyStream(QuicStreamId id, |
| 185 | QuicSpdySession* spdy_session, |
| 186 | StreamType type) |
| 187 | : QuicStream(id, spdy_session, /*is_static=*/false, type), |
| 188 | spdy_session_(spdy_session), |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 189 | on_body_available_called_because_sequencer_is_closed_(false), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 190 | visitor_(nullptr), |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 191 | blocked_on_decoding_headers_(false), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 192 | headers_decompressed_(false), |
bnc | 446887e | 2019-11-27 13:08:28 -0800 | [diff] [blame] | 193 | header_list_size_limit_exceeded_(false), |
renjietang | 6f572a8 | 2019-07-23 16:33:13 -0700 | [diff] [blame] | 194 | headers_payload_length_(0), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 195 | trailers_decompressed_(false), |
| 196 | trailers_consumed_(false), |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 197 | http_decoder_visitor_(std::make_unique<HttpDecoderVisitor>(this)), |
bnc | a9bb469 | 2019-07-09 17:29:48 -0700 | [diff] [blame] | 198 | decoder_(http_decoder_visitor_.get()), |
bnc | 8aadca7 | 2019-06-28 11:09:39 -0700 | [diff] [blame] | 199 | sequencer_offset_(0), |
| 200 | is_decoder_processing_input_(false), |
bnc | b8abf38 | 2020-01-30 11:26:12 -0800 | [diff] [blame] | 201 | ack_listener_(nullptr), |
bnc | 3e004e9 | 2020-08-31 07:03:13 -0700 | [diff] [blame] | 202 | last_sent_urgency_(DefaultUrgency()) { |
bnc | fa1de5f | 2019-07-09 17:53:56 -0700 | [diff] [blame] | 203 | DCHECK_EQ(session()->connection(), spdy_session->connection()); |
renjietang | d1d0085 | 2019-09-06 10:43:12 -0700 | [diff] [blame] | 204 | DCHECK_EQ(transport_version(), spdy_session->transport_version()); |
bnc | fa1de5f | 2019-07-09 17:53:56 -0700 | [diff] [blame] | 205 | DCHECK(!QuicUtils::IsCryptoStreamId(transport_version(), id)); |
bnc | 8aadca7 | 2019-06-28 11:09:39 -0700 | [diff] [blame] | 206 | DCHECK_EQ(0u, sequencer()->NumBytesConsumed()); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 207 | // If headers are sent on the headers stream, then do not receive any |
| 208 | // callbacks from the sequencer until headers are complete. |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 209 | if (!VersionUsesHttp3(transport_version())) { |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 210 | sequencer()->SetBlockedUntilFlush(); |
| 211 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 212 | |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 213 | if (VersionUsesHttp3(transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 214 | sequencer()->set_level_triggered(true); |
| 215 | } |
bnc | f6b86b2 | 2020-01-26 11:08:46 -0800 | [diff] [blame] | 216 | |
| 217 | spdy_session_->OnStreamCreated(this); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 218 | } |
| 219 | |
renjietang | baea59c | 2019-05-29 15:08:14 -0700 | [diff] [blame] | 220 | QuicSpdyStream::QuicSpdyStream(PendingStream* pending, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 221 | QuicSpdySession* spdy_session, |
| 222 | StreamType type) |
renjietang | 49aec63 | 2020-08-31 10:56:28 -0700 | [diff] [blame] | 223 | : QuicStream(pending, spdy_session, type, /*is_static=*/false), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 224 | spdy_session_(spdy_session), |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 225 | on_body_available_called_because_sequencer_is_closed_(false), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 226 | visitor_(nullptr), |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 227 | blocked_on_decoding_headers_(false), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 228 | headers_decompressed_(false), |
bnc | 446887e | 2019-11-27 13:08:28 -0800 | [diff] [blame] | 229 | header_list_size_limit_exceeded_(false), |
renjietang | 6f572a8 | 2019-07-23 16:33:13 -0700 | [diff] [blame] | 230 | headers_payload_length_(0), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 231 | trailers_decompressed_(false), |
| 232 | trailers_consumed_(false), |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 233 | http_decoder_visitor_(std::make_unique<HttpDecoderVisitor>(this)), |
bnc | a9bb469 | 2019-07-09 17:29:48 -0700 | [diff] [blame] | 234 | decoder_(http_decoder_visitor_.get()), |
bnc | 8aadca7 | 2019-06-28 11:09:39 -0700 | [diff] [blame] | 235 | sequencer_offset_(sequencer()->NumBytesConsumed()), |
| 236 | is_decoder_processing_input_(false), |
bnc | b8abf38 | 2020-01-30 11:26:12 -0800 | [diff] [blame] | 237 | ack_listener_(nullptr), |
bnc | 3e004e9 | 2020-08-31 07:03:13 -0700 | [diff] [blame] | 238 | last_sent_urgency_(DefaultUrgency()) { |
bnc | fa1de5f | 2019-07-09 17:53:56 -0700 | [diff] [blame] | 239 | DCHECK_EQ(session()->connection(), spdy_session->connection()); |
renjietang | d1d0085 | 2019-09-06 10:43:12 -0700 | [diff] [blame] | 240 | DCHECK_EQ(transport_version(), spdy_session->transport_version()); |
bnc | fa1de5f | 2019-07-09 17:53:56 -0700 | [diff] [blame] | 241 | DCHECK(!QuicUtils::IsCryptoStreamId(transport_version(), id())); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 242 | // If headers are sent on the headers stream, then do not receive any |
| 243 | // callbacks from the sequencer until headers are complete. |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 244 | if (!VersionUsesHttp3(transport_version())) { |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 245 | sequencer()->SetBlockedUntilFlush(); |
| 246 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 247 | |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 248 | if (VersionUsesHttp3(transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 249 | sequencer()->set_level_triggered(true); |
| 250 | } |
bnc | f6b86b2 | 2020-01-26 11:08:46 -0800 | [diff] [blame] | 251 | |
| 252 | spdy_session_->OnStreamCreated(this); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | QuicSpdyStream::~QuicSpdyStream() {} |
| 256 | |
| 257 | size_t QuicSpdyStream::WriteHeaders( |
| 258 | SpdyHeaderBlock header_block, |
| 259 | bool fin, |
| 260 | QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 261 | QuicConnection::ScopedPacketFlusher flusher(spdy_session_->connection()); |
renjietang | bb1c489 | 2019-05-24 15:58:44 -0700 | [diff] [blame] | 262 | // Send stream type for server push stream |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 263 | if (VersionUsesHttp3(transport_version()) && type() == WRITE_UNIDIRECTIONAL && |
| 264 | send_buffer().stream_offset() == 0) { |
renjietang | bb1c489 | 2019-05-24 15:58:44 -0700 | [diff] [blame] | 265 | char data[sizeof(kServerPushStream)]; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 266 | QuicDataWriter writer(QUICHE_ARRAYSIZE(data), data); |
renjietang | bb1c489 | 2019-05-24 15:58:44 -0700 | [diff] [blame] | 267 | writer.WriteVarInt62(kServerPushStream); |
| 268 | |
| 269 | // Similar to frame headers, stream type byte shouldn't be exposed to upper |
| 270 | // layer applications. |
| 271 | unacked_frame_headers_offsets_.Add(0, writer.length()); |
| 272 | |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 273 | QUIC_LOG(INFO) << ENDPOINT << "Stream " << id() |
| 274 | << " is writing type as server push"; |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 275 | WriteOrBufferData(quiche::QuicheStringPiece(writer.data(), writer.length()), |
| 276 | false, nullptr); |
renjietang | bb1c489 | 2019-05-24 15:58:44 -0700 | [diff] [blame] | 277 | } |
bnc | 80abd36 | 2020-01-30 10:46:30 -0800 | [diff] [blame] | 278 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 279 | size_t bytes_written = |
| 280 | WriteHeadersImpl(std::move(header_block), fin, std::move(ack_listener)); |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 281 | if (!VersionUsesHttp3(transport_version()) && fin) { |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 282 | // If HEADERS are sent on the headers stream, then |fin_sent_| needs to be |
| 283 | // set and write side needs to be closed without actually sending a FIN on |
| 284 | // this stream. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 285 | // TODO(rch): Add test to ensure fin_sent_ is set whenever a fin is sent. |
fayang | 3a51d1a | 2020-04-16 13:42:08 -0700 | [diff] [blame] | 286 | SetFinSent(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 287 | CloseWriteSide(); |
| 288 | } |
| 289 | return bytes_written; |
| 290 | } |
| 291 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 292 | void QuicSpdyStream::WriteOrBufferBody(quiche::QuicheStringPiece data, |
| 293 | bool fin) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 294 | if (!VersionUsesHttp3(transport_version()) || data.length() == 0) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 295 | WriteOrBufferData(data, fin, nullptr); |
| 296 | return; |
| 297 | } |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 298 | QuicConnection::ScopedPacketFlusher flusher(spdy_session_->connection()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 299 | |
bnc | b9d5e79 | 2020-03-20 17:43:41 -0700 | [diff] [blame] | 300 | if (spdy_session_->debug_visitor()) { |
| 301 | spdy_session_->debug_visitor()->OnDataFrameSent(id(), data.length()); |
| 302 | } |
| 303 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 304 | // Write frame header. |
| 305 | std::unique_ptr<char[]> buffer; |
| 306 | QuicByteCount header_length = |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 307 | HttpEncoder::SerializeDataFrameHeader(data.length(), &buffer); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 308 | unacked_frame_headers_offsets_.Add( |
| 309 | send_buffer().stream_offset(), |
| 310 | send_buffer().stream_offset() + header_length); |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 311 | QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id() |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 312 | << " is writing DATA frame header of length " |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 313 | << header_length; |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 314 | WriteOrBufferData(quiche::QuicheStringPiece(buffer.get(), header_length), |
| 315 | false, nullptr); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 316 | |
| 317 | // Write body. |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 318 | QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id() |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 319 | << " is writing DATA frame payload of length " |
renjietang | dbe9834 | 2019-10-18 11:00:57 -0700 | [diff] [blame] | 320 | << data.length() << " with fin " << fin; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 321 | WriteOrBufferData(data, fin, nullptr); |
| 322 | } |
| 323 | |
| 324 | size_t QuicSpdyStream::WriteTrailers( |
| 325 | SpdyHeaderBlock trailer_block, |
| 326 | QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
| 327 | if (fin_sent()) { |
| 328 | QUIC_BUG << "Trailers cannot be sent after a FIN, on stream " << id(); |
| 329 | return 0; |
| 330 | } |
| 331 | |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 332 | if (!VersionUsesHttp3(transport_version())) { |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 333 | // The header block must contain the final offset for this stream, as the |
| 334 | // trailers may be processed out of order at the peer. |
| 335 | const QuicStreamOffset final_offset = |
| 336 | stream_bytes_written() + BufferedDataBytes(); |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 337 | QUIC_DLOG(INFO) << ENDPOINT << "Inserting trailer: (" |
| 338 | << kFinalOffsetHeaderKey << ", " << final_offset << ")"; |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 339 | trailer_block.insert( |
| 340 | std::make_pair(kFinalOffsetHeaderKey, |
| 341 | quiche::QuicheTextUtils::Uint64ToString(final_offset))); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 342 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 343 | |
| 344 | // Write the trailing headers with a FIN, and close stream for writing: |
| 345 | // trailers are the last thing to be sent on a stream. |
| 346 | const bool kFin = true; |
| 347 | size_t bytes_written = |
| 348 | WriteHeadersImpl(std::move(trailer_block), kFin, std::move(ack_listener)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 349 | |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 350 | // If trailers are sent on the headers stream, then |fin_sent_| needs to be |
| 351 | // set without actually sending a FIN on this stream. |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 352 | if (!VersionUsesHttp3(transport_version())) { |
fayang | 3a51d1a | 2020-04-16 13:42:08 -0700 | [diff] [blame] | 353 | SetFinSent(); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 354 | |
| 355 | // Also, write side of this stream needs to be closed. However, only do |
| 356 | // this if there is no more buffered data, otherwise it will never be sent. |
| 357 | if (BufferedDataBytes() == 0) { |
| 358 | CloseWriteSide(); |
| 359 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | return bytes_written; |
| 363 | } |
| 364 | |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 365 | void QuicSpdyStream::WritePushPromise(const PushPromiseFrame& frame) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 366 | DCHECK(VersionUsesHttp3(transport_version())); |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 367 | std::unique_ptr<char[]> push_promise_frame_with_id; |
| 368 | const size_t push_promise_frame_length = |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 369 | HttpEncoder::SerializePushPromiseFrameWithOnlyPushId( |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 370 | frame, &push_promise_frame_with_id); |
| 371 | |
| 372 | unacked_frame_headers_offsets_.Add(send_buffer().stream_offset(), |
| 373 | send_buffer().stream_offset() + |
| 374 | push_promise_frame_length + |
| 375 | frame.headers.length()); |
| 376 | |
| 377 | // Write Push Promise frame header and push id. |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 378 | QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id() |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 379 | << " is writing Push Promise frame header of length " |
| 380 | << push_promise_frame_length << " , with promised id " |
| 381 | << frame.push_id; |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 382 | WriteOrBufferData(quiche::QuicheStringPiece(push_promise_frame_with_id.get(), |
| 383 | push_promise_frame_length), |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 384 | /* fin = */ false, /* ack_listener = */ nullptr); |
| 385 | |
| 386 | // Write response headers. |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 387 | QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id() |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 388 | << " is writing Push Promise request header of length " |
| 389 | << frame.headers.length(); |
| 390 | WriteOrBufferData(frame.headers, /* fin = */ false, |
| 391 | /* ack_listener = */ nullptr); |
| 392 | } |
| 393 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 394 | QuicConsumedData QuicSpdyStream::WritevBody(const struct iovec* iov, |
| 395 | int count, |
| 396 | bool fin) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 397 | QuicMemSliceStorage storage( |
| 398 | iov, count, |
| 399 | session()->connection()->helper()->GetStreamSendBufferAllocator(), |
| 400 | GetQuicFlag(FLAGS_quic_send_buffer_max_data_slice_size)); |
| 401 | return WriteBodySlices(storage.ToSpan(), fin); |
| 402 | } |
| 403 | |
| 404 | QuicConsumedData QuicSpdyStream::WriteBodySlices(QuicMemSliceSpan slices, |
| 405 | bool fin) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 406 | if (!VersionUsesHttp3(transport_version()) || slices.empty()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 407 | return WriteMemSlices(slices, fin); |
| 408 | } |
| 409 | |
| 410 | std::unique_ptr<char[]> buffer; |
| 411 | QuicByteCount header_length = |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 412 | HttpEncoder::SerializeDataFrameHeader(slices.total_length(), &buffer); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 413 | if (!CanWriteNewDataAfterData(header_length)) { |
| 414 | return {0, false}; |
| 415 | } |
| 416 | |
bnc | b9d5e79 | 2020-03-20 17:43:41 -0700 | [diff] [blame] | 417 | if (spdy_session_->debug_visitor()) { |
| 418 | spdy_session_->debug_visitor()->OnDataFrameSent(id(), |
| 419 | slices.total_length()); |
| 420 | } |
| 421 | |
fayang | a4b37b2 | 2019-06-18 13:37:47 -0700 | [diff] [blame] | 422 | QuicConnection::ScopedPacketFlusher flusher(spdy_session_->connection()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 423 | |
| 424 | // Write frame header. |
| 425 | struct iovec header_iov = {static_cast<void*>(buffer.get()), header_length}; |
| 426 | QuicMemSliceStorage storage( |
| 427 | &header_iov, 1, |
| 428 | spdy_session_->connection()->helper()->GetStreamSendBufferAllocator(), |
| 429 | GetQuicFlag(FLAGS_quic_send_buffer_max_data_slice_size)); |
| 430 | unacked_frame_headers_offsets_.Add( |
| 431 | send_buffer().stream_offset(), |
| 432 | send_buffer().stream_offset() + header_length); |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 433 | QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id() |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 434 | << " is writing DATA frame header of length " |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 435 | << header_length; |
| 436 | WriteMemSlices(storage.ToSpan(), false); |
| 437 | |
| 438 | // Write body. |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 439 | QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id() |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 440 | << " is writing DATA frame payload of length " |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 441 | << slices.total_length(); |
| 442 | return WriteMemSlices(slices, fin); |
| 443 | } |
| 444 | |
| 445 | size_t QuicSpdyStream::Readv(const struct iovec* iov, size_t iov_len) { |
| 446 | DCHECK(FinishedReadingHeaders()); |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 447 | if (!VersionUsesHttp3(transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 448 | return sequencer()->Readv(iov, iov_len); |
| 449 | } |
bnc | c901949 | 2019-07-23 06:44:39 -0700 | [diff] [blame] | 450 | size_t bytes_read = 0; |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 451 | sequencer()->MarkConsumed(body_manager_.ReadBody(iov, iov_len, &bytes_read)); |
bnc | 8d04130 | 2019-06-10 10:19:04 -0700 | [diff] [blame] | 452 | |
renjietang | bd1a039 | 2019-05-31 11:36:24 -0700 | [diff] [blame] | 453 | return bytes_read; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | int QuicSpdyStream::GetReadableRegions(iovec* iov, size_t iov_len) const { |
| 457 | DCHECK(FinishedReadingHeaders()); |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 458 | if (!VersionUsesHttp3(transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 459 | return sequencer()->GetReadableRegions(iov, iov_len); |
| 460 | } |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 461 | return body_manager_.PeekBody(iov, iov_len); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | void QuicSpdyStream::MarkConsumed(size_t num_bytes) { |
| 465 | DCHECK(FinishedReadingHeaders()); |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 466 | if (!VersionUsesHttp3(transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 467 | sequencer()->MarkConsumed(num_bytes); |
| 468 | return; |
| 469 | } |
bnc | 8d04130 | 2019-06-10 10:19:04 -0700 | [diff] [blame] | 470 | |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 471 | sequencer()->MarkConsumed(body_manager_.OnBodyConsumed(num_bytes)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | bool QuicSpdyStream::IsDoneReading() const { |
| 475 | bool done_reading_headers = FinishedReadingHeaders(); |
| 476 | bool done_reading_body = sequencer()->IsClosed(); |
| 477 | bool done_reading_trailers = FinishedReadingTrailers(); |
| 478 | return done_reading_headers && done_reading_body && done_reading_trailers; |
| 479 | } |
| 480 | |
| 481 | bool QuicSpdyStream::HasBytesToRead() const { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 482 | if (!VersionUsesHttp3(transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 483 | return sequencer()->HasBytesToRead(); |
| 484 | } |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 485 | return body_manager_.HasBytesToRead(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | void QuicSpdyStream::MarkTrailersConsumed() { |
| 489 | trailers_consumed_ = true; |
| 490 | } |
| 491 | |
| 492 | uint64_t QuicSpdyStream::total_body_bytes_read() const { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 493 | if (VersionUsesHttp3(transport_version())) { |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 494 | return body_manager_.total_body_bytes_received(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 495 | } |
| 496 | return sequencer()->NumBytesConsumed(); |
| 497 | } |
| 498 | |
| 499 | void QuicSpdyStream::ConsumeHeaderList() { |
| 500 | header_list_.Clear(); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 501 | |
bnc | 8d04130 | 2019-06-10 10:19:04 -0700 | [diff] [blame] | 502 | if (!FinishedReadingHeaders()) { |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 503 | return; |
| 504 | } |
| 505 | |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 506 | if (!VersionUsesHttp3(transport_version())) { |
bnc | 8d04130 | 2019-06-10 10:19:04 -0700 | [diff] [blame] | 507 | sequencer()->SetUnblocked(); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 508 | return; |
| 509 | } |
| 510 | |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 511 | if (body_manager_.HasBytesToRead()) { |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 512 | OnBodyAvailable(); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | if (sequencer()->IsClosed() && |
| 517 | !on_body_available_called_because_sequencer_is_closed_) { |
| 518 | on_body_available_called_because_sequencer_is_closed_ = true; |
| 519 | OnBodyAvailable(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 520 | } |
| 521 | } |
| 522 | |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 523 | void QuicSpdyStream::OnStreamHeadersPriority( |
| 524 | const spdy::SpdyStreamPrecedence& precedence) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 525 | DCHECK_EQ(Perspective::IS_SERVER, session()->connection()->perspective()); |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 526 | SetPriority(precedence); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 527 | } |
| 528 | |
bnc | 6270680 | 2019-06-26 12:37:46 -0700 | [diff] [blame] | 529 | void QuicSpdyStream::OnStreamHeaderList(bool fin, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 530 | size_t frame_len, |
| 531 | const QuicHeaderList& header_list) { |
wub | 13ebfa6 | 2020-08-10 07:48:24 -0700 | [diff] [blame] | 532 | if (!spdy_session()->user_agent_id().has_value()) { |
| 533 | std::string uaid; |
| 534 | for (const auto& kv : header_list) { |
| 535 | if (quiche::QuicheTextUtils::ToLower(kv.first) == kUserAgentHeaderName) { |
| 536 | uaid = kv.second; |
| 537 | break; |
wub | be634b7 | 2020-06-16 08:41:26 -0700 | [diff] [blame] | 538 | } |
wub | be634b7 | 2020-06-16 08:41:26 -0700 | [diff] [blame] | 539 | } |
wub | 13ebfa6 | 2020-08-10 07:48:24 -0700 | [diff] [blame] | 540 | spdy_session()->SetUserAgentId(std::move(uaid)); |
wub | be634b7 | 2020-06-16 08:41:26 -0700 | [diff] [blame] | 541 | } |
| 542 | |
bnc | 8d04130 | 2019-06-10 10:19:04 -0700 | [diff] [blame] | 543 | // TODO(b/134706391): remove |fin| argument. |
bnc | 446887e | 2019-11-27 13:08:28 -0800 | [diff] [blame] | 544 | // When using Google QUIC, an empty header list indicates that the size limit |
| 545 | // has been exceeded. |
| 546 | // When using IETF QUIC, there is an explicit signal from |
| 547 | // QpackDecodedHeadersAccumulator. |
| 548 | if ((VersionUsesHttp3(transport_version()) && |
| 549 | header_list_size_limit_exceeded_) || |
| 550 | (!VersionUsesHttp3(transport_version()) && header_list.empty())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 551 | OnHeadersTooLarge(); |
| 552 | if (IsDoneReading()) { |
bnc | 6270680 | 2019-06-26 12:37:46 -0700 | [diff] [blame] | 553 | return; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | if (!headers_decompressed_) { |
| 557 | OnInitialHeadersComplete(fin, frame_len, header_list); |
| 558 | } else { |
| 559 | OnTrailingHeadersComplete(fin, frame_len, header_list); |
| 560 | } |
| 561 | } |
| 562 | |
bnc | b7ac104 | 2019-12-06 10:32:23 -0800 | [diff] [blame] | 563 | void QuicSpdyStream::OnHeadersDecoded(QuicHeaderList headers, |
| 564 | bool header_list_size_limit_exceeded) { |
| 565 | header_list_size_limit_exceeded_ = header_list_size_limit_exceeded; |
bnc | 232ff9b | 2019-11-13 18:38:22 -0800 | [diff] [blame] | 566 | qpack_decoded_headers_accumulator_.reset(); |
| 567 | |
| 568 | QuicSpdySession::LogHeaderCompressionRatioHistogram( |
| 569 | /* using_qpack = */ true, |
| 570 | /* is_sent = */ false, headers.compressed_header_bytes(), |
| 571 | headers.uncompressed_header_bytes()); |
| 572 | |
bnc | b9d5e79 | 2020-03-20 17:43:41 -0700 | [diff] [blame] | 573 | const QuicStreamId promised_stream_id = spdy_session()->promised_stream_id(); |
| 574 | Http3DebugVisitor* const debug_visitor = spdy_session()->debug_visitor(); |
| 575 | if (promised_stream_id == |
| 576 | QuicUtils::GetInvalidStreamId(transport_version())) { |
| 577 | if (debug_visitor) { |
| 578 | debug_visitor->OnHeadersDecoded(id(), headers); |
| 579 | } |
| 580 | |
bnc | 7ffadb8 | 2020-04-07 10:01:30 -0700 | [diff] [blame] | 581 | OnStreamHeaderList(/* fin = */ false, headers_payload_length_, headers); |
bnc | 232ff9b | 2019-11-13 18:38:22 -0800 | [diff] [blame] | 582 | } else { |
bnc | b9d5e79 | 2020-03-20 17:43:41 -0700 | [diff] [blame] | 583 | if (debug_visitor) { |
| 584 | debug_visitor->OnPushPromiseDecoded(id(), promised_stream_id, headers); |
| 585 | } |
| 586 | |
bnc | 232ff9b | 2019-11-13 18:38:22 -0800 | [diff] [blame] | 587 | spdy_session_->OnHeaderList(headers); |
| 588 | } |
| 589 | |
| 590 | if (blocked_on_decoding_headers_) { |
| 591 | blocked_on_decoding_headers_ = false; |
| 592 | // Continue decoding HTTP/3 frames. |
| 593 | OnDataAvailable(); |
| 594 | } |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 595 | } |
| 596 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 597 | void QuicSpdyStream::OnHeaderDecodingError( |
| 598 | quiche::QuicheStringPiece error_message) { |
bnc | 232ff9b | 2019-11-13 18:38:22 -0800 | [diff] [blame] | 599 | qpack_decoded_headers_accumulator_.reset(); |
| 600 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 601 | std::string connection_close_error_message = quiche::QuicheStrCat( |
bnc | 232ff9b | 2019-11-13 18:38:22 -0800 | [diff] [blame] | 602 | "Error decoding ", headers_decompressed_ ? "trailers" : "headers", |
| 603 | " on stream ", id(), ": ", error_message); |
renjietang | 87df0d0 | 2020-02-13 11:53:52 -0800 | [diff] [blame] | 604 | OnUnrecoverableError(QUIC_QPACK_DECOMPRESSION_FAILED, |
| 605 | connection_close_error_message); |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 606 | } |
| 607 | |
bnc | 80abd36 | 2020-01-30 10:46:30 -0800 | [diff] [blame] | 608 | void QuicSpdyStream::MaybeSendPriorityUpdateFrame() { |
| 609 | if (!VersionUsesHttp3(transport_version()) || |
| 610 | session()->perspective() != Perspective::IS_CLIENT) { |
| 611 | return; |
| 612 | } |
| 613 | |
| 614 | // Value between 0 and 7, inclusive. Lower value means higher priority. |
| 615 | int urgency = precedence().spdy3_priority(); |
bnc | b8abf38 | 2020-01-30 11:26:12 -0800 | [diff] [blame] | 616 | if (last_sent_urgency_ == urgency) { |
| 617 | return; |
| 618 | } |
| 619 | last_sent_urgency_ = urgency; |
bnc | 80abd36 | 2020-01-30 10:46:30 -0800 | [diff] [blame] | 620 | |
| 621 | PriorityUpdateFrame priority_update; |
| 622 | priority_update.prioritized_element_type = REQUEST_STREAM; |
| 623 | priority_update.prioritized_element_id = id(); |
| 624 | priority_update.priority_field_value = quiche::QuicheStrCat("u=", urgency); |
| 625 | spdy_session_->WriteHttp3PriorityUpdate(priority_update); |
| 626 | } |
| 627 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 628 | void QuicSpdyStream::OnHeadersTooLarge() { |
bnc | 52ffb98 | 2020-05-01 11:31:28 -0700 | [diff] [blame] | 629 | Reset(QUIC_HEADERS_TOO_LARGE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | void QuicSpdyStream::OnInitialHeadersComplete( |
| 633 | bool fin, |
| 634 | size_t /*frame_len*/, |
| 635 | const QuicHeaderList& header_list) { |
bnc | 8d04130 | 2019-06-10 10:19:04 -0700 | [diff] [blame] | 636 | // TODO(b/134706391): remove |fin| argument. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 637 | headers_decompressed_ = true; |
| 638 | header_list_ = header_list; |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 639 | |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 640 | if (VersionUsesHttp3(transport_version())) { |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 641 | if (fin) { |
renjietang | 07b2e8d | 2020-08-10 15:18:24 -0700 | [diff] [blame] | 642 | OnStreamFrame(QuicStreamFrame(id(), /* fin = */ true, |
| 643 | highest_received_byte_offset(), |
| 644 | quiche::QuicheStringPiece())); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 645 | } |
| 646 | return; |
| 647 | } |
| 648 | |
bnc | 70f78fc | 2019-08-26 10:12:31 -0700 | [diff] [blame] | 649 | if (fin && !rst_sent()) { |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 650 | OnStreamFrame(QuicStreamFrame(id(), fin, /* offset = */ 0, |
| 651 | quiche::QuicheStringPiece())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 652 | } |
| 653 | if (FinishedReadingHeaders()) { |
| 654 | sequencer()->SetUnblocked(); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | void QuicSpdyStream::OnPromiseHeaderList( |
| 659 | QuicStreamId /* promised_id */, |
| 660 | size_t /* frame_len */, |
| 661 | const QuicHeaderList& /*header_list */) { |
| 662 | // To be overridden in QuicSpdyClientStream. Not supported on |
| 663 | // server side. |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 664 | stream_delegate()->OnStreamError(QUIC_INVALID_HEADERS_STREAM_DATA, |
| 665 | "Promise headers received by server"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | void QuicSpdyStream::OnTrailingHeadersComplete( |
| 669 | bool fin, |
| 670 | size_t /*frame_len*/, |
| 671 | const QuicHeaderList& header_list) { |
bnc | 8d04130 | 2019-06-10 10:19:04 -0700 | [diff] [blame] | 672 | // TODO(b/134706391): remove |fin| argument. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 673 | DCHECK(!trailers_decompressed_); |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 674 | if (!VersionUsesHttp3(transport_version()) && fin_received()) { |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 675 | QUIC_DLOG(INFO) << ENDPOINT |
| 676 | << "Received Trailers after FIN, on stream: " << id(); |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 677 | stream_delegate()->OnStreamError(QUIC_INVALID_HEADERS_STREAM_DATA, |
| 678 | "Trailers after fin"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 679 | return; |
| 680 | } |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 681 | |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 682 | if (!VersionUsesHttp3(transport_version()) && !fin) { |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 683 | QUIC_DLOG(INFO) << ENDPOINT |
| 684 | << "Trailers must have FIN set, on stream: " << id(); |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 685 | stream_delegate()->OnStreamError(QUIC_INVALID_HEADERS_STREAM_DATA, |
| 686 | "Fin missing from trailers"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 687 | return; |
| 688 | } |
| 689 | |
| 690 | size_t final_byte_offset = 0; |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 691 | const bool expect_final_byte_offset = !VersionUsesHttp3(transport_version()); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 692 | if (!SpdyUtils::CopyAndValidateTrailers(header_list, expect_final_byte_offset, |
bnc | 5231ee2 | 2019-04-15 19:02:13 -0700 | [diff] [blame] | 693 | &final_byte_offset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 694 | &received_trailers_)) { |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 695 | QUIC_DLOG(ERROR) << ENDPOINT << "Trailers for stream " << id() |
| 696 | << " are malformed."; |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 697 | stream_delegate()->OnStreamError(QUIC_INVALID_HEADERS_STREAM_DATA, |
| 698 | "Trailers are malformed"); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 699 | return; |
| 700 | } |
| 701 | trailers_decompressed_ = true; |
bnc | ab33c71 | 2019-06-28 15:42:15 -0700 | [diff] [blame] | 702 | if (fin) { |
renjietang | 07b2e8d | 2020-08-10 15:18:24 -0700 | [diff] [blame] | 703 | const QuicStreamOffset offset = VersionUsesHttp3(transport_version()) |
| 704 | ? highest_received_byte_offset() |
| 705 | : final_byte_offset; |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 706 | OnStreamFrame( |
| 707 | QuicStreamFrame(id(), fin, offset, quiche::QuicheStringPiece())); |
bnc | ab33c71 | 2019-06-28 15:42:15 -0700 | [diff] [blame] | 708 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 709 | } |
| 710 | |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 711 | void QuicSpdyStream::OnPriorityFrame( |
| 712 | const spdy::SpdyStreamPrecedence& precedence) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 713 | DCHECK_EQ(Perspective::IS_SERVER, session()->connection()->perspective()); |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 714 | SetPriority(precedence); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | void QuicSpdyStream::OnStreamReset(const QuicRstStreamFrame& frame) { |
| 718 | if (frame.error_code != QUIC_STREAM_NO_ERROR) { |
bnc | 84aa7e5 | 2019-12-13 05:25:21 -0800 | [diff] [blame] | 719 | if (VersionUsesHttp3(transport_version()) && !fin_received() && |
| 720 | spdy_session_->qpack_decoder()) { |
| 721 | spdy_session_->qpack_decoder()->OnStreamReset(id()); |
| 722 | } |
bnc | 6f18a82 | 2019-11-27 17:50:38 -0800 | [diff] [blame] | 723 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 724 | QuicStream::OnStreamReset(frame); |
| 725 | return; |
| 726 | } |
bnc | 6f18a82 | 2019-11-27 17:50:38 -0800 | [diff] [blame] | 727 | |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 728 | QUIC_DVLOG(1) << ENDPOINT |
| 729 | << "Received QUIC_STREAM_NO_ERROR, not discarding response"; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 730 | set_rst_received(true); |
| 731 | MaybeIncreaseHighestReceivedOffset(frame.byte_offset); |
| 732 | set_stream_error(frame.error_code); |
| 733 | CloseWriteSide(); |
| 734 | } |
| 735 | |
bnc | 6f18a82 | 2019-11-27 17:50:38 -0800 | [diff] [blame] | 736 | void QuicSpdyStream::Reset(QuicRstStreamErrorCode error) { |
bnc | 84aa7e5 | 2019-12-13 05:25:21 -0800 | [diff] [blame] | 737 | if (VersionUsesHttp3(transport_version()) && !fin_received() && |
| 738 | spdy_session_->qpack_decoder()) { |
| 739 | spdy_session_->qpack_decoder()->OnStreamReset(id()); |
| 740 | } |
bnc | 6f18a82 | 2019-11-27 17:50:38 -0800 | [diff] [blame] | 741 | |
| 742 | QuicStream::Reset(error); |
| 743 | } |
| 744 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 745 | void QuicSpdyStream::OnDataAvailable() { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 746 | if (!VersionUsesHttp3(transport_version())) { |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 747 | // Sequencer must be blocked until headers are consumed. |
| 748 | DCHECK(FinishedReadingHeaders()); |
| 749 | } |
bnc | fa0c90c | 2019-03-13 14:14:28 -0700 | [diff] [blame] | 750 | |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 751 | if (!VersionUsesHttp3(transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 752 | OnBodyAvailable(); |
| 753 | return; |
| 754 | } |
| 755 | |
bnc | 8aadca7 | 2019-06-28 11:09:39 -0700 | [diff] [blame] | 756 | if (is_decoder_processing_input_) { |
| 757 | // Let the outermost nested OnDataAvailable() call do the work. |
| 758 | return; |
| 759 | } |
| 760 | |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 761 | if (blocked_on_decoding_headers_) { |
| 762 | return; |
| 763 | } |
| 764 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 765 | iovec iov; |
bnc | ef51815 | 2019-07-18 05:36:44 -0700 | [diff] [blame] | 766 | while (session()->connection()->connected() && !reading_stopped() && |
| 767 | decoder_.error() == QUIC_NO_ERROR) { |
bnc | 8aadca7 | 2019-06-28 11:09:39 -0700 | [diff] [blame] | 768 | DCHECK_GE(sequencer_offset_, sequencer()->NumBytesConsumed()); |
| 769 | if (!sequencer()->PeekRegion(sequencer_offset_, &iov)) { |
| 770 | break; |
| 771 | } |
| 772 | |
bnc | d48a92e | 2019-06-18 19:24:58 -0700 | [diff] [blame] | 773 | DCHECK(!sequencer()->IsClosed()); |
bnc | 8aadca7 | 2019-06-28 11:09:39 -0700 | [diff] [blame] | 774 | is_decoder_processing_input_ = true; |
| 775 | QuicByteCount processed_bytes = decoder_.ProcessInput( |
| 776 | reinterpret_cast<const char*>(iov.iov_base), iov.iov_len); |
| 777 | is_decoder_processing_input_ = false; |
| 778 | sequencer_offset_ += processed_bytes; |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 779 | if (blocked_on_decoding_headers_) { |
| 780 | return; |
| 781 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 782 | } |
| 783 | |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 784 | // Do not call OnBodyAvailable() until headers are consumed. |
| 785 | if (!FinishedReadingHeaders()) { |
| 786 | return; |
| 787 | } |
| 788 | |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 789 | if (body_manager_.HasBytesToRead()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 790 | OnBodyAvailable(); |
| 791 | return; |
| 792 | } |
| 793 | |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 794 | if (sequencer()->IsClosed() && |
| 795 | !on_body_available_called_because_sequencer_is_closed_) { |
| 796 | on_body_available_called_because_sequencer_is_closed_ = true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 797 | OnBodyAvailable(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 798 | } |
| 799 | } |
| 800 | |
| 801 | void QuicSpdyStream::OnClose() { |
| 802 | QuicStream::OnClose(); |
| 803 | |
| 804 | if (visitor_) { |
| 805 | Visitor* visitor = visitor_; |
| 806 | // Calling Visitor::OnClose() may result the destruction of the visitor, |
| 807 | // so we need to ensure we don't call it again. |
| 808 | visitor_ = nullptr; |
| 809 | visitor->OnClose(this); |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | void QuicSpdyStream::OnCanWrite() { |
| 814 | QuicStream::OnCanWrite(); |
| 815 | |
| 816 | // Trailers (and hence a FIN) may have been sent ahead of queued body bytes. |
| 817 | if (!HasBufferedData() && fin_sent()) { |
| 818 | CloseWriteSide(); |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | bool QuicSpdyStream::FinishedReadingHeaders() const { |
| 823 | return headers_decompressed_ && header_list_.empty(); |
| 824 | } |
| 825 | |
bnc | d011990 | 2019-06-26 12:12:33 -0700 | [diff] [blame] | 826 | // static |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 827 | bool QuicSpdyStream::ParseHeaderStatusCode(const SpdyHeaderBlock& header, |
bnc | d011990 | 2019-06-26 12:12:33 -0700 | [diff] [blame] | 828 | int* status_code) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 829 | SpdyHeaderBlock::const_iterator it = header.find(spdy::kHttp2StatusHeader); |
| 830 | if (it == header.end()) { |
| 831 | return false; |
| 832 | } |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 833 | const quiche::QuicheStringPiece status(it->second); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 834 | if (status.size() != 3) { |
| 835 | return false; |
| 836 | } |
| 837 | // First character must be an integer in range [1,5]. |
| 838 | if (status[0] < '1' || status[0] > '5') { |
| 839 | return false; |
| 840 | } |
| 841 | // The remaining two characters must be integers. |
| 842 | if (!isdigit(status[1]) || !isdigit(status[2])) { |
| 843 | return false; |
| 844 | } |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 845 | return quiche::QuicheTextUtils::StringToInt(status, status_code); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | bool QuicSpdyStream::FinishedReadingTrailers() const { |
| 849 | // If no further trailing headers are expected, and the decompressed trailers |
| 850 | // (if any) have been consumed, then reading of trailers is finished. |
| 851 | if (!fin_received()) { |
| 852 | return false; |
| 853 | } else if (!trailers_decompressed_) { |
| 854 | return true; |
| 855 | } else { |
| 856 | return trailers_consumed_; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | void QuicSpdyStream::ClearSession() { |
| 861 | spdy_session_ = nullptr; |
| 862 | } |
| 863 | |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 864 | bool QuicSpdyStream::OnDataFrameStart(QuicByteCount header_length, |
bnc | 6ab8c79 | 2020-03-27 16:15:03 -0700 | [diff] [blame] | 865 | QuicByteCount payload_length) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 866 | DCHECK(VersionUsesHttp3(transport_version())); |
bnc | 6ab8c79 | 2020-03-27 16:15:03 -0700 | [diff] [blame] | 867 | |
| 868 | if (spdy_session_->debug_visitor()) { |
| 869 | spdy_session_->debug_visitor()->OnDataFrameReceived(id(), payload_length); |
| 870 | } |
| 871 | |
bnc | 519216c | 2019-07-09 05:03:48 -0700 | [diff] [blame] | 872 | if (!headers_decompressed_ || trailers_decompressed_) { |
bnc | 3e8fe7c | 2020-03-10 17:44:58 -0700 | [diff] [blame] | 873 | stream_delegate()->OnStreamError( |
| 874 | QUIC_HTTP_INVALID_FRAME_SEQUENCE_ON_SPDY_STREAM, |
| 875 | "Unexpected DATA frame received."); |
bnc | 519216c | 2019-07-09 05:03:48 -0700 | [diff] [blame] | 876 | return false; |
| 877 | } |
| 878 | |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 879 | sequencer()->MarkConsumed(body_manager_.OnNonBody(header_length)); |
bnc | e5f9c03 | 2019-07-25 11:30:40 -0700 | [diff] [blame] | 880 | |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 881 | return true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 882 | } |
| 883 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 884 | bool QuicSpdyStream::OnDataFramePayload(quiche::QuicheStringPiece payload) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 885 | DCHECK(VersionUsesHttp3(transport_version())); |
bnc | fa0c90c | 2019-03-13 14:14:28 -0700 | [diff] [blame] | 886 | |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 887 | body_manager_.OnBody(payload); |
bnc | e5f9c03 | 2019-07-25 11:30:40 -0700 | [diff] [blame] | 888 | |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 889 | return true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 890 | } |
| 891 | |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 892 | bool QuicSpdyStream::OnDataFrameEnd() { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 893 | DCHECK(VersionUsesHttp3(transport_version())); |
bnc | b9d5e79 | 2020-03-20 17:43:41 -0700 | [diff] [blame] | 894 | |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 895 | QUIC_DVLOG(1) << ENDPOINT |
| 896 | << "Reaches the end of a data frame. Total bytes received are " |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 897 | << body_manager_.total_body_bytes_received(); |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 898 | return true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | bool QuicSpdyStream::OnStreamFrameAcked(QuicStreamOffset offset, |
| 902 | QuicByteCount data_length, |
| 903 | bool fin_acked, |
| 904 | QuicTime::Delta ack_delay_time, |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 905 | QuicTime receive_timestamp, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 906 | QuicByteCount* newly_acked_length) { |
| 907 | const bool new_data_acked = QuicStream::OnStreamFrameAcked( |
QUICHE team | 2f5f30b | 2020-02-18 08:52:28 -0800 | [diff] [blame] | 908 | offset, data_length, fin_acked, ack_delay_time, receive_timestamp, |
| 909 | newly_acked_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 910 | |
| 911 | const QuicByteCount newly_acked_header_length = |
| 912 | GetNumFrameHeadersInInterval(offset, data_length); |
| 913 | DCHECK_LE(newly_acked_header_length, *newly_acked_length); |
| 914 | unacked_frame_headers_offsets_.Difference(offset, offset + data_length); |
| 915 | if (ack_listener_ != nullptr && new_data_acked) { |
wub | 2146ce8 | 2020-07-30 13:17:52 -0700 | [diff] [blame] | 916 | ack_listener_->OnPacketAcked( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 917 | *newly_acked_length - newly_acked_header_length, ack_delay_time); |
| 918 | } |
| 919 | return new_data_acked; |
| 920 | } |
| 921 | |
| 922 | void QuicSpdyStream::OnStreamFrameRetransmitted(QuicStreamOffset offset, |
| 923 | QuicByteCount data_length, |
| 924 | bool fin_retransmitted) { |
| 925 | QuicStream::OnStreamFrameRetransmitted(offset, data_length, |
| 926 | fin_retransmitted); |
| 927 | |
| 928 | const QuicByteCount retransmitted_header_length = |
| 929 | GetNumFrameHeadersInInterval(offset, data_length); |
| 930 | DCHECK_LE(retransmitted_header_length, data_length); |
| 931 | |
| 932 | if (ack_listener_ != nullptr) { |
| 933 | ack_listener_->OnPacketRetransmitted(data_length - |
| 934 | retransmitted_header_length); |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | QuicByteCount QuicSpdyStream::GetNumFrameHeadersInInterval( |
| 939 | QuicStreamOffset offset, |
| 940 | QuicByteCount data_length) const { |
| 941 | QuicByteCount header_acked_length = 0; |
| 942 | QuicIntervalSet<QuicStreamOffset> newly_acked(offset, offset + data_length); |
| 943 | newly_acked.Intersection(unacked_frame_headers_offsets_); |
| 944 | for (const auto& interval : newly_acked) { |
| 945 | header_acked_length += interval.Length(); |
| 946 | } |
| 947 | return header_acked_length; |
| 948 | } |
| 949 | |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 950 | bool QuicSpdyStream::OnHeadersFrameStart(QuicByteCount header_length, |
bnc | 6ab8c79 | 2020-03-27 16:15:03 -0700 | [diff] [blame] | 951 | QuicByteCount payload_length) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 952 | DCHECK(VersionUsesHttp3(transport_version())); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 953 | DCHECK(!qpack_decoded_headers_accumulator_); |
| 954 | |
bnc | 6ab8c79 | 2020-03-27 16:15:03 -0700 | [diff] [blame] | 955 | if (spdy_session_->debug_visitor()) { |
| 956 | spdy_session_->debug_visitor()->OnHeadersFrameReceived(id(), |
| 957 | payload_length); |
| 958 | } |
| 959 | |
bnc | 7ffadb8 | 2020-04-07 10:01:30 -0700 | [diff] [blame] | 960 | headers_payload_length_ = payload_length; |
| 961 | |
bnc | 519216c | 2019-07-09 05:03:48 -0700 | [diff] [blame] | 962 | if (trailers_decompressed_) { |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 963 | stream_delegate()->OnStreamError( |
bnc | 3e8fe7c | 2020-03-10 17:44:58 -0700 | [diff] [blame] | 964 | QUIC_HTTP_INVALID_FRAME_SEQUENCE_ON_SPDY_STREAM, |
renjietang | f196f6a | 2020-02-12 12:34:23 -0800 | [diff] [blame] | 965 | "HEADERS frame received after trailing HEADERS."); |
bnc | 519216c | 2019-07-09 05:03:48 -0700 | [diff] [blame] | 966 | return false; |
| 967 | } |
| 968 | |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 969 | sequencer()->MarkConsumed(body_manager_.OnNonBody(header_length)); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 970 | |
| 971 | qpack_decoded_headers_accumulator_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 972 | std::make_unique<QpackDecodedHeadersAccumulator>( |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 973 | id(), spdy_session_->qpack_decoder(), this, |
bnc | bdd303e | 2019-07-09 05:33:17 -0700 | [diff] [blame] | 974 | spdy_session_->max_inbound_header_list_size()); |
bnc | 8d04130 | 2019-06-10 10:19:04 -0700 | [diff] [blame] | 975 | |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 976 | return true; |
bnc | 62446bc | 2019-03-14 06:11:25 -0700 | [diff] [blame] | 977 | } |
| 978 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 979 | bool QuicSpdyStream::OnHeadersFramePayload(quiche::QuicheStringPiece payload) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 980 | DCHECK(VersionUsesHttp3(transport_version())); |
bnc | fcd4235 | 2019-09-20 17:55:47 -0700 | [diff] [blame] | 981 | DCHECK(qpack_decoded_headers_accumulator_); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 982 | |
bnc | 232ff9b | 2019-11-13 18:38:22 -0800 | [diff] [blame] | 983 | qpack_decoded_headers_accumulator_->Decode(payload); |
bnc | 8d04130 | 2019-06-10 10:19:04 -0700 | [diff] [blame] | 984 | |
bnc | 232ff9b | 2019-11-13 18:38:22 -0800 | [diff] [blame] | 985 | // |qpack_decoded_headers_accumulator_| is reset if an error is detected. |
bnc | f9ff46b | 2019-11-26 10:32:09 -0800 | [diff] [blame] | 986 | if (!qpack_decoded_headers_accumulator_) { |
| 987 | return false; |
| 988 | } |
| 989 | |
| 990 | sequencer()->MarkConsumed(body_manager_.OnNonBody(payload.size())); |
| 991 | return true; |
bnc | 62446bc | 2019-03-14 06:11:25 -0700 | [diff] [blame] | 992 | } |
| 993 | |
renjietang | 546a628 | 2019-06-03 10:21:21 -0700 | [diff] [blame] | 994 | bool QuicSpdyStream::OnHeadersFrameEnd() { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 995 | DCHECK(VersionUsesHttp3(transport_version())); |
bnc | fcd4235 | 2019-09-20 17:55:47 -0700 | [diff] [blame] | 996 | DCHECK(qpack_decoded_headers_accumulator_); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 997 | |
bnc | 232ff9b | 2019-11-13 18:38:22 -0800 | [diff] [blame] | 998 | qpack_decoded_headers_accumulator_->EndHeaderBlock(); |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 999 | |
bnc | 232ff9b | 2019-11-13 18:38:22 -0800 | [diff] [blame] | 1000 | // If decoding is complete or an error is detected, then |
| 1001 | // |qpack_decoded_headers_accumulator_| is already reset. |
| 1002 | if (qpack_decoded_headers_accumulator_) { |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 1003 | blocked_on_decoding_headers_ = true; |
| 1004 | return false; |
| 1005 | } |
| 1006 | |
bnc | c057c01 | 2019-07-02 11:13:22 -0700 | [diff] [blame] | 1007 | return !sequencer()->IsClosed() && !reading_stopped(); |
| 1008 | } |
| 1009 | |
bnc | f0db654 | 2019-09-23 11:18:28 -0700 | [diff] [blame] | 1010 | bool QuicSpdyStream::OnPushPromiseFrameStart(QuicByteCount header_length) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 1011 | DCHECK(VersionUsesHttp3(transport_version())); |
bnc | f0db654 | 2019-09-23 11:18:28 -0700 | [diff] [blame] | 1012 | DCHECK(!qpack_decoded_headers_accumulator_); |
| 1013 | |
| 1014 | sequencer()->MarkConsumed(body_manager_.OnNonBody(header_length)); |
| 1015 | |
| 1016 | return true; |
| 1017 | } |
| 1018 | |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 1019 | bool QuicSpdyStream::OnPushPromiseFramePushId( |
| 1020 | PushId push_id, |
| 1021 | QuicByteCount push_id_length, |
bnc | 6ab8c79 | 2020-03-27 16:15:03 -0700 | [diff] [blame] | 1022 | QuicByteCount header_block_length) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 1023 | DCHECK(VersionUsesHttp3(transport_version())); |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 1024 | DCHECK(!qpack_decoded_headers_accumulator_); |
| 1025 | |
bnc | 6ab8c79 | 2020-03-27 16:15:03 -0700 | [diff] [blame] | 1026 | if (spdy_session_->debug_visitor()) { |
| 1027 | spdy_session_->debug_visitor()->OnPushPromiseFrameReceived( |
| 1028 | id(), push_id, header_block_length); |
| 1029 | } |
| 1030 | |
bnc | 7ffadb8 | 2020-04-07 10:01:30 -0700 | [diff] [blame] | 1031 | // TODO(b/151749109): Check max push id and handle errors. |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 1032 | spdy_session_->OnPushPromise(id(), push_id); |
bnc | f0db654 | 2019-09-23 11:18:28 -0700 | [diff] [blame] | 1033 | sequencer()->MarkConsumed(body_manager_.OnNonBody(push_id_length)); |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 1034 | |
| 1035 | qpack_decoded_headers_accumulator_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 1036 | std::make_unique<QpackDecodedHeadersAccumulator>( |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 1037 | id(), spdy_session_->qpack_decoder(), this, |
| 1038 | spdy_session_->max_inbound_header_list_size()); |
| 1039 | |
| 1040 | return true; |
| 1041 | } |
| 1042 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 1043 | bool QuicSpdyStream::OnPushPromiseFramePayload( |
| 1044 | quiche::QuicheStringPiece payload) { |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 1045 | spdy_session_->OnCompressedFrameSize(payload.length()); |
| 1046 | return OnHeadersFramePayload(payload); |
| 1047 | } |
| 1048 | |
| 1049 | bool QuicSpdyStream::OnPushPromiseFrameEnd() { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 1050 | DCHECK(VersionUsesHttp3(transport_version())); |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 1051 | |
renjietang | 6fbdaf4 | 2019-07-29 10:50:54 -0700 | [diff] [blame] | 1052 | return OnHeadersFrameEnd(); |
renjietang | 3c3dfb7 | 2019-07-26 11:55:52 -0700 | [diff] [blame] | 1053 | } |
| 1054 | |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 1055 | bool QuicSpdyStream::OnUnknownFrameStart(uint64_t frame_type, |
bnc | 32f36f9 | 2020-03-27 15:48:45 -0700 | [diff] [blame] | 1056 | QuicByteCount header_length, |
bnc | 6ab8c79 | 2020-03-27 16:15:03 -0700 | [diff] [blame] | 1057 | QuicByteCount payload_length) { |
bnc | b9d5e79 | 2020-03-20 17:43:41 -0700 | [diff] [blame] | 1058 | if (spdy_session_->debug_visitor()) { |
bnc | 6ab8c79 | 2020-03-27 16:15:03 -0700 | [diff] [blame] | 1059 | spdy_session_->debug_visitor()->OnUnknownFrameReceived(id(), frame_type, |
| 1060 | payload_length); |
bnc | b9d5e79 | 2020-03-20 17:43:41 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 1063 | // Ignore unknown frames, but consume frame header. |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 1064 | QUIC_DVLOG(1) << ENDPOINT << "Discarding " << header_length |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 1065 | << " byte long frame header of frame of unknown type " |
| 1066 | << frame_type << "."; |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 1067 | sequencer()->MarkConsumed(body_manager_.OnNonBody(header_length)); |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 1068 | return true; |
| 1069 | } |
| 1070 | |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 1071 | bool QuicSpdyStream::OnUnknownFramePayload(quiche::QuicheStringPiece payload) { |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 1072 | // Ignore unknown frames, but consume frame payload. |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 1073 | QUIC_DVLOG(1) << ENDPOINT << "Discarding " << payload.size() |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 1074 | << " bytes of payload of frame of unknown type."; |
bnc | 0b83e0c | 2019-08-16 15:56:32 -0700 | [diff] [blame] | 1075 | sequencer()->MarkConsumed(body_manager_.OnNonBody(payload.size())); |
bnc | 25827c4 | 2019-07-29 08:57:24 -0700 | [diff] [blame] | 1076 | return true; |
| 1077 | } |
| 1078 | |
| 1079 | bool QuicSpdyStream::OnUnknownFrameEnd() { |
| 1080 | return true; |
| 1081 | } |
| 1082 | |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1083 | size_t QuicSpdyStream::WriteHeadersImpl( |
| 1084 | spdy::SpdyHeaderBlock header_block, |
| 1085 | bool fin, |
| 1086 | QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
renjietang | a29a96a | 2019-10-10 12:47:50 -0700 | [diff] [blame] | 1087 | if (!VersionUsesHttp3(transport_version())) { |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1088 | return spdy_session_->WriteHeadersOnHeadersStream( |
fayang | 476683a | 2019-07-25 12:42:16 -0700 | [diff] [blame] | 1089 | id(), std::move(header_block), fin, precedence(), |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1090 | std::move(ack_listener)); |
| 1091 | } |
| 1092 | |
| 1093 | // Encode header list. |
bnc | 609c24e | 2019-09-10 05:24:32 -0700 | [diff] [blame] | 1094 | QuicByteCount encoder_stream_sent_byte_count; |
bnc | f21c1ad | 2019-06-20 20:09:50 -0700 | [diff] [blame] | 1095 | std::string encoded_headers = |
bnc | 609c24e | 2019-09-10 05:24:32 -0700 | [diff] [blame] | 1096 | spdy_session_->qpack_encoder()->EncodeHeaderList( |
| 1097 | id(), header_block, &encoder_stream_sent_byte_count); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1098 | |
bnc | b9d5e79 | 2020-03-20 17:43:41 -0700 | [diff] [blame] | 1099 | if (spdy_session_->debug_visitor()) { |
| 1100 | spdy_session_->debug_visitor()->OnHeadersFrameSent(id(), header_block); |
| 1101 | } |
| 1102 | |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1103 | // Write HEADERS frame. |
| 1104 | std::unique_ptr<char[]> headers_frame_header; |
| 1105 | const size_t headers_frame_header_length = |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 1106 | HttpEncoder::SerializeHeadersFrameHeader(encoded_headers.size(), |
| 1107 | &headers_frame_header); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1108 | unacked_frame_headers_offsets_.Add( |
| 1109 | send_buffer().stream_offset(), |
| 1110 | send_buffer().stream_offset() + headers_frame_header_length); |
| 1111 | |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 1112 | QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id() |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1113 | << " is writing HEADERS frame header of length " |
| 1114 | << headers_frame_header_length; |
dmcardle | ba2fb7e | 2019-12-13 07:44:34 -0800 | [diff] [blame] | 1115 | WriteOrBufferData(quiche::QuicheStringPiece(headers_frame_header.get(), |
| 1116 | headers_frame_header_length), |
| 1117 | /* fin = */ false, /* ack_listener = */ nullptr); |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1118 | |
dschinazi | 88bd5b0 | 2019-10-10 00:52:20 -0700 | [diff] [blame] | 1119 | QUIC_DLOG(INFO) << ENDPOINT << "Stream " << id() |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1120 | << " is writing HEADERS frame payload of length " |
renjietang | dbe9834 | 2019-10-18 11:00:57 -0700 | [diff] [blame] | 1121 | << encoded_headers.length() << " with fin " << fin; |
renjietang | 2abedac | 2019-05-20 14:04:50 -0700 | [diff] [blame] | 1122 | WriteOrBufferData(encoded_headers, fin, nullptr); |
| 1123 | |
bnc | 20a9ad9 | 2019-10-01 10:29:14 -0700 | [diff] [blame] | 1124 | QuicSpdySession::LogHeaderCompressionRatioHistogram( |
| 1125 | /* using_qpack = */ true, |
| 1126 | /* is_sent = */ true, |
| 1127 | encoded_headers.size() + encoder_stream_sent_byte_count, |
| 1128 | header_block.TotalBytesUsed()); |
| 1129 | |
bnc | 7a6f00f | 2020-04-27 13:10:18 -0700 | [diff] [blame] | 1130 | return encoded_headers.size(); |
bnc | 62446bc | 2019-03-14 06:11:25 -0700 | [diff] [blame] | 1131 | } |
| 1132 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1133 | #undef ENDPOINT // undef for jumbo builds |
| 1134 | } // namespace quic |