OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_SPDY_SPDY_STREAM_H_ | 5 #ifndef NET_SPDY_SPDY_STREAM_H_ |
6 #define NET_SPDY_SPDY_STREAM_H_ | 6 #define NET_SPDY_SPDY_STREAM_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 }; | 47 }; |
48 | 48 |
49 // Passed to some SpdyStream functions to indicate whether there's | 49 // Passed to some SpdyStream functions to indicate whether there's |
50 // more data to send. | 50 // more data to send. |
51 enum SpdySendStatus { | 51 enum SpdySendStatus { |
52 MORE_DATA_TO_SEND, | 52 MORE_DATA_TO_SEND, |
53 NO_MORE_DATA_TO_SEND | 53 NO_MORE_DATA_TO_SEND |
54 }; | 54 }; |
55 | 55 |
56 // Returned by SpdyStream::OnResponseHeadersUpdated() to indicate | 56 // Returned by SpdyStream::OnResponseHeadersUpdated() to indicate |
57 // whether the current response headers are complete or not. | 57 // whether the current response headers are complete or not, or whether |
| 58 // trailers have been received. TRAILERS_RECEIVED denotes the state where |
| 59 // headers are received after DATA frames. TRAILERS_RECEIVED is only used for |
| 60 // SPDY_REQUEST_RESPONSE_STREAM, and this state also implies that the response |
| 61 // headers are complete. |
58 enum SpdyResponseHeadersStatus { | 62 enum SpdyResponseHeadersStatus { |
59 RESPONSE_HEADERS_ARE_INCOMPLETE, | 63 RESPONSE_HEADERS_ARE_INCOMPLETE, |
60 RESPONSE_HEADERS_ARE_COMPLETE | 64 RESPONSE_HEADERS_ARE_COMPLETE, |
| 65 TRAILERS_RECEIVED, |
61 }; | 66 }; |
62 | 67 |
63 // The SpdyStream is used by the SpdySession to represent each stream known | 68 // The SpdyStream is used by the SpdySession to represent each stream known |
64 // on the SpdySession. This class provides interfaces for SpdySession to use. | 69 // on the SpdySession. This class provides interfaces for SpdySession to use. |
65 // Streams can be created either by the client or by the server. When they | 70 // Streams can be created either by the client or by the server. When they |
66 // are initiated by the client, both the SpdySession and client object (such as | 71 // are initiated by the client, both the SpdySession and client object (such as |
67 // a SpdyNetworkTransaction) will maintain a reference to the stream. When | 72 // a SpdyNetworkTransaction) will maintain a reference to the stream. When |
68 // initiated by the server, only the SpdySession will maintain any reference, | 73 // initiated by the server, only the SpdySession will maintain any reference, |
69 // until such a time as a client object requests a stream for the path. | 74 // until such a time as a client object requests a stream for the path. |
70 class NET_EXPORT_PRIVATE SpdyStream { | 75 class NET_EXPORT_PRIVATE SpdyStream { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // exactly once before data is received, and it is expected | 117 // exactly once before data is received, and it is expected |
113 // that RESPONSE_HEADERS_ARE_COMPLETE is returned. If | 118 // that RESPONSE_HEADERS_ARE_COMPLETE is returned. If |
114 // RESPONSE_HEADERS_ARE_INCOMPLETE is returned, this is | 119 // RESPONSE_HEADERS_ARE_INCOMPLETE is returned, this is |
115 // treated as a protocol error. | 120 // treated as a protocol error. |
116 // | 121 // |
117 // - For push streams, it is expected that this function will be | 122 // - For push streams, it is expected that this function will be |
118 // called until RESPONSE_HEADERS_ARE_COMPLETE is returned | 123 // called until RESPONSE_HEADERS_ARE_COMPLETE is returned |
119 // before any data is received; any deviation from this is | 124 // before any data is received; any deviation from this is |
120 // treated as a protocol error. | 125 // treated as a protocol error. |
121 // | 126 // |
122 // TODO(akalin): Treat headers received after data has been | |
123 // received as a protocol error for non-bidirectional streams. | |
124 // TODO(jgraettinger): This should be at the semantic (HTTP) rather | 127 // TODO(jgraettinger): This should be at the semantic (HTTP) rather |
125 // than stream layer. Streams shouldn't have a notion of header | 128 // than stream layer. Streams shouldn't have a notion of header |
126 // completeness. Move to SpdyHttpStream/SpdyWebsocketStream. | 129 // completeness. Move to SpdyHttpStream/SpdyWebsocketStream. |
127 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 130 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( |
128 const SpdyHeaderBlock& response_headers) = 0; | 131 const SpdyHeaderBlock& response_headers) = 0; |
129 | 132 |
130 // Called when data is received after all required response | 133 // Called when data is received after all required response |
131 // headers have been received. |buffer| may be NULL, which signals | 134 // headers have been received. |buffer| may be NULL, which signals |
132 // EOF. Must return OK if the data was received successfully, or | 135 // EOF. Must return OK if the data was received successfully, or |
133 // a network error code otherwise. | 136 // a network error code otherwise. |
134 // | 137 // |
135 // May cause the stream to be closed. | 138 // May cause the stream to be closed. |
136 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) = 0; | 139 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) = 0; |
137 | 140 |
138 // Called when data is sent. Must not cause the stream to be | 141 // Called when data is sent. Must not cause the stream to be |
139 // closed. | 142 // closed. |
140 virtual void OnDataSent() = 0; | 143 virtual void OnDataSent() = 0; |
141 | 144 |
| 145 // Called when trailers are received. Note that trailers HEADER frame will |
| 146 // have END_STREAM flag set according to section 8.1 of the HTTP/2 RFC, |
| 147 // so this will be followed by OnClose. |
| 148 virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0; |
| 149 |
142 // Called when SpdyStream is closed. No other delegate functions | 150 // Called when SpdyStream is closed. No other delegate functions |
143 // will be called after this is called, and the delegate must not | 151 // will be called after this is called, and the delegate must not |
144 // access the stream after this is called. Must not cause the | 152 // access the stream after this is called. Must not cause the |
145 // stream to be be (re-)closed. | 153 // stream to be be (re-)closed. |
146 // | 154 // |
147 // TODO(akalin): Allow this function to re-close the stream and | 155 // TODO(akalin): Allow this function to re-close the stream and |
148 // handle it gracefully. | 156 // handle it gracefully. |
149 virtual void OnClose(int status) = 0; | 157 virtual void OnClose(int status) = 0; |
150 | 158 |
151 protected: | 159 protected: |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 bool write_handler_guard_; | 582 bool write_handler_guard_; |
575 | 583 |
576 base::WeakPtrFactory<SpdyStream> weak_ptr_factory_; | 584 base::WeakPtrFactory<SpdyStream> weak_ptr_factory_; |
577 | 585 |
578 DISALLOW_COPY_AND_ASSIGN(SpdyStream); | 586 DISALLOW_COPY_AND_ASSIGN(SpdyStream); |
579 }; | 587 }; |
580 | 588 |
581 } // namespace net | 589 } // namespace net |
582 | 590 |
583 #endif // NET_SPDY_SPDY_STREAM_H_ | 591 #endif // NET_SPDY_SPDY_STREAM_H_ |
OLD | NEW |