QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_QUIC_CORE_HTTP_QUIC_CLIENT_PROMISED_INFO_H_ |
| 6 | #define QUICHE_QUIC_CORE_HTTP_QUIC_CLIENT_PROMISED_INFO_H_ |
| 7 | |
| 8 | #include <cstddef> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 9 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/quic/core/http/quic_client_push_promise_index.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_client_session_base.h" |
| 13 | #include "net/third_party/quiche/src/quic/core/http/quic_spdy_stream.h" |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 14 | #include "net/third_party/quiche/src/quic/core/quic_alarm.h" |
| 15 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 16 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
| 18 | |
| 19 | namespace quic { |
| 20 | |
| 21 | namespace test { |
| 22 | class QuicClientPromisedInfoPeer; |
| 23 | } // namespace test |
| 24 | |
| 25 | // QuicClientPromisedInfo tracks the client state of a server push |
| 26 | // stream from the time a PUSH_PROMISE is received until rendezvous |
| 27 | // between the promised response and the corresponding client request |
| 28 | // is complete. |
| 29 | class QUIC_EXPORT_PRIVATE QuicClientPromisedInfo |
| 30 | : public QuicClientPushPromiseIndex::TryHandle { |
| 31 | public: |
| 32 | // Interface to QuicSpdyClientStream |
| 33 | QuicClientPromisedInfo(QuicSpdyClientSessionBase* session, |
| 34 | QuicStreamId id, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 35 | std::string url); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 36 | QuicClientPromisedInfo(const QuicClientPromisedInfo&) = delete; |
| 37 | QuicClientPromisedInfo& operator=(const QuicClientPromisedInfo&) = delete; |
| 38 | virtual ~QuicClientPromisedInfo(); |
| 39 | |
| 40 | void Init(); |
| 41 | |
| 42 | // Validate promise headers etc. Returns true if headers are valid. |
| 43 | bool OnPromiseHeaders(const spdy::SpdyHeaderBlock& headers); |
| 44 | |
| 45 | // Store response, possibly proceed with final validation. |
| 46 | void OnResponseHeaders(const spdy::SpdyHeaderBlock& headers); |
| 47 | |
| 48 | // Rendezvous between this promised stream and a client request that |
| 49 | // has a matching URL. |
| 50 | virtual QuicAsyncStatus HandleClientRequest( |
| 51 | const spdy::SpdyHeaderBlock& headers, |
| 52 | QuicClientPushPromiseIndex::Delegate* delegate); |
| 53 | |
| 54 | void Cancel() override; |
| 55 | |
| 56 | void Reset(QuicRstStreamErrorCode error_code); |
| 57 | |
| 58 | // Client requests are initially associated to promises by matching |
| 59 | // URL in the client request against the URL in the promise headers, |
| 60 | // uing the |promised_by_url| map. The push can be cross-origin, so |
| 61 | // the client should validate that the session is authoritative for |
| 62 | // the promised URL. If not, it should call |RejectUnauthorized|. |
| 63 | QuicSpdyClientSessionBase* session() { return session_; } |
| 64 | |
| 65 | // If the promised response contains Vary header, then the fields |
| 66 | // specified by Vary must match between the client request header |
| 67 | // and the promise headers (see https://crbug.com//554220). Vary |
| 68 | // validation requires the response headers (for the actual Vary |
| 69 | // field list), the promise headers (taking the role of the "cached" |
| 70 | // request), and the client request headers. |
| 71 | spdy::SpdyHeaderBlock* request_headers() { return &request_headers_; } |
| 72 | |
| 73 | spdy::SpdyHeaderBlock* response_headers() { return response_headers_.get(); } |
| 74 | |
| 75 | // After validation, client will use this to access the pushed stream. |
| 76 | |
| 77 | QuicStreamId id() const { return id_; } |
| 78 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 79 | const std::string url() const { return url_; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 80 | |
| 81 | // Return true if there's a request pending matching this push promise. |
| 82 | bool is_validating() const { return client_request_delegate_ != nullptr; } |
| 83 | |
| 84 | private: |
| 85 | friend class test::QuicClientPromisedInfoPeer; |
| 86 | |
| 87 | class CleanupAlarm : public QuicAlarm::Delegate { |
| 88 | public: |
| 89 | explicit CleanupAlarm(QuicClientPromisedInfo* promised) |
| 90 | : promised_(promised) {} |
| 91 | |
| 92 | void OnAlarm() override; |
| 93 | |
| 94 | QuicClientPromisedInfo* promised_; |
| 95 | }; |
| 96 | |
| 97 | QuicAsyncStatus FinalValidation(); |
| 98 | |
| 99 | QuicSpdyClientSessionBase* session_; |
| 100 | QuicStreamId id_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 101 | std::string url_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 102 | spdy::SpdyHeaderBlock request_headers_; |
| 103 | std::unique_ptr<spdy::SpdyHeaderBlock> response_headers_; |
| 104 | spdy::SpdyHeaderBlock client_request_headers_; |
| 105 | QuicClientPushPromiseIndex::Delegate* client_request_delegate_; |
| 106 | |
| 107 | // The promise will commit suicide eventually if it is not claimed by a GET |
| 108 | // first. |
| 109 | std::unique_ptr<QuicAlarm> cleanup_alarm_; |
| 110 | }; |
| 111 | |
| 112 | } // namespace quic |
| 113 | |
| 114 | #endif // QUICHE_QUIC_CORE_HTTP_QUIC_CLIENT_PROMISED_INFO_H_ |