| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/quic/quic_spdy_stream.h" | 5 #include "net/quic/quic_spdy_stream.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 9 #include "net/quic/quic_bug_tracker.h" | 11 #include "net/quic/quic_bug_tracker.h" |
| 10 #include "net/quic/quic_spdy_session.h" | 12 #include "net/quic/quic_spdy_session.h" |
| 11 #include "net/quic/quic_utils.h" | 13 #include "net/quic/quic_utils.h" |
| 12 #include "net/quic/quic_write_blocked_list.h" | 14 #include "net/quic/quic_write_blocked_list.h" |
| 13 #include "net/quic/spdy_utils.h" | 15 #include "net/quic/spdy_utils.h" |
| 14 | 16 |
| 15 using base::StringPiece; | 17 using base::StringPiece; |
| 16 using net::SpdyPriority; | 18 using net::SpdyPriority; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 write_side_closed() && !rst_sent()) { | 63 write_side_closed() && !rst_sent()) { |
| 62 DCHECK(fin_sent()); | 64 DCHECK(fin_sent()); |
| 63 // Tell the peer to stop sending further data. | 65 // Tell the peer to stop sending further data. |
| 64 DVLOG(1) << ENDPOINT << "Send QUIC_STREAM_NO_ERROR on stream " << id(); | 66 DVLOG(1) << ENDPOINT << "Send QUIC_STREAM_NO_ERROR on stream " << id(); |
| 65 Reset(QUIC_STREAM_NO_ERROR); | 67 Reset(QUIC_STREAM_NO_ERROR); |
| 66 } | 68 } |
| 67 ReliableQuicStream::StopReading(); | 69 ReliableQuicStream::StopReading(); |
| 68 } | 70 } |
| 69 | 71 |
| 70 size_t QuicSpdyStream::WriteHeaders( | 72 size_t QuicSpdyStream::WriteHeaders( |
| 71 const SpdyHeaderBlock& header_block, | 73 SpdyHeaderBlock header_block, |
| 72 bool fin, | 74 bool fin, |
| 73 QuicAckListenerInterface* ack_notifier_delegate) { | 75 QuicAckListenerInterface* ack_notifier_delegate) { |
| 74 size_t bytes_written = spdy_session_->WriteHeaders( | 76 size_t bytes_written = spdy_session_->WriteHeaders( |
| 75 id(), header_block, fin, priority_, ack_notifier_delegate); | 77 id(), std::move(header_block), fin, priority_, ack_notifier_delegate); |
| 76 if (fin) { | 78 if (fin) { |
| 77 // TODO(rch): Add test to ensure fin_sent_ is set whenever a fin is sent. | 79 // TODO(rch): Add test to ensure fin_sent_ is set whenever a fin is sent. |
| 78 set_fin_sent(true); | 80 set_fin_sent(true); |
| 79 CloseWriteSide(); | 81 CloseWriteSide(); |
| 80 } | 82 } |
| 81 return bytes_written; | 83 return bytes_written; |
| 82 } | 84 } |
| 83 | 85 |
| 84 void QuicSpdyStream::WriteOrBufferBody( | 86 void QuicSpdyStream::WriteOrBufferBody( |
| 85 const string& data, | 87 const string& data, |
| 86 bool fin, | 88 bool fin, |
| 87 QuicAckListenerInterface* ack_notifier_delegate) { | 89 QuicAckListenerInterface* ack_notifier_delegate) { |
| 88 WriteOrBufferData(data, fin, ack_notifier_delegate); | 90 WriteOrBufferData(data, fin, ack_notifier_delegate); |
| 89 } | 91 } |
| 90 | 92 |
| 91 size_t QuicSpdyStream::WriteTrailers( | 93 size_t QuicSpdyStream::WriteTrailers( |
| 92 const SpdyHeaderBlock& trailer_block, | 94 SpdyHeaderBlock trailer_block, |
| 93 QuicAckListenerInterface* ack_notifier_delegate) { | 95 QuicAckListenerInterface* ack_notifier_delegate) { |
| 94 if (fin_sent()) { | 96 if (fin_sent()) { |
| 95 QUIC_BUG << "Trailers cannot be sent after a FIN."; | 97 QUIC_BUG << "Trailers cannot be sent after a FIN."; |
| 96 return 0; | 98 return 0; |
| 97 } | 99 } |
| 98 | 100 |
| 99 // The header block must contain the final offset for this stream, as the | 101 // The header block must contain the final offset for this stream, as the |
| 100 // trailers may be processed out of order at the peer. | 102 // trailers may be processed out of order at the peer. |
| 101 DVLOG(1) << "Inserting trailer: (" << kFinalOffsetHeaderKey << ", " | 103 DVLOG(1) << "Inserting trailer: (" << kFinalOffsetHeaderKey << ", " |
| 102 << stream_bytes_written() + queued_data_bytes() << ")"; | 104 << stream_bytes_written() + queued_data_bytes() << ")"; |
| 103 SpdyHeaderBlock trailer_block_with_offset(trailer_block); | 105 trailer_block.insert(std::make_pair( |
| 104 trailer_block_with_offset.insert(std::make_pair( | |
| 105 kFinalOffsetHeaderKey, | 106 kFinalOffsetHeaderKey, |
| 106 base::IntToString(stream_bytes_written() + queued_data_bytes()))); | 107 base::IntToString(stream_bytes_written() + queued_data_bytes()))); |
| 107 | 108 |
| 108 // Write the trailing headers with a FIN, and close stream for writing: | 109 // Write the trailing headers with a FIN, and close stream for writing: |
| 109 // trailers are the last thing to be sent on a stream. | 110 // trailers are the last thing to be sent on a stream. |
| 110 const bool kFin = true; | 111 const bool kFin = true; |
| 111 size_t bytes_written = spdy_session_->WriteHeaders( | 112 size_t bytes_written = spdy_session_->WriteHeaders( |
| 112 id(), trailer_block_with_offset, kFin, priority_, ack_notifier_delegate); | 113 id(), std::move(trailer_block), kFin, priority_, ack_notifier_delegate); |
| 113 set_fin_sent(kFin); | 114 set_fin_sent(kFin); |
| 114 | 115 |
| 115 // Trailers are the last thing to be sent on a stream, but if there is still | 116 // Trailers are the last thing to be sent on a stream, but if there is still |
| 116 // queued data then CloseWriteSide() will cause it never to be sent. | 117 // queued data then CloseWriteSide() will cause it never to be sent. |
| 117 if (queued_data_bytes() == 0) { | 118 if (queued_data_bytes() == 0) { |
| 118 CloseWriteSide(); | 119 CloseWriteSide(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 return bytes_written; | 122 return bytes_written; |
| 122 } | 123 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 273 } |
| 273 if (!fin) { | 274 if (!fin) { |
| 274 DLOG(ERROR) << "Trailers must have FIN set, on stream: " << id(); | 275 DLOG(ERROR) << "Trailers must have FIN set, on stream: " << id(); |
| 275 session()->connection()->CloseConnection( | 276 session()->connection()->CloseConnection( |
| 276 QUIC_INVALID_HEADERS_STREAM_DATA, "Fin missing from trailers", | 277 QUIC_INVALID_HEADERS_STREAM_DATA, "Fin missing from trailers", |
| 277 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 278 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 278 return; | 279 return; |
| 279 } | 280 } |
| 280 | 281 |
| 281 size_t final_byte_offset = 0; | 282 size_t final_byte_offset = 0; |
| 282 SpdyHeaderBlock trailers; | |
| 283 if (!SpdyUtils::ParseTrailers(decompressed_trailers().data(), | 283 if (!SpdyUtils::ParseTrailers(decompressed_trailers().data(), |
| 284 decompressed_trailers().length(), | 284 decompressed_trailers().length(), |
| 285 &final_byte_offset, &received_trailers_)) { | 285 &final_byte_offset, &received_trailers_)) { |
| 286 DLOG(ERROR) << "Trailers are malformed: " << id(); | 286 DLOG(ERROR) << "Trailers are malformed: " << id(); |
| 287 session()->connection()->CloseConnection( | 287 session()->connection()->CloseConnection( |
| 288 QUIC_INVALID_HEADERS_STREAM_DATA, "Trailers are malformed", | 288 QUIC_INVALID_HEADERS_STREAM_DATA, "Trailers are malformed", |
| 289 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 289 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 290 return; | 290 return; |
| 291 } | 291 } |
| 292 | 292 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 | 392 |
| 393 SpdyPriority QuicSpdyStream::priority() const { | 393 SpdyPriority QuicSpdyStream::priority() const { |
| 394 return priority_; | 394 return priority_; |
| 395 } | 395 } |
| 396 | 396 |
| 397 void QuicSpdyStream::ClearSession() { | 397 void QuicSpdyStream::ClearSession() { |
| 398 spdy_session_ = nullptr; | 398 spdy_session_ = nullptr; |
| 399 } | 399 } |
| 400 | 400 |
| 401 } // namespace net | 401 } // namespace net |
| OLD | NEW |