transport_info.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2020 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. #ifndef NET_BASE_TRANSPORT_INFO_H_
  5. #define NET_BASE_TRANSPORT_INFO_H_
  6. #include <iosfwd>
  7. #include <string>
  8. #include "base/strings/string_piece.h"
  9. #include "net/base/ip_endpoint.h"
  10. #include "net/base/net_export.h"
  11. namespace net {
  12. // Specifies the type of a network transport over which a resource is loaded.
  13. enum class TransportType {
  14. // The transport was established directly to a peer.
  15. kDirect,
  16. // The transport was established to a proxy of some kind.
  17. kProxied,
  18. // The transport was "established" to a cache entry.
  19. kCached,
  20. // Same as `kCached`, but the resource was initially loaded through a proxy.
  21. kCachedFromProxy,
  22. };
  23. // Returns a string representation of the given transport type.
  24. // The returned StringPiece is static, has no lifetime restrictions.
  25. NET_EXPORT base::StringPiece TransportTypeToString(TransportType type);
  26. // Describes a network transport.
  27. struct NET_EXPORT TransportInfo {
  28. TransportInfo();
  29. TransportInfo(TransportType type_arg,
  30. IPEndPoint endpoint_arg,
  31. std::string accept_ch_frame_arg);
  32. TransportInfo(const TransportInfo&);
  33. ~TransportInfo();
  34. // Instances of this type are comparable for equality.
  35. bool operator==(const TransportInfo& other) const;
  36. bool operator!=(const TransportInfo& other) const;
  37. // Returns a string representation of this struct, suitable for debugging.
  38. std::string ToString() const;
  39. // The type of the transport.
  40. TransportType type = TransportType::kDirect;
  41. // If `type` is `kDirect`, then this identifies the peer endpoint.
  42. // If `type` is `kProxied`, then this identifies the proxy endpoint.
  43. // If `type` is `kCached`, then this identifies the peer endpoint from which
  44. // the resource was originally loaded.
  45. // If `type` is `kCachedFromProxy`, then this identifies the proxy endpoint
  46. // from which the resource was originally loaded.
  47. IPEndPoint endpoint;
  48. // The value of the ACCEPT_CH HTTP2/3 frame, as pulled in through ALPS.
  49. //
  50. // Invariant: if `type` is `kCached` or `kCachedFromProxy`, then this is
  51. // empty.
  52. std::string accept_ch_frame;
  53. };
  54. // Instances of these types are streamable for easier debugging.
  55. NET_EXPORT std::ostream& operator<<(std::ostream& out, TransportType type);
  56. NET_EXPORT std::ostream& operator<<(std::ostream& out,
  57. const TransportInfo& info);
  58. } // namespace net
  59. #endif // NET_BASE_TRANSPORT_INFO_H_