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 "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 | 8 |
9 #include "net/quic/quic_connection.h" | 9 #include "net/quic/quic_connection.h" |
10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 624 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
625 stream_->OnStreamHeaders(headers); | 625 stream_->OnStreamHeaders(headers); |
626 stream_->OnStreamHeadersComplete(false, headers.size()); | 626 stream_->OnStreamHeadersComplete(false, headers.size()); |
627 stream_->MarkHeadersConsumed(stream_->decompressed_headers().size()); | 627 stream_->MarkHeadersConsumed(stream_->decompressed_headers().size()); |
628 | 628 |
629 // Receive trailing headers. | 629 // Receive trailing headers. |
630 SpdyHeaderBlock trailers_block; | 630 SpdyHeaderBlock trailers_block; |
631 trailers_block["key1"] = "value1"; | 631 trailers_block["key1"] = "value1"; |
632 trailers_block["key2"] = "value2"; | 632 trailers_block["key2"] = "value2"; |
633 trailers_block["key3"] = "value3"; | 633 trailers_block["key3"] = "value3"; |
| 634 trailers_block[kFinalOffsetHeaderKey] = "0"; |
634 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); | 635 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); |
635 stream_->OnStreamHeaders(trailers); | 636 stream_->OnStreamHeaders(trailers); |
636 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); | 637 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); |
637 | 638 |
638 // The trailers should be decompressed, and readable from the stream. | 639 // The trailers should be decompressed, and readable from the stream. |
639 EXPECT_TRUE(stream_->trailers_decompressed()); | 640 EXPECT_TRUE(stream_->trailers_decompressed()); |
640 const string decompressed_trailers = stream_->decompressed_trailers(); | 641 const string decompressed_trailers = stream_->decompressed_trailers(); |
641 EXPECT_EQ(trailers, decompressed_trailers); | 642 EXPECT_EQ(trailers, decompressed_trailers); |
642 | 643 |
643 // Consuming the trailers erases them from the stream. | 644 // Consuming the trailers erases them from the stream. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
702 SpdyHeaderBlock trailers_block; | 703 SpdyHeaderBlock trailers_block; |
703 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); | 704 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); |
704 stream_->OnStreamHeaders(trailers); | 705 stream_->OnStreamHeaders(trailers); |
705 | 706 |
706 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( | 707 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
707 QUIC_INVALID_HEADERS_STREAM_DATA, _)) | 708 QUIC_INVALID_HEADERS_STREAM_DATA, _)) |
708 .Times(1); | 709 .Times(1); |
709 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); | 710 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); |
710 } | 711 } |
711 | 712 |
| 713 TEST_P(QuicSpdyStreamTest, ReceivingTrailersWithOffset) { |
| 714 // Test that when receiving trailing headers with an offset before response |
| 715 // body, stream is closed at the right offset. |
| 716 Initialize(kShouldProcessData); |
| 717 |
| 718 // Receive initial headers. |
| 719 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 720 stream_->OnStreamHeaders(headers); |
| 721 stream_->OnStreamHeadersComplete(false, headers.size()); |
| 722 stream_->MarkHeadersConsumed(stream_->decompressed_headers().size()); |
| 723 |
| 724 const string body = "this is the body"; |
| 725 // Receive trailing headers. |
| 726 SpdyHeaderBlock trailers_block; |
| 727 trailers_block["key1"] = "value1"; |
| 728 trailers_block["key2"] = "value2"; |
| 729 trailers_block["key3"] = "value3"; |
| 730 trailers_block[kFinalOffsetHeaderKey] = base::IntToString(body.size()); |
| 731 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); |
| 732 stream_->OnStreamHeaders(trailers); |
| 733 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); |
| 734 |
| 735 // The trailers should be decompressed, and readable from the stream. |
| 736 EXPECT_TRUE(stream_->trailers_decompressed()); |
| 737 const string decompressed_trailers = stream_->decompressed_trailers(); |
| 738 EXPECT_EQ(trailers, decompressed_trailers); |
| 739 // Consuming the trailers erases them from the stream. |
| 740 stream_->MarkTrailersConsumed(decompressed_trailers.size()); |
| 741 EXPECT_EQ("", stream_->decompressed_trailers()); |
| 742 |
| 743 EXPECT_FALSE(stream_->IsDoneReading()); |
| 744 // Receive and consume body. |
| 745 QuicStreamFrame frame(kClientDataStreamId1, /*fin=*/false, 0, body); |
| 746 stream_->OnStreamFrame(frame); |
| 747 EXPECT_EQ(body, stream_->data()); |
| 748 EXPECT_TRUE(stream_->IsDoneReading()); |
| 749 } |
| 750 |
712 TEST_P(QuicSpdyStreamTest, ClosingStreamWithNoTrailers) { | 751 TEST_P(QuicSpdyStreamTest, ClosingStreamWithNoTrailers) { |
713 // Verify that a stream receiving headers, body, and no trailers is correctly | 752 // Verify that a stream receiving headers, body, and no trailers is correctly |
714 // marked as done reading on consumption of headers and body. | 753 // marked as done reading on consumption of headers and body. |
715 Initialize(kShouldProcessData); | 754 Initialize(kShouldProcessData); |
716 | 755 |
717 // Receive and consume initial headers with FIN not set. | 756 // Receive and consume initial headers with FIN not set. |
718 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 757 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
719 stream_->OnStreamHeaders(headers); | 758 stream_->OnStreamHeaders(headers); |
720 stream_->OnStreamHeadersComplete(/*fin=*/false, headers.size()); | 759 stream_->OnStreamHeadersComplete(/*fin=*/false, headers.size()); |
721 stream_->MarkHeadersConsumed(headers.size()); | 760 stream_->MarkHeadersConsumed(headers.size()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 | 882 |
844 // Writing Trailers should fail, as the FIN has already been sent. | 883 // Writing Trailers should fail, as the FIN has already been sent. |
845 // populated with the number of body bytes written. | 884 // populated with the number of body bytes written. |
846 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), | 885 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), |
847 "Trailers cannot be sent after a FIN"); | 886 "Trailers cannot be sent after a FIN"); |
848 } | 887 } |
849 | 888 |
850 } // namespace | 889 } // namespace |
851 } // namespace test | 890 } // namespace test |
852 } // namespace net | 891 } // namespace net |
OLD | NEW |