| 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_spdy_client_stream.h" | 5 #include "net/tools/quic/quic_spdy_client_stream.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | |
| 10 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 11 #include "net/quic/core/quic_alarm.h" | 10 #include "net/quic/core/quic_alarm.h" |
| 12 #include "net/quic/core/quic_client_promised_info.h" | 11 #include "net/quic/core/quic_client_promised_info.h" |
| 13 #include "net/quic/core/spdy_utils.h" | 12 #include "net/quic/core/spdy_utils.h" |
| 13 #include "net/quic/platform/api/quic_logging.h" |
| 14 #include "net/spdy/spdy_protocol.h" | 14 #include "net/spdy/spdy_protocol.h" |
| 15 #include "net/tools/quic/quic_client_session.h" | 15 #include "net/tools/quic/quic_client_session.h" |
| 16 | 16 |
| 17 using base::StringPiece; | 17 using base::StringPiece; |
| 18 using std::string; | 18 using std::string; |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 QuicSpdyClientStream::QuicSpdyClientStream(QuicStreamId id, | 22 QuicSpdyClientStream::QuicSpdyClientStream(QuicStreamId id, |
| 23 QuicClientSession* session) | 23 QuicClientSession* session) |
| 24 : QuicSpdyStream(id, session), | 24 : QuicSpdyStream(id, session), |
| 25 content_length_(-1), | 25 content_length_(-1), |
| 26 response_code_(0), | 26 response_code_(0), |
| 27 header_bytes_read_(0), | 27 header_bytes_read_(0), |
| 28 header_bytes_written_(0), | 28 header_bytes_written_(0), |
| 29 session_(session), | 29 session_(session), |
| 30 has_preliminary_headers_(false) {} | 30 has_preliminary_headers_(false) {} |
| 31 | 31 |
| 32 QuicSpdyClientStream::~QuicSpdyClientStream() {} | 32 QuicSpdyClientStream::~QuicSpdyClientStream() {} |
| 33 | 33 |
| 34 void QuicSpdyClientStream::OnStreamFrame(const QuicStreamFrame& frame) { | 34 void QuicSpdyClientStream::OnStreamFrame(const QuicStreamFrame& frame) { |
| 35 if (!allow_bidirectional_data() && !write_side_closed()) { | 35 if (!allow_bidirectional_data() && !write_side_closed()) { |
| 36 DVLOG(1) << "Got a response before the request was complete. " | 36 QUIC_DLOG(INFO) << "Got a response before the request was complete. " |
| 37 << "Aborting request."; | 37 << "Aborting request."; |
| 38 CloseWriteSide(); | 38 CloseWriteSide(); |
| 39 } | 39 } |
| 40 QuicSpdyStream::OnStreamFrame(frame); | 40 QuicSpdyStream::OnStreamFrame(frame); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void QuicSpdyClientStream::OnInitialHeadersComplete( | 43 void QuicSpdyClientStream::OnInitialHeadersComplete( |
| 44 bool fin, | 44 bool fin, |
| 45 size_t frame_len, | 45 size_t frame_len, |
| 46 const QuicHeaderList& header_list) { | 46 const QuicHeaderList& header_list) { |
| 47 QuicSpdyStream::OnInitialHeadersComplete(fin, frame_len, header_list); | 47 QuicSpdyStream::OnInitialHeadersComplete(fin, frame_len, header_list); |
| 48 | 48 |
| 49 DCHECK(headers_decompressed()); | 49 DCHECK(headers_decompressed()); |
| 50 header_bytes_read_ += frame_len; | 50 header_bytes_read_ += frame_len; |
| 51 if (!SpdyUtils::CopyAndValidateHeaders(header_list, &content_length_, | 51 if (!SpdyUtils::CopyAndValidateHeaders(header_list, &content_length_, |
| 52 &response_headers_)) { | 52 &response_headers_)) { |
| 53 DLOG(ERROR) << "Failed to parse header list: " << header_list.DebugString(); | 53 QUIC_DLOG(ERROR) << "Failed to parse header list: " |
| 54 << header_list.DebugString(); |
| 54 Reset(QUIC_BAD_APPLICATION_PAYLOAD); | 55 Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
| 55 return; | 56 return; |
| 56 } | 57 } |
| 57 | 58 |
| 58 if (!ParseHeaderStatusCode(response_headers_, &response_code_)) { | 59 if (!ParseHeaderStatusCode(response_headers_, &response_code_)) { |
| 59 DLOG(ERROR) << "Received invalid response code: " | 60 QUIC_DLOG(ERROR) << "Received invalid response code: " |
| 60 << response_headers_[":status"].as_string(); | 61 << response_headers_[":status"].as_string(); |
| 61 Reset(QUIC_BAD_APPLICATION_PAYLOAD); | 62 Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
| 62 return; | 63 return; |
| 63 } | 64 } |
| 64 | 65 |
| 65 if (FLAGS_quic_restart_flag_quic_supports_100_continue && | 66 if (FLAGS_quic_restart_flag_quic_supports_100_continue && |
| 66 response_code_ == 100 && !has_preliminary_headers_) { | 67 response_code_ == 100 && !has_preliminary_headers_) { |
| 67 // These are preliminary 100 Continue headers, not the actual response | 68 // These are preliminary 100 Continue headers, not the actual response |
| 68 // headers. | 69 // headers. |
| 69 set_headers_decompressed(false); | 70 set_headers_decompressed(false); |
| 70 has_preliminary_headers_ = true; | 71 has_preliminary_headers_ = true; |
| 71 preliminary_headers_ = std::move(response_headers_); | 72 preliminary_headers_ = std::move(response_headers_); |
| 72 } | 73 } |
| 73 | 74 |
| 74 ConsumeHeaderList(); | 75 ConsumeHeaderList(); |
| 75 DVLOG(1) << "headers complete for stream " << id(); | 76 QUIC_DVLOG(1) << "headers complete for stream " << id(); |
| 76 | 77 |
| 77 session_->OnInitialHeadersComplete(id(), response_headers_); | 78 session_->OnInitialHeadersComplete(id(), response_headers_); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void QuicSpdyClientStream::OnTrailingHeadersComplete( | 81 void QuicSpdyClientStream::OnTrailingHeadersComplete( |
| 81 bool fin, | 82 bool fin, |
| 82 size_t frame_len, | 83 size_t frame_len, |
| 83 const QuicHeaderList& header_list) { | 84 const QuicHeaderList& header_list) { |
| 84 QuicSpdyStream::OnTrailingHeadersComplete(fin, frame_len, header_list); | 85 QuicSpdyStream::OnTrailingHeadersComplete(fin, frame_len, header_list); |
| 85 MarkTrailersConsumed(); | 86 MarkTrailersConsumed(); |
| 86 } | 87 } |
| 87 | 88 |
| 88 void QuicSpdyClientStream::OnPromiseHeaderList( | 89 void QuicSpdyClientStream::OnPromiseHeaderList( |
| 89 QuicStreamId promised_id, | 90 QuicStreamId promised_id, |
| 90 size_t frame_len, | 91 size_t frame_len, |
| 91 const QuicHeaderList& header_list) { | 92 const QuicHeaderList& header_list) { |
| 92 header_bytes_read_ += frame_len; | 93 header_bytes_read_ += frame_len; |
| 93 int64_t content_length = -1; | 94 int64_t content_length = -1; |
| 94 SpdyHeaderBlock promise_headers; | 95 SpdyHeaderBlock promise_headers; |
| 95 if (!SpdyUtils::CopyAndValidateHeaders(header_list, &content_length, | 96 if (!SpdyUtils::CopyAndValidateHeaders(header_list, &content_length, |
| 96 &promise_headers)) { | 97 &promise_headers)) { |
| 97 DLOG(ERROR) << "Failed to parse promise headers: " | 98 QUIC_DLOG(ERROR) << "Failed to parse promise headers: " |
| 98 << header_list.DebugString(); | 99 << header_list.DebugString(); |
| 99 Reset(QUIC_BAD_APPLICATION_PAYLOAD); | 100 Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
| 100 return; | 101 return; |
| 101 } | 102 } |
| 102 | 103 |
| 103 session_->HandlePromised(id(), promised_id, promise_headers); | 104 session_->HandlePromised(id(), promised_id, promise_headers); |
| 104 if (visitor() != nullptr) { | 105 if (visitor() != nullptr) { |
| 105 visitor()->OnPromiseHeadersComplete(promised_id, frame_len); | 106 visitor()->OnPromiseHeadersComplete(promised_id, frame_len); |
| 106 } | 107 } |
| 107 } | 108 } |
| 108 | 109 |
| 109 void QuicSpdyClientStream::OnDataAvailable() { | 110 void QuicSpdyClientStream::OnDataAvailable() { |
| 110 // For push streams, visitor will not be set until the rendezvous | 111 // For push streams, visitor will not be set until the rendezvous |
| 111 // between server promise and client request is complete. | 112 // between server promise and client request is complete. |
| 112 if (visitor() == nullptr) | 113 if (visitor() == nullptr) |
| 113 return; | 114 return; |
| 114 | 115 |
| 115 while (HasBytesToRead()) { | 116 while (HasBytesToRead()) { |
| 116 struct iovec iov; | 117 struct iovec iov; |
| 117 if (GetReadableRegions(&iov, 1) == 0) { | 118 if (GetReadableRegions(&iov, 1) == 0) { |
| 118 // No more data to read. | 119 // No more data to read. |
| 119 break; | 120 break; |
| 120 } | 121 } |
| 121 DVLOG(1) << "Client processed " << iov.iov_len << " bytes for stream " | 122 QUIC_DVLOG(1) << "Client processed " << iov.iov_len << " bytes for stream " |
| 122 << id(); | 123 << id(); |
| 123 data_.append(static_cast<char*>(iov.iov_base), iov.iov_len); | 124 data_.append(static_cast<char*>(iov.iov_base), iov.iov_len); |
| 124 | 125 |
| 125 if (content_length_ >= 0 && | 126 if (content_length_ >= 0 && |
| 126 data_.size() > static_cast<uint64_t>(content_length_)) { | 127 data_.size() > static_cast<uint64_t>(content_length_)) { |
| 127 DLOG(ERROR) << "Invalid content length (" << content_length_ | 128 QUIC_DLOG(ERROR) << "Invalid content length (" << content_length_ |
| 128 << ") with data of size " << data_.size(); | 129 << ") with data of size " << data_.size(); |
| 129 Reset(QUIC_BAD_APPLICATION_PAYLOAD); | 130 Reset(QUIC_BAD_APPLICATION_PAYLOAD); |
| 130 return; | 131 return; |
| 131 } | 132 } |
| 132 MarkConsumed(iov.iov_len); | 133 MarkConsumed(iov.iov_len); |
| 133 } | 134 } |
| 134 if (sequencer()->IsClosed()) { | 135 if (sequencer()->IsClosed()) { |
| 135 OnFinRead(); | 136 OnFinRead(); |
| 136 } else { | 137 } else { |
| 137 sequencer()->SetUnblocked(); | 138 sequencer()->SetUnblocked(); |
| 138 } | 139 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 150 bytes_sent += header_bytes_written_; | 151 bytes_sent += header_bytes_written_; |
| 151 | 152 |
| 152 if (!body.empty()) { | 153 if (!body.empty()) { |
| 153 WriteOrBufferData(body, fin, nullptr); | 154 WriteOrBufferData(body, fin, nullptr); |
| 154 } | 155 } |
| 155 | 156 |
| 156 return bytes_sent; | 157 return bytes_sent; |
| 157 } | 158 } |
| 158 | 159 |
| 159 } // namespace net | 160 } // namespace net |
| OLD | NEW |