spdy_log_util.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2017 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. #include "net/spdy/spdy_log_util.h"
  5. #include <utility>
  6. #include "base/strings/abseil_string_conversions.h"
  7. #include "base/strings/strcat.h"
  8. #include "base/strings/string_number_conversions.h"
  9. #include "base/strings/string_piece.h"
  10. #include "base/values.h"
  11. #include "net/http/http_log_util.h"
  12. #include "net/log/net_log_values.h"
  13. namespace net {
  14. base::Value ElideGoAwayDebugDataForNetLog(NetLogCaptureMode capture_mode,
  15. base::StringPiece debug_data) {
  16. if (NetLogCaptureIncludesSensitive(capture_mode))
  17. return NetLogStringValue(debug_data);
  18. return NetLogStringValue(base::StrCat(
  19. {"[", base::NumberToString(debug_data.size()), " bytes were stripped]"}));
  20. }
  21. base::Value::List ElideHttp2HeaderBlockForNetLog(
  22. const spdy::Http2HeaderBlock& headers,
  23. NetLogCaptureMode capture_mode) {
  24. base::Value::List headers_list;
  25. for (const auto& header : headers) {
  26. base::StringPiece key = base::StringViewToStringPiece(header.first);
  27. base::StringPiece value = base::StringViewToStringPiece(header.second);
  28. headers_list.Append(NetLogStringValue(
  29. base::StrCat({key, ": ",
  30. ElideHeaderValueForNetLog(capture_mode, std::string(key),
  31. std::string(value))})));
  32. }
  33. return headers_list;
  34. }
  35. base::Value Http2HeaderBlockNetLogParams(const spdy::Http2HeaderBlock* headers,
  36. NetLogCaptureMode capture_mode) {
  37. base::Value::Dict dict;
  38. dict.Set("headers", ElideHttp2HeaderBlockForNetLog(*headers, capture_mode));
  39. return base::Value(std::move(dict));
  40. }
  41. } // namespace net