| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 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/quic/core/quic_client_promised_info.h" | 5 #include "net/quic/core/quic_client_promised_info.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | |
| 8 #include "net/quic/core/spdy_utils.h" | 7 #include "net/quic/core/spdy_utils.h" |
| 8 #include "net/quic/platform/api/quic_logging.h" |
| 9 | 9 |
| 10 using net::SpdyHeaderBlock; | 10 using net::SpdyHeaderBlock; |
| 11 using net::kPushPromiseTimeoutSecs; | 11 using net::kPushPromiseTimeoutSecs; |
| 12 using std::string; | 12 using std::string; |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 QuicClientPromisedInfo::QuicClientPromisedInfo(QuicClientSessionBase* session, | 16 QuicClientPromisedInfo::QuicClientPromisedInfo(QuicClientSessionBase* session, |
| 17 QuicStreamId id, | 17 QuicStreamId id, |
| 18 string url) | 18 string url) |
| 19 : session_(session), | 19 : session_(session), |
| 20 id_(id), | 20 id_(id), |
| 21 url_(std::move(url)), | 21 url_(std::move(url)), |
| 22 client_request_delegate_(nullptr) {} | 22 client_request_delegate_(nullptr) {} |
| 23 | 23 |
| 24 QuicClientPromisedInfo::~QuicClientPromisedInfo() {} | 24 QuicClientPromisedInfo::~QuicClientPromisedInfo() {} |
| 25 | 25 |
| 26 void QuicClientPromisedInfo::CleanupAlarm::OnAlarm() { | 26 void QuicClientPromisedInfo::CleanupAlarm::OnAlarm() { |
| 27 DVLOG(1) << "self GC alarm for stream " << promised_->id_; | 27 QUIC_DVLOG(1) << "self GC alarm for stream " << promised_->id_; |
| 28 promised_->session()->OnPushStreamTimedOut(promised_->id_); | 28 promised_->session()->OnPushStreamTimedOut(promised_->id_); |
| 29 promised_->Reset(QUIC_PUSH_STREAM_TIMED_OUT); | 29 promised_->Reset(QUIC_PUSH_STREAM_TIMED_OUT); |
| 30 } | 30 } |
| 31 | 31 |
| 32 void QuicClientPromisedInfo::Init() { | 32 void QuicClientPromisedInfo::Init() { |
| 33 cleanup_alarm_.reset(session_->connection()->alarm_factory()->CreateAlarm( | 33 cleanup_alarm_.reset(session_->connection()->alarm_factory()->CreateAlarm( |
| 34 new QuicClientPromisedInfo::CleanupAlarm(this))); | 34 new QuicClientPromisedInfo::CleanupAlarm(this))); |
| 35 cleanup_alarm_->Set( | 35 cleanup_alarm_->Set( |
| 36 session_->connection()->helper()->GetClock()->ApproximateNow() + | 36 session_->connection()->helper()->GetClock()->ApproximateNow() + |
| 37 QuicTime::Delta::FromSeconds(kPushPromiseTimeoutSecs)); | 37 QuicTime::Delta::FromSeconds(kPushPromiseTimeoutSecs)); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void QuicClientPromisedInfo::OnPromiseHeaders(const SpdyHeaderBlock& headers) { | 40 void QuicClientPromisedInfo::OnPromiseHeaders(const SpdyHeaderBlock& headers) { |
| 41 // RFC7540, Section 8.2, requests MUST be safe [RFC7231], Section | 41 // RFC7540, Section 8.2, requests MUST be safe [RFC7231], Section |
| 42 // 4.2.1. GET and HEAD are the methods that are safe and required. | 42 // 4.2.1. GET and HEAD are the methods that are safe and required. |
| 43 SpdyHeaderBlock::const_iterator it = headers.find(":method"); | 43 SpdyHeaderBlock::const_iterator it = headers.find(":method"); |
| 44 DCHECK(it != headers.end()); | 44 DCHECK(it != headers.end()); |
| 45 if (!(it->second == "GET" || it->second == "HEAD")) { | 45 if (!(it->second == "GET" || it->second == "HEAD")) { |
| 46 DVLOG(1) << "Promise for stream " << id_ << " has invalid method " | 46 QUIC_DVLOG(1) << "Promise for stream " << id_ << " has invalid method " |
| 47 << it->second; | 47 << it->second; |
| 48 Reset(QUIC_INVALID_PROMISE_METHOD); | 48 Reset(QUIC_INVALID_PROMISE_METHOD); |
| 49 return; | 49 return; |
| 50 } | 50 } |
| 51 if (!SpdyUtils::UrlIsValid(headers)) { | 51 if (!SpdyUtils::UrlIsValid(headers)) { |
| 52 DVLOG(1) << "Promise for stream " << id_ << " has invalid URL " << url_; | 52 QUIC_DVLOG(1) << "Promise for stream " << id_ << " has invalid URL " |
| 53 << url_; |
| 53 Reset(QUIC_INVALID_PROMISE_URL); | 54 Reset(QUIC_INVALID_PROMISE_URL); |
| 54 return; | 55 return; |
| 55 } | 56 } |
| 56 if (!session_->IsAuthorized(SpdyUtils::GetHostNameFromHeaderBlock(headers))) { | 57 if (!session_->IsAuthorized(SpdyUtils::GetHostNameFromHeaderBlock(headers))) { |
| 57 Reset(QUIC_UNAUTHORIZED_PROMISE_URL); | 58 Reset(QUIC_UNAUTHORIZED_PROMISE_URL); |
| 58 return; | 59 return; |
| 59 } | 60 } |
| 60 request_headers_.reset(new SpdyHeaderBlock(headers.Clone())); | 61 request_headers_.reset(new SpdyHeaderBlock(headers.Clone())); |
| 61 } | 62 } |
| 62 | 63 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return FinalValidation(); | 125 return FinalValidation(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void QuicClientPromisedInfo::Cancel() { | 128 void QuicClientPromisedInfo::Cancel() { |
| 128 // Don't fire OnRendezvousResult() for client initiated cancel. | 129 // Don't fire OnRendezvousResult() for client initiated cancel. |
| 129 client_request_delegate_ = nullptr; | 130 client_request_delegate_ = nullptr; |
| 130 Reset(QUIC_STREAM_CANCELLED); | 131 Reset(QUIC_STREAM_CANCELLED); |
| 131 } | 132 } |
| 132 | 133 |
| 133 } // namespace net | 134 } // namespace net |
| OLD | NEW |