xref: /aosp_15_r20/external/cronet/net/spdy/multiplexed_session.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2016 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_SPDY_MULTIPLEXED_SESSION_H_
6 #define NET_SPDY_MULTIPLEXED_SESSION_H_
7 
8 #include <string_view>
9 
10 #include "net/base/ip_endpoint.h"
11 #include "net/base/net_errors.h"
12 #include "net/http/http_stream.h"
13 #include "net/ssl/ssl_info.h"
14 
15 namespace url {
16 class SchemeHostPort;
17 }
18 
19 namespace net {
20 
21 // Base class for SPDY and QUIC sessions.
22 class NET_EXPORT_PRIVATE MultiplexedSession {
23  public:
24   virtual ~MultiplexedSession() = default;
25 
26   // Fills SSL info in |ssl_info| and returns true when SSL is in use.
27   virtual bool GetSSLInfo(SSLInfo* ssl_info) const = 0;
28 
29   // Gets the remote endpoint of the socket that the HTTP stream is using, if
30   // any. Returns OK and fills in |endpoint| if it is available; returns an
31   // error and does not modify |endpoint| otherwise.
32   virtual int GetRemoteEndpoint(IPEndPoint* endpoint) = 0;
33 
34   // The value corresponding to |scheme_host_port| in the ACCEPT_CH frame
35   // received during TLS handshake via the ALPS extension, or the empty string
36   // if the server did not send one.  Unlike Accept-CH header fields received in
37   // HTTP responses, this value is available before any requests are made.
38   //
39   // Note that this uses url::SchemeHostPort instead of url::Origin because this
40   // is based around network authorities, as opposed to general RFC 6454
41   // origins.
42   virtual std::string_view GetAcceptChViaAlps(
43       const url::SchemeHostPort& scheme_host_port) const = 0;
44 };
45 
46 // A handle to a multiplexed session which will be valid even after the
47 // underlying session is deleted.
48 class NET_EXPORT_PRIVATE MultiplexedSessionHandle {
49  public:
50   explicit MultiplexedSessionHandle(base::WeakPtr<MultiplexedSession> session);
51   virtual ~MultiplexedSessionHandle();
52 
53   // Gets the remote endpoint of the socket that the HTTP stream is using, if
54   // any. Returns OK and fills in |endpoint| if it is available; returns an
55   // error and does not modify |endpoint| otherwise.
56   int GetRemoteEndpoint(IPEndPoint* endpoint);
57 
58   // Fills SSL info in |ssl_info| and returns true when SSL is in use.
59   bool GetSSLInfo(SSLInfo* ssl_info) const;
60 
61   // Caches SSL info from the underlying session.
62   void SaveSSLInfo();
63 
64   // The value corresponding to |scheme_host_port| in the ACCEPT_CH frame
65   // received during TLS handshake via the ALPS extension, or the empty string
66   // if the server did not send one or if the underlying session is not
67   // available.
68   //
69   // Note that this uses url::SchemeHostPort instead of url::Origin because this
70   // is based around network authorities, as opposed to general RFC 6454
71   // origins.
72   virtual std::string_view GetAcceptChViaAlps(
73       const url::SchemeHostPort& scheme_host_port) const;
74 
75  private:
76   base::WeakPtr<MultiplexedSession> session_;
77   SSLInfo ssl_info_;
78   bool has_ssl_info_;
79 };
80 
81 }  // namespace net
82 
83 #endif  // NET_SPDY_MULTIPLEXED_SESSION_H_
84