| 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 // A toy server specific QuicSession subclass. | 5 // A toy server specific QuicSession subclass. |
| 6 | 6 |
| 7 #ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_SESSION_H_ | 7 #ifndef NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_SESSION_H_ |
| 8 #define NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_SESSION_H_ | 8 #define NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_SESSION_H_ |
| 9 | 9 |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| 11 | 11 |
| 12 #include <deque> | 12 #include <deque> |
| 13 #include <list> | 13 #include <list> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <set> | 15 #include <set> |
| 16 #include <string> | 16 #include <string> |
| 17 #include <utility> | 17 #include <utility> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "net/quic/core/quic_crypto_server_stream.h" | 21 #include "net/quic/core/quic_crypto_server_stream.h" |
| 22 #include "net/quic/core/quic_packets.h" | 22 #include "net/quic/core/quic_packets.h" |
| 23 #include "net/quic/core/quic_server_session_base.h" | 23 #include "net/quic/core/quic_server_session_base.h" |
| 24 #include "net/quic/core/quic_spdy_session.h" | 24 #include "net/quic/core/quic_spdy_session.h" |
| 25 #include "net/tools/quic/quic_in_memory_cache.h" | 25 #include "net/tools/quic/quic_http_response_cache.h" |
| 26 #include "net/tools/quic/quic_simple_server_stream.h" | 26 #include "net/tools/quic/quic_simple_server_stream.h" |
| 27 | 27 |
| 28 namespace net { | 28 namespace net { |
| 29 | 29 |
| 30 class QuicConfig; | 30 class QuicConfig; |
| 31 class QuicConnection; | 31 class QuicConnection; |
| 32 class QuicCryptoServerConfig; | 32 class QuicCryptoServerConfig; |
| 33 | 33 |
| 34 namespace test { | 34 namespace test { |
| 35 class QuicSimpleServerSessionPeer; | 35 class QuicSimpleServerSessionPeer; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 55 bool is_cancelled; | 55 bool is_cancelled; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Takes ownership of |connection|. | 58 // Takes ownership of |connection|. |
| 59 QuicSimpleServerSession(const QuicConfig& config, | 59 QuicSimpleServerSession(const QuicConfig& config, |
| 60 QuicConnection* connection, | 60 QuicConnection* connection, |
| 61 QuicSession::Visitor* visitor, | 61 QuicSession::Visitor* visitor, |
| 62 QuicCryptoServerStream::Helper* helper, | 62 QuicCryptoServerStream::Helper* helper, |
| 63 const QuicCryptoServerConfig* crypto_config, | 63 const QuicCryptoServerConfig* crypto_config, |
| 64 QuicCompressedCertsCache* compressed_certs_cache, | 64 QuicCompressedCertsCache* compressed_certs_cache, |
| 65 QuicInMemoryCache* in_memory_cache); | 65 QuicHttpResponseCache* response_cache); |
| 66 | 66 |
| 67 ~QuicSimpleServerSession() override; | 67 ~QuicSimpleServerSession() override; |
| 68 | 68 |
| 69 // When a stream is marked draining, it will decrease the number of open | 69 // When a stream is marked draining, it will decrease the number of open |
| 70 // streams. If it is an outgoing stream, try to open a new stream to send | 70 // streams. If it is an outgoing stream, try to open a new stream to send |
| 71 // remaing push responses. | 71 // remaing push responses. |
| 72 void StreamDraining(QuicStreamId id) override; | 72 void StreamDraining(QuicStreamId id) override; |
| 73 | 73 |
| 74 // Override base class to detact client sending data on server push stream. | 74 // Override base class to detact client sending data on server push stream. |
| 75 void OnStreamFrame(const QuicStreamFrame& frame) override; | 75 void OnStreamFrame(const QuicStreamFrame& frame) override; |
| 76 | 76 |
| 77 // Send out PUSH_PROMISE for all |resources| promised stream id in each frame | 77 // Send out PUSH_PROMISE for all |resources| promised stream id in each frame |
| 78 // will increase by 2 for each item in |resources|. | 78 // will increase by 2 for each item in |resources|. |
| 79 // And enqueue HEADERS block in those PUSH_PROMISED for sending push response | 79 // And enqueue HEADERS block in those PUSH_PROMISED for sending push response |
| 80 // later. | 80 // later. |
| 81 virtual void PromisePushResources( | 81 virtual void PromisePushResources( |
| 82 const std::string& request_url, | 82 const std::string& request_url, |
| 83 const std::list<QuicInMemoryCache::ServerPushInfo>& resources, | 83 const std::list<QuicHttpResponseCache::ServerPushInfo>& resources, |
| 84 QuicStreamId original_stream_id, | 84 QuicStreamId original_stream_id, |
| 85 const SpdyHeaderBlock& original_request_headers); | 85 const SpdyHeaderBlock& original_request_headers); |
| 86 | 86 |
| 87 protected: | 87 protected: |
| 88 // QuicSession methods: | 88 // QuicSession methods: |
| 89 QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override; | 89 QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override; |
| 90 QuicSimpleServerStream* CreateOutgoingDynamicStream( | 90 QuicSimpleServerStream* CreateOutgoingDynamicStream( |
| 91 SpdyPriority priority) override; | 91 SpdyPriority priority) override; |
| 92 // Closing an outgoing stream can reduce open outgoing stream count, try | 92 // Closing an outgoing stream can reduce open outgoing stream count, try |
| 93 // to handle queued promised streams right now. | 93 // to handle queued promised streams right now. |
| 94 void CloseStreamInner(QuicStreamId stream_id, bool locally_reset) override; | 94 void CloseStreamInner(QuicStreamId stream_id, bool locally_reset) override; |
| 95 // Override to return true for locally preserved server push stream. | 95 // Override to return true for locally preserved server push stream. |
| 96 void HandleFrameOnNonexistentOutgoingStream(QuicStreamId stream_id) override; | 96 void HandleFrameOnNonexistentOutgoingStream(QuicStreamId stream_id) override; |
| 97 // Override to handle reseting locally preserved streams. | 97 // Override to handle reseting locally preserved streams. |
| 98 void HandleRstOnValidNonexistentStream( | 98 void HandleRstOnValidNonexistentStream( |
| 99 const QuicRstStreamFrame& frame) override; | 99 const QuicRstStreamFrame& frame) override; |
| 100 | 100 |
| 101 // QuicServerSessionBaseMethod: | 101 // QuicServerSessionBaseMethod: |
| 102 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( | 102 QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( |
| 103 const QuicCryptoServerConfig* crypto_config, | 103 const QuicCryptoServerConfig* crypto_config, |
| 104 QuicCompressedCertsCache* compressed_certs_cache) override; | 104 QuicCompressedCertsCache* compressed_certs_cache) override; |
| 105 | 105 |
| 106 QuicInMemoryCache* in_memory_cache() { return in_memory_cache_; } | 106 QuicHttpResponseCache* response_cache() { return response_cache_; } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 friend class test::QuicSimpleServerSessionPeer; | 109 friend class test::QuicSimpleServerSessionPeer; |
| 110 | 110 |
| 111 // Create a server push headers block by copying request's headers block. | 111 // Create a server push headers block by copying request's headers block. |
| 112 // But replace or add these pseudo-headers as they are specific to each | 112 // But replace or add these pseudo-headers as they are specific to each |
| 113 // request: | 113 // request: |
| 114 // :authority, :path, :method, :scheme, referer. | 114 // :authority, :path, :method, :scheme, referer. |
| 115 // Copying the rest headers ensures they are the same as the original | 115 // Copying the rest headers ensures they are the same as the original |
| 116 // request, especially cookies. | 116 // request, especially cookies. |
| 117 SpdyHeaderBlock SynthesizePushRequestHeaders( | 117 SpdyHeaderBlock SynthesizePushRequestHeaders( |
| 118 std::string request_url, | 118 std::string request_url, |
| 119 QuicInMemoryCache::ServerPushInfo resource, | 119 QuicHttpResponseCache::ServerPushInfo resource, |
| 120 const SpdyHeaderBlock& original_request_headers); | 120 const SpdyHeaderBlock& original_request_headers); |
| 121 | 121 |
| 122 // Send PUSH_PROMISE frame on headers stream. | 122 // Send PUSH_PROMISE frame on headers stream. |
| 123 void SendPushPromise(QuicStreamId original_stream_id, | 123 void SendPushPromise(QuicStreamId original_stream_id, |
| 124 QuicStreamId promised_stream_id, | 124 QuicStreamId promised_stream_id, |
| 125 SpdyHeaderBlock headers); | 125 SpdyHeaderBlock headers); |
| 126 | 126 |
| 127 // Fetch response from cache for request headers enqueued into | 127 // Fetch response from cache for request headers enqueued into |
| 128 // promised_headers_and_streams_ and send them on dedicated stream until | 128 // promised_headers_and_streams_ and send them on dedicated stream until |
| 129 // reaches max_open_stream_ limit. | 129 // reaches max_open_stream_ limit. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 143 QuicStreamId highest_promised_stream_id_; | 143 QuicStreamId highest_promised_stream_id_; |
| 144 | 144 |
| 145 // Promised streams which hasn't been created yet because of max_open_stream_ | 145 // Promised streams which hasn't been created yet because of max_open_stream_ |
| 146 // limit. New element is added to the end of the queue. | 146 // limit. New element is added to the end of the queue. |
| 147 // Since outgoing stream is created in sequence, stream_id of each element in | 147 // Since outgoing stream is created in sequence, stream_id of each element in |
| 148 // the queue also increases by 2 from previous one's. The front element's | 148 // the queue also increases by 2 from previous one's. The front element's |
| 149 // stream_id is always next_outgoing_stream_id_, and the last one is always | 149 // stream_id is always next_outgoing_stream_id_, and the last one is always |
| 150 // highest_promised_stream_id_. | 150 // highest_promised_stream_id_. |
| 151 std::deque<PromisedStreamInfo> promised_streams_; | 151 std::deque<PromisedStreamInfo> promised_streams_; |
| 152 | 152 |
| 153 QuicInMemoryCache* in_memory_cache_; // Not owned. | 153 QuicHttpResponseCache* response_cache_; // Not owned. |
| 154 | 154 |
| 155 DISALLOW_COPY_AND_ASSIGN(QuicSimpleServerSession); | 155 DISALLOW_COPY_AND_ASSIGN(QuicSimpleServerSession); |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 } // namespace net | 158 } // namespace net |
| 159 | 159 |
| 160 #endif // NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_SESSION_H_ | 160 #endif // NET_TOOLS_QUIC_QUIC_SIMPLE_SERVER_SESSION_H_ |
| OLD | NEW |