blob: bf614051fc10893a6f22ac795b119e1192c8d838 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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>
vasilvv872e7a32019-03-12 16:42:44 -07009#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050010
QUICHE teama6ef0a62019-03-07 20:34:33 -050011#include "net/third_party/quiche/src/quic/core/http/quic_client_push_promise_index.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050012#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"
vasilvvc48c8712019-03-11 13:38:16 -070014#include "net/third_party/quiche/src/quic/core/quic_alarm.h"
15#include "net/third_party/quiche/src/quic/core/quic_packets.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050016#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050017#include "net/third_party/quiche/src/spdy/core/spdy_framer.h"
18
19namespace quic {
20
21namespace test {
22class 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.
29class QUIC_EXPORT_PRIVATE QuicClientPromisedInfo
30 : public QuicClientPushPromiseIndex::TryHandle {
31 public:
32 // Interface to QuicSpdyClientStream
33 QuicClientPromisedInfo(QuicSpdyClientSessionBase* session,
34 QuicStreamId id,
vasilvvc48c8712019-03-11 13:38:16 -070035 std::string url);
QUICHE teama6ef0a62019-03-07 20:34:33 -050036 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
vasilvvc48c8712019-03-11 13:38:16 -070079 const std::string url() const { return url_; }
QUICHE teama6ef0a62019-03-07 20:34:33 -050080
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_;
vasilvvc48c8712019-03-11 13:38:16 -0700101 std::string url_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500102 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_