/src/mozilla-central/netwerk/protocol/http/nsHttpConnectionInfo.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* vim: set sw=4 ts=8 et tw=80 : */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef nsHttpConnectionInfo_h__ |
8 | | #define nsHttpConnectionInfo_h__ |
9 | | |
10 | | #include "nsHttp.h" |
11 | | #include "nsProxyInfo.h" |
12 | | #include "nsCOMPtr.h" |
13 | | #include "nsStringFwd.h" |
14 | | #include "mozilla/Logging.h" |
15 | | #include "mozilla/BasePrincipal.h" |
16 | | #include "ARefBase.h" |
17 | | |
18 | | //----------------------------------------------------------------------------- |
19 | | // nsHttpConnectionInfo - holds the properties of a connection |
20 | | //----------------------------------------------------------------------------- |
21 | | |
22 | | // http:// uris through a proxy will all share the same CI, because they can |
23 | | // all use the same connection. (modulo pb and anonymous flags). They just use |
24 | | // the proxy as the origin host name. |
25 | | // however, https:// uris tunnel through the proxy so they will have different |
26 | | // CIs - the CI reflects both the proxy and the origin. |
27 | | // however, proxy conenctions made with http/2 (or spdy) can tunnel to the origin |
28 | | // and multiplex non tunneled transactions at the same time, so they have a |
29 | | // special wildcard CI that accepts all origins through that proxy. |
30 | | |
31 | | namespace mozilla { namespace net { |
32 | | |
33 | | extern LazyLogModule gHttpLog; |
34 | | |
35 | | class nsHttpConnectionInfo final : public ARefBase |
36 | | { |
37 | | public: |
38 | | nsHttpConnectionInfo(const nsACString &originHost, |
39 | | int32_t originPort, |
40 | | const nsACString &npnToken, |
41 | | const nsACString &username, |
42 | | nsProxyInfo *proxyInfo, |
43 | | const OriginAttributes &originAttributes, |
44 | | bool endToEndSSL = false); |
45 | | |
46 | | // this version must use TLS and you may supply separate |
47 | | // connection (aka routing) information than the authenticated |
48 | | // origin information |
49 | | nsHttpConnectionInfo(const nsACString &originHost, |
50 | | int32_t originPort, |
51 | | const nsACString &npnToken, |
52 | | const nsACString &username, |
53 | | nsProxyInfo *proxyInfo, |
54 | | const OriginAttributes &originAttributes, |
55 | | const nsACString &routedHost, |
56 | | int32_t routedPort); |
57 | | |
58 | | private: |
59 | | virtual ~nsHttpConnectionInfo() |
60 | 0 | { |
61 | 0 | MOZ_LOG(gHttpLog, LogLevel::Debug, ("Destroying nsHttpConnectionInfo @%p\n", this)); |
62 | 0 | } |
63 | | |
64 | | void BuildHashKey(); |
65 | | |
66 | | public: |
67 | 0 | const nsCString& HashKey() const { return mHashKey; } |
68 | | |
69 | 0 | const nsCString &GetOrigin() const { return mOrigin; } |
70 | 0 | const char *Origin() const { return mOrigin.get(); } |
71 | 0 | int32_t OriginPort() const { return mOriginPort; } |
72 | | |
73 | 0 | const nsCString &GetRoutedHost() const { return mRoutedHost; } |
74 | 0 | const char *RoutedHost() const { return mRoutedHost.get(); } |
75 | 0 | int32_t RoutedPort() const { return mRoutedPort; } |
76 | | |
77 | | // OK to treat these as an infalible allocation |
78 | | nsHttpConnectionInfo* Clone() const; |
79 | | void CloneAsDirectRoute(nsHttpConnectionInfo **outParam); |
80 | | MOZ_MUST_USE nsresult CreateWildCard(nsHttpConnectionInfo **outParam); |
81 | | |
82 | 0 | const char *ProxyHost() const { return mProxyInfo ? mProxyInfo->Host().get() : nullptr; } |
83 | 0 | int32_t ProxyPort() const { return mProxyInfo ? mProxyInfo->Port() : -1; } |
84 | 0 | const char *ProxyType() const { return mProxyInfo ? mProxyInfo->Type() : nullptr; } |
85 | 0 | const char *ProxyUsername() const { return mProxyInfo ? mProxyInfo->Username().get() : nullptr; } |
86 | 0 | const char *ProxyPassword() const { return mProxyInfo ? mProxyInfo->Password().get() : nullptr; } |
87 | | |
88 | | // Compare this connection info to another... |
89 | | // Two connections are 'equal' if they end up talking the same |
90 | | // protocol to the same server. This is needed to properly manage |
91 | | // persistent connections to proxies |
92 | | // Note that we don't care about transparent proxies - |
93 | | // it doesn't matter if we're talking via socks or not, since |
94 | | // a request will end up at the same host. |
95 | | bool Equals(const nsHttpConnectionInfo *info) |
96 | 0 | { |
97 | 0 | return mHashKey.Equals(info->HashKey()); |
98 | 0 | } |
99 | | |
100 | 0 | const char *Username() const { return mUsername.get(); } |
101 | 0 | nsProxyInfo *ProxyInfo() const { return mProxyInfo; } |
102 | 0 | int32_t DefaultPort() const { return mEndToEndSSL ? NS_HTTPS_DEFAULT_PORT : NS_HTTP_DEFAULT_PORT; } |
103 | | void SetAnonymous(bool anon) |
104 | 0 | { mHashKey.SetCharAt(anon ? 'A' : '.', 2); } |
105 | 0 | bool GetAnonymous() const { return mHashKey.CharAt(2) == 'A'; } |
106 | 0 | void SetPrivate(bool priv) { mHashKey.SetCharAt(priv ? 'P' : '.', 3); } |
107 | 0 | bool GetPrivate() const { return mHashKey.CharAt(3) == 'P'; } |
108 | | void SetInsecureScheme(bool insecureScheme) |
109 | 0 | { mHashKey.SetCharAt(insecureScheme ? 'I' : '.', 4); } |
110 | 0 | bool GetInsecureScheme() const { return mHashKey.CharAt(4) == 'I'; } |
111 | | |
112 | | void SetNoSpdy(bool aNoSpdy) |
113 | 0 | { mHashKey.SetCharAt(aNoSpdy ? 'X' : '.', 5); } |
114 | 0 | bool GetNoSpdy() const { return mHashKey.CharAt(5) == 'X'; } |
115 | | |
116 | | void SetBeConservative(bool aBeConservative) |
117 | 0 | { mHashKey.SetCharAt(aBeConservative ? 'C' : '.', 6); } |
118 | 0 | bool GetBeConservative() const { return mHashKey.CharAt(6) == 'C'; } |
119 | | |
120 | | void SetTlsFlags(uint32_t aTlsFlags); |
121 | 0 | uint32_t GetTlsFlags() const { return mTlsFlags; } |
122 | | |
123 | | // TrrUsed means that this connection is used to send TRR requests over |
124 | 0 | void SetTrrUsed(bool aUsed) { mTrrUsed = aUsed; } |
125 | 0 | bool GetTrrUsed() const { return mTrrUsed; } |
126 | | |
127 | | // SetTrrDisabled means don't use TRR to resolve host names for this |
128 | | // connection |
129 | | void SetTrrDisabled(bool aNoTrr); |
130 | 0 | bool GetTrrDisabled() const { return mTrrDisabled; } |
131 | | |
132 | 0 | const nsCString &GetNPNToken() { return mNPNToken; } |
133 | 0 | const nsCString &GetUsername() { return mUsername; } |
134 | | |
135 | 0 | const OriginAttributes &GetOriginAttributes() { return mOriginAttributes; } |
136 | | |
137 | | // Returns true for any kind of proxy (http, socks, https, etc..) |
138 | | bool UsingProxy(); |
139 | | |
140 | | // Returns true when proxying over HTTP or HTTPS |
141 | 0 | bool UsingHttpProxy() const { return mUsingHttpProxy || mUsingHttpsProxy; } |
142 | | |
143 | | // Returns true when proxying over HTTPS |
144 | 0 | bool UsingHttpsProxy() const { return mUsingHttpsProxy; } |
145 | | |
146 | | // Returns true when a resource is in SSL end to end (e.g. https:// uri) |
147 | 0 | bool EndToEndSSL() const { return mEndToEndSSL; } |
148 | | |
149 | | // Returns true when at least first hop is SSL (e.g. proxy over https or https uri) |
150 | 0 | bool FirstHopSSL() const { return mEndToEndSSL || mUsingHttpsProxy; } |
151 | | |
152 | | // Returns true when CONNECT is used to tunnel through the proxy (e.g. https:// or ws://) |
153 | 0 | bool UsingConnect() const { return mUsingConnect; } |
154 | | |
155 | | // Returns true when origin/proxy is an RFC1918 literal. |
156 | | bool HostIsLocalIPLiteral() const; |
157 | | |
158 | 0 | bool GetLessThanTls13() const { return mLessThanTls13; } |
159 | | void SetLessThanTls13(bool aLessThanTls13) |
160 | 0 | { |
161 | 0 | mLessThanTls13 = aLessThanTls13; |
162 | 0 | } |
163 | | |
164 | | private: |
165 | | void Init(const nsACString &host, |
166 | | int32_t port, |
167 | | const nsACString &npnToken, |
168 | | const nsACString &username, |
169 | | nsProxyInfo* proxyInfo, |
170 | | const OriginAttributes &originAttributes, |
171 | | bool EndToEndSSL); |
172 | | void SetOriginServer(const nsACString &host, int32_t port); |
173 | | |
174 | | nsCString mOrigin; |
175 | | int32_t mOriginPort; |
176 | | nsCString mRoutedHost; |
177 | | int32_t mRoutedPort; |
178 | | |
179 | | nsCString mHashKey; |
180 | | nsCString mUsername; |
181 | | nsCOMPtr<nsProxyInfo> mProxyInfo; |
182 | | bool mUsingHttpProxy; |
183 | | bool mUsingHttpsProxy; |
184 | | bool mEndToEndSSL; |
185 | | bool mUsingConnect; // if will use CONNECT with http proxy |
186 | | nsCString mNPNToken; |
187 | | OriginAttributes mOriginAttributes; |
188 | | |
189 | | uint32_t mTlsFlags; |
190 | | uint16_t mTrrUsed : 1; |
191 | | uint16_t mTrrDisabled : 1; |
192 | | |
193 | | bool mLessThanTls13; // This will be set to true if we negotiate less than |
194 | | // tls1.3. If the tls version is till not know or it |
195 | | // is 1.3 or greater the value will be false. |
196 | | |
197 | | // for RefPtr |
198 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHttpConnectionInfo, override) |
199 | | }; |
200 | | |
201 | | } // namespace net |
202 | | } // namespace mozilla |
203 | | |
204 | | #endif // nsHttpConnectionInfo_h__ |