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