xref: /aosp_15_r20/external/cronet/net/spdy/spdy_log_util.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "net/spdy/spdy_log_util.h"
6 
7 #include <string_view>
8 #include <utility>
9 
10 #include "base/strings/strcat.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/values.h"
13 #include "net/http/http_log_util.h"
14 #include "net/log/net_log_values.h"
15 
16 namespace net {
17 
ElideGoAwayDebugDataForNetLog(NetLogCaptureMode capture_mode,std::string_view debug_data)18 base::Value ElideGoAwayDebugDataForNetLog(NetLogCaptureMode capture_mode,
19                                           std::string_view debug_data) {
20   if (NetLogCaptureIncludesSensitive(capture_mode))
21     return NetLogStringValue(debug_data);
22 
23   return NetLogStringValue(base::StrCat(
24       {"[", base::NumberToString(debug_data.size()), " bytes were stripped]"}));
25 }
26 
ElideHttp2HeaderBlockForNetLog(const spdy::Http2HeaderBlock & headers,NetLogCaptureMode capture_mode)27 base::Value::List ElideHttp2HeaderBlockForNetLog(
28     const spdy::Http2HeaderBlock& headers,
29     NetLogCaptureMode capture_mode) {
30   base::Value::List headers_list;
31   for (const auto& [key, value] : headers) {
32     headers_list.Append(NetLogStringValue(
33         base::StrCat({key, ": ",
34                       ElideHeaderValueForNetLog(capture_mode, std::string(key),
35                                                 std::string(value))})));
36   }
37   return headers_list;
38 }
39 
Http2HeaderBlockNetLogParams(const spdy::Http2HeaderBlock * headers,NetLogCaptureMode capture_mode)40 base::Value::Dict Http2HeaderBlockNetLogParams(
41     const spdy::Http2HeaderBlock* headers,
42     NetLogCaptureMode capture_mode) {
43   return base::Value::Dict().Set(
44       "headers", ElideHttp2HeaderBlockForNetLog(*headers, capture_mode));
45 }
46 
47 }  // namespace net
48