| 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/tools/quic/quic_simple_server_session.h" | 5 #include "net/tools/quic/quic_simple_server_session.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "net/quic/core/proto/cached_network_parameters.pb.h" | 11 #include "net/quic/core/proto/cached_network_parameters.pb.h" |
| 12 #include "net/quic/core/quic_connection.h" | 12 #include "net/quic/core/quic_connection.h" |
| 13 #include "net/quic/core/quic_flags.h" | 13 #include "net/quic/core/quic_flags.h" |
| 14 #include "net/quic/core/quic_spdy_session.h" | 14 #include "net/quic/core/quic_spdy_session.h" |
| 15 #include "net/tools/quic/quic_simple_server_stream.h" | 15 #include "net/tools/quic/quic_simple_server_stream.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 using std::string; | 18 using std::string; |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 QuicSimpleServerSession::QuicSimpleServerSession( | 22 QuicSimpleServerSession::QuicSimpleServerSession( |
| 23 const QuicConfig& config, | 23 const QuicConfig& config, |
| 24 QuicConnection* connection, | 24 QuicConnection* connection, |
| 25 QuicSession::Visitor* visitor, | 25 QuicSession::Visitor* visitor, |
| 26 QuicCryptoServerStream::Helper* helper, | 26 QuicCryptoServerStream::Helper* helper, |
| 27 const QuicCryptoServerConfig* crypto_config, | 27 const QuicCryptoServerConfig* crypto_config, |
| 28 QuicCompressedCertsCache* compressed_certs_cache, | 28 QuicCompressedCertsCache* compressed_certs_cache, |
| 29 QuicInMemoryCache* in_memory_cache) | 29 QuicHttpResponseCache* response_cache) |
| 30 : QuicServerSessionBase(config, | 30 : QuicServerSessionBase(config, |
| 31 connection, | 31 connection, |
| 32 visitor, | 32 visitor, |
| 33 helper, | 33 helper, |
| 34 crypto_config, | 34 crypto_config, |
| 35 compressed_certs_cache), | 35 compressed_certs_cache), |
| 36 highest_promised_stream_id_(0), | 36 highest_promised_stream_id_(0), |
| 37 in_memory_cache_(in_memory_cache) {} | 37 response_cache_(response_cache) {} |
| 38 | 38 |
| 39 QuicSimpleServerSession::~QuicSimpleServerSession() { | 39 QuicSimpleServerSession::~QuicSimpleServerSession() { |
| 40 delete connection(); | 40 delete connection(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 QuicCryptoServerStreamBase* | 43 QuicCryptoServerStreamBase* |
| 44 QuicSimpleServerSession::CreateQuicCryptoServerStream( | 44 QuicSimpleServerSession::CreateQuicCryptoServerStream( |
| 45 const QuicCryptoServerConfig* crypto_config, | 45 const QuicCryptoServerConfig* crypto_config, |
| 46 QuicCompressedCertsCache* compressed_certs_cache) { | 46 QuicCompressedCertsCache* compressed_certs_cache) { |
| 47 return new QuicCryptoServerStream(crypto_config, compressed_certs_cache, | 47 return new QuicCryptoServerStream(crypto_config, compressed_certs_cache, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 62 connection()->CloseConnection( | 62 connection()->CloseConnection( |
| 63 QUIC_INVALID_STREAM_ID, "Client sent data on server push stream", | 63 QUIC_INVALID_STREAM_ID, "Client sent data on server push stream", |
| 64 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 64 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 QuicSpdySession::OnStreamFrame(frame); | 67 QuicSpdySession::OnStreamFrame(frame); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void QuicSimpleServerSession::PromisePushResources( | 70 void QuicSimpleServerSession::PromisePushResources( |
| 71 const string& request_url, | 71 const string& request_url, |
| 72 const std::list<QuicInMemoryCache::ServerPushInfo>& resources, | 72 const std::list<QuicHttpResponseCache::ServerPushInfo>& resources, |
| 73 QuicStreamId original_stream_id, | 73 QuicStreamId original_stream_id, |
| 74 const SpdyHeaderBlock& original_request_headers) { | 74 const SpdyHeaderBlock& original_request_headers) { |
| 75 if (!server_push_enabled()) { | 75 if (!server_push_enabled()) { |
| 76 return; | 76 return; |
| 77 } | 77 } |
| 78 | 78 |
| 79 for (QuicInMemoryCache::ServerPushInfo resource : resources) { | 79 for (QuicHttpResponseCache::ServerPushInfo resource : resources) { |
| 80 SpdyHeaderBlock headers = SynthesizePushRequestHeaders( | 80 SpdyHeaderBlock headers = SynthesizePushRequestHeaders( |
| 81 request_url, resource, original_request_headers); | 81 request_url, resource, original_request_headers); |
| 82 highest_promised_stream_id_ += 2; | 82 highest_promised_stream_id_ += 2; |
| 83 SendPushPromise(original_stream_id, highest_promised_stream_id_, | 83 SendPushPromise(original_stream_id, highest_promised_stream_id_, |
| 84 headers.Clone()); | 84 headers.Clone()); |
| 85 promised_streams_.push_back(PromisedStreamInfo( | 85 promised_streams_.push_back(PromisedStreamInfo( |
| 86 std::move(headers), highest_promised_stream_id_, resource.priority)); | 86 std::move(headers), highest_promised_stream_id_, resource.priority)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Procese promised push request as many as possible. | 89 // Procese promised push request as many as possible. |
| 90 HandlePromisedPushRequests(); | 90 HandlePromisedPushRequests(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 QuicSpdyStream* QuicSimpleServerSession::CreateIncomingDynamicStream( | 93 QuicSpdyStream* QuicSimpleServerSession::CreateIncomingDynamicStream( |
| 94 QuicStreamId id) { | 94 QuicStreamId id) { |
| 95 if (!ShouldCreateIncomingDynamicStream(id)) { | 95 if (!ShouldCreateIncomingDynamicStream(id)) { |
| 96 return nullptr; | 96 return nullptr; |
| 97 } | 97 } |
| 98 | 98 |
| 99 QuicSpdyStream* stream = | 99 QuicSpdyStream* stream = |
| 100 new QuicSimpleServerStream(id, this, in_memory_cache_); | 100 new QuicSimpleServerStream(id, this, response_cache_); |
| 101 ActivateStream(base::WrapUnique(stream)); | 101 ActivateStream(base::WrapUnique(stream)); |
| 102 return stream; | 102 return stream; |
| 103 } | 103 } |
| 104 | 104 |
| 105 QuicSimpleServerStream* QuicSimpleServerSession::CreateOutgoingDynamicStream( | 105 QuicSimpleServerStream* QuicSimpleServerSession::CreateOutgoingDynamicStream( |
| 106 SpdyPriority priority) { | 106 SpdyPriority priority) { |
| 107 if (!ShouldCreateOutgoingDynamicStream()) { | 107 if (!ShouldCreateOutgoingDynamicStream()) { |
| 108 return nullptr; | 108 return nullptr; |
| 109 } | 109 } |
| 110 | 110 |
| 111 QuicSimpleServerStream* stream = new QuicSimpleServerStream( | 111 QuicSimpleServerStream* stream = new QuicSimpleServerStream( |
| 112 GetNextOutgoingStreamId(), this, in_memory_cache_); | 112 GetNextOutgoingStreamId(), this, response_cache_); |
| 113 stream->SetPriority(priority); | 113 stream->SetPriority(priority); |
| 114 ActivateStream(base::WrapUnique(stream)); | 114 ActivateStream(base::WrapUnique(stream)); |
| 115 return stream; | 115 return stream; |
| 116 } | 116 } |
| 117 | 117 |
| 118 void QuicSimpleServerSession::CloseStreamInner(QuicStreamId stream_id, | 118 void QuicSimpleServerSession::CloseStreamInner(QuicStreamId stream_id, |
| 119 bool locally_reset) { | 119 bool locally_reset) { |
| 120 QuicSpdySession::CloseStreamInner(stream_id, locally_reset); | 120 QuicSpdySession::CloseStreamInner(stream_id, locally_reset); |
| 121 HandlePromisedPushRequests(); | 121 HandlePromisedPushRequests(); |
| 122 } | 122 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 144 DCHECK(frame.stream_id >= next_outgoing_stream_id()); | 144 DCHECK(frame.stream_id >= next_outgoing_stream_id()); |
| 145 size_t index = (frame.stream_id - next_outgoing_stream_id()) / 2; | 145 size_t index = (frame.stream_id - next_outgoing_stream_id()) / 2; |
| 146 DCHECK(index <= promised_streams_.size()); | 146 DCHECK(index <= promised_streams_.size()); |
| 147 promised_streams_[index].is_cancelled = true; | 147 promised_streams_[index].is_cancelled = true; |
| 148 connection()->SendRstStream(frame.stream_id, QUIC_RST_ACKNOWLEDGEMENT, 0); | 148 connection()->SendRstStream(frame.stream_id, QUIC_RST_ACKNOWLEDGEMENT, 0); |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 | 151 |
| 152 SpdyHeaderBlock QuicSimpleServerSession::SynthesizePushRequestHeaders( | 152 SpdyHeaderBlock QuicSimpleServerSession::SynthesizePushRequestHeaders( |
| 153 string request_url, | 153 string request_url, |
| 154 QuicInMemoryCache::ServerPushInfo resource, | 154 QuicHttpResponseCache::ServerPushInfo resource, |
| 155 const SpdyHeaderBlock& original_request_headers) { | 155 const SpdyHeaderBlock& original_request_headers) { |
| 156 GURL push_request_url = resource.request_url; | 156 GURL push_request_url = resource.request_url; |
| 157 string path = push_request_url.path(); | 157 string path = push_request_url.path(); |
| 158 | 158 |
| 159 SpdyHeaderBlock spdy_headers = original_request_headers.Clone(); | 159 SpdyHeaderBlock spdy_headers = original_request_headers.Clone(); |
| 160 // :authority could be different from original request. | 160 // :authority could be different from original request. |
| 161 spdy_headers[":authority"] = push_request_url.host(); | 161 spdy_headers[":authority"] = push_request_url.host(); |
| 162 spdy_headers[":path"] = path; | 162 spdy_headers[":path"] = path; |
| 163 // Push request always use GET. | 163 // Push request always use GET. |
| 164 spdy_headers[":method"] = "GET"; | 164 spdy_headers[":method"] = "GET"; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 DVLOG(1) << "created server push stream " << promised_stream->id(); | 202 DVLOG(1) << "created server push stream " << promised_stream->id(); |
| 203 | 203 |
| 204 SpdyHeaderBlock request_headers(std::move(promised_info.request_headers)); | 204 SpdyHeaderBlock request_headers(std::move(promised_info.request_headers)); |
| 205 | 205 |
| 206 promised_streams_.pop_front(); | 206 promised_streams_.pop_front(); |
| 207 promised_stream->PushResponse(std::move(request_headers)); | 207 promised_stream->PushResponse(std::move(request_headers)); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 } // namespace net | 211 } // namespace net |
| OLD | NEW |