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 #include "net/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
257 : request_(request) {} | 257 : request_(request) {} |
258 | 258 |
259 bool operator()(const base::WeakPtr<SpdyStreamRequest>& request) const { | 259 bool operator()(const base::WeakPtr<SpdyStreamRequest>& request) const { |
260 return request_.get() == request.get(); | 260 return request_.get() == request.get(); |
261 } | 261 } |
262 | 262 |
263 private: | 263 private: |
264 const base::WeakPtr<SpdyStreamRequest> request_; | 264 const base::WeakPtr<SpdyStreamRequest> request_; |
265 }; | 265 }; |
266 | 266 |
267 // Splits headers received in SYN_STREAM into request and response headers. | |
268 void GetPushPromiseHeadersFromSynStream(SpdyHeaderBlock* response_headers, | |
269 SpdyHeaderBlock* request_headers, | |
270 SpdyMajorVersion protocol_version) { | |
271 DCHECK(response_headers); | |
272 DCHECK(request_headers); | |
273 | |
274 // SPDY 2 server push urls are specified in a single "url" header. | |
275 if (protocol_version == SPDY2) { | |
276 SpdyHeaderBlock::iterator it; | |
277 it = response_headers->find("url"); | |
278 if (it != response_headers->end()) { | |
279 (*request_headers)["url"] = it->second; | |
280 response_headers->erase(it); | |
281 } | |
282 return; | |
283 } | |
284 | |
285 DCHECK_LT(SPDY2, protocol_version); | |
286 static const char* kRequestHeaders[] = { ":scheme", ":host", ":path" }; | |
Johnny
2014/06/05 02:56:04
Also :authority (instead of :host) for HTTP/2.
ni
baranovich
2014/06/05 19:16:58
Done.
| |
287 SpdyHeaderBlock::iterator it; | |
288 for (size_t i = 0; i < arraysize(kRequestHeaders); ++i) { | |
289 it = response_headers->find(kRequestHeaders[i]); | |
290 if (it != response_headers->end()) { | |
291 (*request_headers)[kRequestHeaders[i]] = it->second; | |
292 response_headers->erase(it); | |
293 } | |
294 } | |
Johnny
2014/06/05 02:56:04
Can we add unit testing on this in SpdySessionTest
baranovich
2014/06/05 19:16:58
Done.
| |
295 } | |
296 | |
267 // The maximum number of concurrent streams we will ever create. Even if | 297 // The maximum number of concurrent streams we will ever create. Even if |
268 // the server permits more, we will never exceed this limit. | 298 // the server permits more, we will never exceed this limit. |
269 const size_t kMaxConcurrentStreamLimit = 256; | 299 const size_t kMaxConcurrentStreamLimit = 256; |
270 | 300 |
271 } // namespace | 301 } // namespace |
272 | 302 |
273 SpdyProtocolErrorDetails MapFramerErrorToProtocolError( | 303 SpdyProtocolErrorDetails MapFramerErrorToProtocolError( |
274 SpdyFramer::SpdyError err) { | 304 SpdyFramer::SpdyError err) { |
275 switch(err) { | 305 switch(err) { |
276 case SpdyFramer::SPDY_NO_ERROR: | 306 case SpdyFramer::SPDY_NO_ERROR: |
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2119 | 2149 |
2120 InsertActivatedStream(stream.Pass()); | 2150 InsertActivatedStream(stream.Pass()); |
2121 | 2151 |
2122 ActiveStreamMap::iterator active_it = active_streams_.find(stream_id); | 2152 ActiveStreamMap::iterator active_it = active_streams_.find(stream_id); |
2123 if (active_it == active_streams_.end()) { | 2153 if (active_it == active_streams_.end()) { |
2124 NOTREACHED(); | 2154 NOTREACHED(); |
2125 return; | 2155 return; |
2126 } | 2156 } |
2127 | 2157 |
2128 // Parse the headers. | 2158 // Parse the headers. |
2159 | |
2160 // Split headers to simulate push promise and response. | |
2161 SpdyHeaderBlock request_headers; | |
2162 SpdyHeaderBlock response_headers(headers); | |
2163 GetPushPromiseHeadersFromSynStream(&response_headers, | |
Johnny
2014/06/05 02:56:04
Since we're copying here anyway, how about passing
baranovich
2014/06/05 19:16:57
Done.
That's the best name I've come up to;) maybe
| |
2164 &request_headers, | |
2165 GetProtocolVersion()); | |
2166 | |
2167 if (active_it->second.stream-> | |
2168 OnPushPromiseHeadersReceived(request_headers) != OK) | |
2169 return; | |
2170 | |
2129 if (OnInitialResponseHeadersReceived( | 2171 if (OnInitialResponseHeadersReceived( |
2130 headers, response_time, | 2172 response_headers, response_time, |
2131 recv_first_byte_time, active_it->second.stream) != OK) | 2173 recv_first_byte_time, active_it->second.stream) != OK) |
2132 return; | 2174 return; |
2133 | 2175 |
2134 base::StatsCounter push_requests("spdy.pushed_streams"); | 2176 base::StatsCounter push_requests("spdy.pushed_streams"); |
2135 push_requests.Increment(); | 2177 push_requests.Increment(); |
2136 } | 2178 } |
2137 | 2179 |
2138 void SpdySession::DeleteExpiredPushedStreams() { | 2180 void SpdySession::DeleteExpiredPushedStreams() { |
2139 if (unclaimed_pushed_streams_.empty()) | 2181 if (unclaimed_pushed_streams_.empty()) |
2140 return; | 2182 return; |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2944 if (!queue->empty()) { | 2986 if (!queue->empty()) { |
2945 SpdyStreamId stream_id = queue->front(); | 2987 SpdyStreamId stream_id = queue->front(); |
2946 queue->pop_front(); | 2988 queue->pop_front(); |
2947 return stream_id; | 2989 return stream_id; |
2948 } | 2990 } |
2949 } | 2991 } |
2950 return 0; | 2992 return 0; |
2951 } | 2993 } |
2952 | 2994 |
2953 } // namespace net | 2995 } // namespace net |
OLD | NEW |