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 // The base class for streams which deliver data to/from an application. | 5 // The base class for streams which deliver data to/from an application. |
6 // In each direction, the data on such a stream first contains compressed | 6 // In each direction, the data on such a stream first contains compressed |
7 // headers then body data. | 7 // headers then body data. |
8 | 8 |
9 #ifndef NET_QUIC_QUIC_SPDY_STREAM_H_ | 9 #ifndef NET_QUIC_QUIC_SPDY_STREAM_H_ |
10 #define NET_QUIC_QUIC_SPDY_STREAM_H_ | 10 #define NET_QUIC_QUIC_SPDY_STREAM_H_ |
11 | 11 |
12 #include <stddef.h> | 12 #include <stddef.h> |
13 #include <sys/types.h> | 13 #include <sys/types.h> |
14 | 14 |
15 #include <list> | 15 #include <list> |
16 #include <string> | 16 #include <string> |
17 | 17 |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
20 #include "net/base/iovec.h" | 20 #include "net/base/iovec.h" |
21 #include "net/base/ip_endpoint.h" | 21 #include "net/base/ip_endpoint.h" |
22 #include "net/base/net_export.h" | 22 #include "net/base/net_export.h" |
| 23 #include "net/quic/quic_header_list.h" |
23 #include "net/quic/quic_protocol.h" | 24 #include "net/quic/quic_protocol.h" |
24 #include "net/quic/quic_stream_sequencer.h" | 25 #include "net/quic/quic_stream_sequencer.h" |
25 #include "net/quic/reliable_quic_stream.h" | 26 #include "net/quic/reliable_quic_stream.h" |
26 #include "net/spdy/spdy_framer.h" | 27 #include "net/spdy/spdy_framer.h" |
27 | 28 |
28 namespace net { | 29 namespace net { |
29 | 30 |
30 namespace test { | 31 namespace test { |
31 class QuicSpdyStreamPeer; | 32 class QuicSpdyStreamPeer; |
32 class ReliableQuicStreamPeer; | 33 class ReliableQuicStreamPeer; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 78 |
78 // Called by the session when headers with a priority have been received | 79 // Called by the session when headers with a priority have been received |
79 // for this stream. This method will only be called for server streams. | 80 // for this stream. This method will only be called for server streams. |
80 virtual void OnStreamHeadersPriority(SpdyPriority priority); | 81 virtual void OnStreamHeadersPriority(SpdyPriority priority); |
81 | 82 |
82 // Called by the session when decompressed headers have been completely | 83 // Called by the session when decompressed headers have been completely |
83 // delivered to this stream. If |fin| is true, then this stream | 84 // delivered to this stream. If |fin| is true, then this stream |
84 // should be closed; no more data will be sent by the peer. | 85 // should be closed; no more data will be sent by the peer. |
85 virtual void OnStreamHeadersComplete(bool fin, size_t frame_len); | 86 virtual void OnStreamHeadersComplete(bool fin, size_t frame_len); |
86 | 87 |
| 88 // Called by the session when decompressed headers have been completely |
| 89 // delivered to this stream. If |fin| is true, then this stream |
| 90 // should be closed; no more data will be sent by the peer. |
| 91 virtual void OnStreamHeaderList(bool fin, |
| 92 size_t frame_len, |
| 93 const QuicHeaderList& header_list); |
| 94 |
87 // Called by the session when decompressed PUSH_PROMISE headers data | 95 // Called by the session when decompressed PUSH_PROMISE headers data |
88 // is received for this stream. | 96 // is received for this stream. |
89 // May be called multiple times, with each call providing additional headers | 97 // May be called multiple times, with each call providing additional headers |
90 // data until OnPromiseHeadersComplete is called. | 98 // data until OnPromiseHeadersComplete is called. |
91 virtual void OnPromiseHeaders(StringPiece headers_data); | 99 virtual void OnPromiseHeaders(StringPiece headers_data); |
92 | 100 |
93 // Called by the session when decompressed push promise headers have | 101 // Called by the session when decompressed push promise headers have |
94 // been completely delivered to this stream. | 102 // been completely delivered to this stream. |
95 virtual void OnPromiseHeadersComplete(QuicStreamId promised_id, | 103 virtual void OnPromiseHeadersComplete(QuicStreamId promised_id, |
96 size_t frame_len); | 104 size_t frame_len); |
97 | 105 |
| 106 // Called by the session when decompressed push promise headers have |
| 107 // been completely delivered to this stream. |
| 108 virtual void OnPromiseHeaderList(QuicStreamId promised_id, |
| 109 size_t frame_len, |
| 110 const QuicHeaderList& header_list); |
| 111 |
98 // Override the base class to not discard response when receiving | 112 // Override the base class to not discard response when receiving |
99 // QUIC_STREAM_NO_ERROR on QUIC_VERSION_29 and later versions. | 113 // QUIC_STREAM_NO_ERROR on QUIC_VERSION_29 and later versions. |
100 void OnStreamReset(const QuicRstStreamFrame& frame) override; | 114 void OnStreamReset(const QuicRstStreamFrame& frame) override; |
101 | 115 |
102 // Writes the headers contained in |header_block| to the dedicated | 116 // Writes the headers contained in |header_block| to the dedicated |
103 // headers stream. | 117 // headers stream. |
104 virtual size_t WriteHeaders(const SpdyHeaderBlock& header_block, | 118 virtual size_t WriteHeaders(const SpdyHeaderBlock& header_block, |
105 bool fin, | 119 bool fin, |
106 QuicAckListenerInterface* ack_notifier_delegate); | 120 QuicAckListenerInterface* ack_notifier_delegate); |
107 | 121 |
108 // Sends |data| to the peer, or buffers if it can't be sent immediately. | 122 // Sends |data| to the peer, or buffers if it can't be sent immediately. |
109 void WriteOrBufferBody(const std::string& data, | 123 void WriteOrBufferBody(const std::string& data, |
110 bool fin, | 124 bool fin, |
111 QuicAckListenerInterface* ack_notifier_delegate); | 125 QuicAckListenerInterface* ack_notifier_delegate); |
112 | 126 |
113 // Writes the trailers contained in |trailer_block| to the dedicated | 127 // Writes the trailers contained in |trailer_block| to the dedicated |
114 // headers stream. Trailers will always have the FIN set. | 128 // headers stream. Trailers will always have the FIN set. |
115 size_t WriteTrailers(SpdyHeaderBlock trailer_block, | 129 size_t WriteTrailers(SpdyHeaderBlock trailer_block, |
116 QuicAckListenerInterface* ack_notifier_delegate); | 130 QuicAckListenerInterface* ack_notifier_delegate); |
117 | 131 |
118 // Marks |bytes_consumed| of the headers data as consumed. | 132 // Marks |bytes_consumed| of the headers data as consumed. |
119 void MarkHeadersConsumed(size_t bytes_consumed); | 133 void MarkHeadersConsumed(size_t bytes_consumed); |
120 | 134 |
121 // Marks |bytes_consumed| of the trailers data as consumed. | 135 // Marks |bytes_consumed| of the trailers data as consumed. |
122 void MarkTrailersConsumed(size_t bytes_consumed); | 136 void MarkTrailersConsumed(size_t bytes_consumed); |
123 | 137 |
| 138 // Clears |header_list_|. |
| 139 void ConsumeHeaderList() { header_list_.Clear(); } |
| 140 |
124 // This block of functions wraps the sequencer's functions of the same | 141 // This block of functions wraps the sequencer's functions of the same |
125 // name. These methods return uncompressed data until that has | 142 // name. These methods return uncompressed data until that has |
126 // been fully processed. Then they simply delegate to the sequencer. | 143 // been fully processed. Then they simply delegate to the sequencer. |
127 virtual size_t Readv(const struct iovec* iov, size_t iov_len); | 144 virtual size_t Readv(const struct iovec* iov, size_t iov_len); |
128 virtual int GetReadableRegions(iovec* iov, size_t iov_len) const; | 145 virtual int GetReadableRegions(iovec* iov, size_t iov_len) const; |
129 void MarkConsumed(size_t num_bytes); | 146 void MarkConsumed(size_t num_bytes); |
130 | 147 |
131 // Returns true if header contains a valid 3-digit status and parse the status | 148 // Returns true if header contains a valid 3-digit status and parse the status |
132 // code to |status_code|. | 149 // code to |status_code|. |
133 bool ParseHeaderStatusCode(SpdyHeaderBlock* header, int* status_code) const; | 150 bool ParseHeaderStatusCode(SpdyHeaderBlock* header, int* status_code) const; |
134 | 151 |
135 // Returns true when all data has been read from the peer, including the fin. | 152 // Returns true when all data has been read from the peer, including the fin. |
136 bool IsDoneReading() const; | 153 bool IsDoneReading() const; |
137 bool HasBytesToRead() const; | 154 bool HasBytesToRead() const; |
138 | 155 |
139 void set_visitor(Visitor* visitor) { visitor_ = visitor; } | 156 void set_visitor(Visitor* visitor) { visitor_ = visitor; } |
140 | 157 |
141 bool headers_decompressed() const { return headers_decompressed_; } | 158 bool headers_decompressed() const { return headers_decompressed_; } |
142 | 159 |
143 const std::string& decompressed_headers() const { | 160 const std::string& decompressed_headers() const { |
144 return decompressed_headers_; | 161 return decompressed_headers_; |
145 } | 162 } |
146 | 163 |
| 164 const QuicHeaderList& header_list() const { return header_list_; } |
| 165 |
147 bool trailers_decompressed() const { return trailers_decompressed_; } | 166 bool trailers_decompressed() const { return trailers_decompressed_; } |
148 | 167 |
149 const std::string& decompressed_trailers() const { | 168 const std::string& decompressed_trailers() const { |
150 return decompressed_trailers_; | 169 return decompressed_trailers_; |
151 } | 170 } |
152 | 171 |
153 // Returns whatever trailers have been received for this stream. | 172 // Returns whatever trailers have been received for this stream. |
154 const SpdyHeaderBlock& received_trailers() const { | 173 const SpdyHeaderBlock& received_trailers() const { |
155 return received_trailers_; | 174 return received_trailers_; |
156 } | 175 } |
157 | 176 |
158 virtual SpdyPriority priority() const; | 177 virtual SpdyPriority priority() const; |
159 | 178 |
160 // Sets priority_ to priority. This should only be called before bytes are | 179 // Sets priority_ to priority. This should only be called before bytes are |
161 // written to the server. | 180 // written to the server. |
162 void SetPriority(SpdyPriority priority); | 181 void SetPriority(SpdyPriority priority); |
163 | 182 |
164 protected: | 183 protected: |
165 // Called by OnStreamHeadersComplete depending on which type (initial or | 184 // Called by OnStreamHeadersComplete depending on which type (initial or |
166 // trailing) headers are expected next. | 185 // trailing) headers are expected next. |
167 virtual void OnInitialHeadersComplete(bool fin, size_t frame_len); | 186 virtual void OnInitialHeadersComplete(bool fin, size_t frame_len); |
168 virtual void OnTrailingHeadersComplete(bool fin, size_t frame_len); | 187 virtual void OnTrailingHeadersComplete(bool fin, size_t frame_len); |
| 188 virtual void OnInitialHeadersComplete(bool fin, |
| 189 size_t frame_len, |
| 190 const QuicHeaderList& header_list); |
| 191 virtual void OnTrailingHeadersComplete(bool fin, |
| 192 size_t frame_len, |
| 193 const QuicHeaderList& header_list); |
169 QuicSpdySession* spdy_session() const { return spdy_session_; } | 194 QuicSpdySession* spdy_session() const { return spdy_session_; } |
170 Visitor* visitor() { return visitor_; } | 195 Visitor* visitor() { return visitor_; } |
171 | 196 |
172 // Returns true if headers have been fully read and consumed. | 197 // Returns true if headers have been fully read and consumed. |
173 bool FinishedReadingHeaders() const; | 198 bool FinishedReadingHeaders() const; |
174 | 199 |
175 private: | 200 private: |
176 friend class test::QuicSpdyStreamPeer; | 201 friend class test::QuicSpdyStreamPeer; |
177 friend class test::ReliableQuicStreamPeer; | 202 friend class test::ReliableQuicStreamPeer; |
178 friend class QuicStreamUtils; | 203 friend class QuicStreamUtils; |
179 | 204 |
180 // Returns true if trailers have been fully read and consumed. | 205 // Returns true if trailers have been fully read and consumed. |
181 bool FinishedReadingTrailers() const; | 206 bool FinishedReadingTrailers() const; |
182 | 207 |
183 QuicSpdySession* spdy_session_; | 208 QuicSpdySession* spdy_session_; |
184 | 209 |
185 Visitor* visitor_; | 210 Visitor* visitor_; |
186 // True if the headers have been completely decompressed. | 211 // True if the headers have been completely decompressed. |
187 bool headers_decompressed_; | 212 bool headers_decompressed_; |
188 // The priority of the stream, once parsed. | 213 // The priority of the stream, once parsed. |
189 SpdyPriority priority_; | 214 SpdyPriority priority_; |
190 // Contains a copy of the decompressed headers until they are consumed | 215 // Contains a copy of the decompressed headers until they are consumed |
191 // via ProcessData or Readv. | 216 // via ProcessData or Readv. |
192 std::string decompressed_headers_; | 217 std::string decompressed_headers_; |
| 218 // Contains a copy of the decompressed header (name, value) pairs until they |
| 219 // are consumed via Readv. |
| 220 QuicHeaderList header_list_; |
193 | 221 |
194 // True if the trailers have been completely decompressed. | 222 // True if the trailers have been completely decompressed. |
195 bool trailers_decompressed_; | 223 bool trailers_decompressed_; |
196 // Contains a copy of the decompressed trailers until they are consumed | 224 // Contains a copy of the decompressed trailers until they are consumed |
197 // via ProcessData or Readv. | 225 // via ProcessData or Readv. |
198 std::string decompressed_trailers_; | 226 std::string decompressed_trailers_; |
199 // The parsed trailers received from the peer. | 227 // The parsed trailers received from the peer. |
200 SpdyHeaderBlock received_trailers_; | 228 SpdyHeaderBlock received_trailers_; |
201 | 229 |
202 DISALLOW_COPY_AND_ASSIGN(QuicSpdyStream); | 230 DISALLOW_COPY_AND_ASSIGN(QuicSpdyStream); |
203 }; | 231 }; |
204 | 232 |
205 } // namespace net | 233 } // namespace net |
206 | 234 |
207 #endif // NET_QUIC_QUIC_SPDY_STREAM_H_ | 235 #endif // NET_QUIC_QUIC_SPDY_STREAM_H_ |
OLD | NEW |