Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: net/http/bidirectional_stream.cc

Issue 1932853002: Log urls and headers in BIDIRECTIONAL_STREAM events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Misha's comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/http/bidirectional_stream.h" 5 #include "net/http/bidirectional_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "base/values.h"
16 #include "net/base/load_flags.h" 18 #include "net/base/load_flags.h"
17 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
18 #include "net/http/bidirectional_stream_request_info.h" 20 #include "net/http/bidirectional_stream_request_info.h"
21 #include "net/http/http_log_util.h"
19 #include "net/http/http_network_session.h" 22 #include "net/http/http_network_session.h"
20 #include "net/http/http_response_headers.h" 23 #include "net/http/http_response_headers.h"
21 #include "net/http/http_stream.h" 24 #include "net/http/http_stream.h"
25 #include "net/log/net_log_capture_mode.h"
26 #include "net/spdy/spdy_header_block.h"
22 #include "net/spdy/spdy_http_utils.h" 27 #include "net/spdy/spdy_http_utils.h"
23 #include "net/ssl/ssl_cert_request_info.h" 28 #include "net/ssl/ssl_cert_request_info.h"
24 #include "net/ssl/ssl_config.h" 29 #include "net/ssl/ssl_config.h"
25 #include "url/gurl.h" 30 #include "url/gurl.h"
26 31
27 namespace net { 32 namespace net {
28 33
34 namespace {
35
36 std::unique_ptr<base::Value> NetLogHeadersCallback(
37 const SpdyHeaderBlock* headers,
38 NetLogCaptureMode capture_mode) {
39 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
40 dict->Set("headers", ElideSpdyHeaderBlockForNetLog(*headers, capture_mode));
41 return std::move(dict);
42 }
43
44 std::unique_ptr<base::Value> NetLogCallback(const GURL* url,
45 const std::string* method,
46 const HttpRequestHeaders* headers,
47 NetLogCaptureMode capture_mode) {
48 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
49 dict->SetString("url", url->possibly_invalid_spec());
50 dict->SetString("method", *method);
51 std::string empty;
52 std::unique_ptr<base::Value> headers_param(
53 headers->NetLogCallback(&empty, capture_mode));
54 dict->Set("headers", std::move(headers_param));
55 return std::move(dict);
56 }
57
58 } // namespace
59
29 BidirectionalStream::Delegate::Delegate() {} 60 BidirectionalStream::Delegate::Delegate() {}
30 61
31 void BidirectionalStream::Delegate::OnStreamReady() {} 62 void BidirectionalStream::Delegate::OnStreamReady() {}
32 63
33 BidirectionalStream::Delegate::~Delegate() {} 64 BidirectionalStream::Delegate::~Delegate() {}
34 65
35 BidirectionalStream::BidirectionalStream( 66 BidirectionalStream::BidirectionalStream(
36 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, 67 std::unique_ptr<BidirectionalStreamRequestInfo> request_info,
37 HttpNetworkSession* session, 68 HttpNetworkSession* session,
38 bool disable_auto_flush, 69 bool disable_auto_flush,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 http_request_info.extra_headers = request_info_->extra_headers; 109 http_request_info.extra_headers = request_info_->extra_headers;
79 stream_request_.reset( 110 stream_request_.reset(
80 session->http_stream_factory()->RequestBidirectionalStreamImpl( 111 session->http_stream_factory()->RequestBidirectionalStreamImpl(
81 http_request_info, request_info_->priority, server_ssl_config, 112 http_request_info, request_info_->priority, server_ssl_config,
82 server_ssl_config, this, net_log_)); 113 server_ssl_config, this, net_log_));
83 // Check that this call cannot fail to set a non-NULL |stream_request_|. 114 // Check that this call cannot fail to set a non-NULL |stream_request_|.
84 DCHECK(stream_request_); 115 DCHECK(stream_request_);
85 // Check that HttpStreamFactory does not invoke OnBidirectionalStreamImplReady 116 // Check that HttpStreamFactory does not invoke OnBidirectionalStreamImplReady
86 // synchronously. 117 // synchronously.
87 DCHECK(!stream_impl_); 118 DCHECK(!stream_impl_);
119 if (net_log_.IsCapturing()) {
120 net_log_.BeginEvent(
121 NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE,
122 base::Bind(&NetLogCallback, &request_info_->url, &request_info_->method,
123 base::Unretained(&request_info_->extra_headers)));
124 }
88 } 125 }
89 126
90 BidirectionalStream::~BidirectionalStream() { 127 BidirectionalStream::~BidirectionalStream() {
91 Cancel(); 128 Cancel();
129 if (net_log_.IsCapturing()) {
130 net_log_.EndEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE);
131 }
92 } 132 }
93 133
94 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { 134 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) {
95 DCHECK(stream_impl_); 135 DCHECK(stream_impl_);
96 136
97 int rv = stream_impl_->ReadData(buf, buf_len); 137 int rv = stream_impl_->ReadData(buf, buf_len);
98 if (rv > 0) { 138 if (rv > 0) {
99 net_log_.AddByteTransferEvent( 139 net_log_.AddByteTransferEvent(
100 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, buf->data()); 140 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, buf->data());
101 } else if (rv == ERR_IO_PENDING) { 141 } else if (rv == ERR_IO_PENDING) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 } 206 }
167 207
168 void BidirectionalStream::OnHeadersReceived( 208 void BidirectionalStream::OnHeadersReceived(
169 const SpdyHeaderBlock& response_headers) { 209 const SpdyHeaderBlock& response_headers) {
170 HttpResponseInfo response_info; 210 HttpResponseInfo response_info;
171 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) { 211 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) {
172 DLOG(WARNING) << "Invalid headers"; 212 DLOG(WARNING) << "Invalid headers";
173 delegate_->OnFailed(ERR_FAILED); 213 delegate_->OnFailed(ERR_FAILED);
174 return; 214 return;
175 } 215 }
176 216 if (net_log_.IsCapturing()) {
217 net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_HEADERS,
218 base::Bind(&NetLogHeadersCallback, &response_headers));
219 }
177 session_->http_stream_factory()->ProcessAlternativeServices( 220 session_->http_stream_factory()->ProcessAlternativeServices(
178 session_, response_info.headers.get(), 221 session_, response_info.headers.get(),
179 url::SchemeHostPort(request_info_->url)); 222 url::SchemeHostPort(request_info_->url));
180 delegate_->OnHeadersReceived(response_headers); 223 delegate_->OnHeadersReceived(response_headers);
181 } 224 }
182 225
183 void BidirectionalStream::OnDataRead(int bytes_read) { 226 void BidirectionalStream::OnDataRead(int bytes_read) {
184 DCHECK(read_buffer_); 227 DCHECK(read_buffer_);
185 228
186 net_log_.AddByteTransferEvent( 229 if (net_log_.IsCapturing()) {
187 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, bytes_read, 230 net_log_.AddByteTransferEvent(
188 read_buffer_->data()); 231 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, bytes_read,
232 read_buffer_->data());
233 }
189 read_buffer_ = nullptr; 234 read_buffer_ = nullptr;
190 delegate_->OnDataRead(bytes_read); 235 delegate_->OnDataRead(bytes_read);
191 } 236 }
192 237
193 void BidirectionalStream::OnDataSent() { 238 void BidirectionalStream::OnDataSent() {
194 DCHECK(!write_buffer_list_.empty()); 239 DCHECK(!write_buffer_list_.empty());
195 DCHECK_EQ(write_buffer_list_.size(), write_buffer_len_list_.size()); 240 DCHECK_EQ(write_buffer_list_.size(), write_buffer_len_list_.size());
196 241
197 for (size_t i = 0; i < write_buffer_list_.size(); ++i) { 242 if (net_log_.IsCapturing()) {
198 net_log_.AddByteTransferEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT, 243 for (size_t i = 0; i < write_buffer_list_.size(); ++i) {
199 write_buffer_len_list_[i], 244 net_log_.AddByteTransferEvent(
200 write_buffer_list_[i]->data()); 245 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT,
246 write_buffer_len_list_[i], write_buffer_list_[i]->data());
247 }
201 } 248 }
202 write_buffer_list_.clear(); 249 write_buffer_list_.clear();
203 write_buffer_len_list_.clear(); 250 write_buffer_len_list_.clear();
204 delegate_->OnDataSent(); 251 delegate_->OnDataSent();
205 } 252 }
206 253
207 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { 254 void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) {
255 if (net_log_.IsCapturing()) {
256 net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_TRAILERS,
257 base::Bind(&NetLogHeadersCallback, &trailers));
258 }
208 delegate_->OnTrailersReceived(trailers); 259 delegate_->OnTrailersReceived(trailers);
209 } 260 }
210 261
211 void BidirectionalStream::OnFailed(int status) { 262 void BidirectionalStream::OnFailed(int status) {
212 delegate_->OnFailed(status); 263 delegate_->OnFailed(status);
213 } 264 }
214 265
215 void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config, 266 void BidirectionalStream::OnStreamReady(const SSLConfig& used_ssl_config,
216 const ProxyInfo& used_proxy_info, 267 const ProxyInfo& used_proxy_info,
217 HttpStream* stream) { 268 HttpStream* stream) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 const ProxyInfo& used_proxy_info, 331 const ProxyInfo& used_proxy_info,
281 HttpStream* stream) { 332 HttpStream* stream) {
282 DCHECK(stream_request_); 333 DCHECK(stream_request_);
283 334
284 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); 335 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE);
285 } 336 }
286 337
287 void BidirectionalStream::OnQuicBroken() {} 338 void BidirectionalStream::OnQuicBroken() {}
288 339
289 } // namespace net 340 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/bidirectional_stream_unittest.cc » ('j') | net/http/bidirectional_stream_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698