netwerk/protocol/http/nsHttpConnectionInfo.h

branch
TOR_BUG_9701
changeset 11
deefc01c0e14
equal deleted inserted replaced
-1:000000000000 0:4c36950b1026
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
15 extern PRLogModuleInfo *gHttpLog;
16
17 //-----------------------------------------------------------------------------
18 // nsHttpConnectionInfo - holds the properties of a connection
19 //-----------------------------------------------------------------------------
20
21 namespace mozilla { namespace net {
22
23 class nsHttpConnectionInfo
24 {
25 public:
26 nsHttpConnectionInfo(const nsACString &host, int32_t port,
27 const nsACString &username,
28 nsProxyInfo* proxyInfo,
29 bool usingSSL=false);
30
31 virtual ~nsHttpConnectionInfo()
32 {
33 PR_LOG(gHttpLog, 4, ("Destroying nsHttpConnectionInfo @%x\n", this));
34 }
35
36 const nsAFlatCString &HashKey() const { return mHashKey; }
37
38 void SetOriginServer(const nsACString &host, int32_t port);
39
40 void SetOriginServer(const char *host, int32_t port)
41 {
42 SetOriginServer(nsDependentCString(host), port);
43 }
44
45 // OK to treat this as an infalible allocation
46 nsHttpConnectionInfo* Clone() const;
47
48 const char *ProxyHost() const { return mProxyInfo ? mProxyInfo->Host().get() : nullptr; }
49 int32_t ProxyPort() const { return mProxyInfo ? mProxyInfo->Port() : -1; }
50 const char *ProxyType() const { return mProxyInfo ? mProxyInfo->Type() : nullptr; }
51
52 // Compare this connection info to another...
53 // Two connections are 'equal' if they end up talking the same
54 // protocol to the same server. This is needed to properly manage
55 // persistent connections to proxies
56 // Note that we don't care about transparent proxies -
57 // it doesn't matter if we're talking via socks or not, since
58 // a request will end up at the same host.
59 bool Equals(const nsHttpConnectionInfo *info)
60 {
61 return mHashKey.Equals(info->HashKey());
62 }
63
64 const char *Host() const { return mHost.get(); }
65 int32_t Port() const { return mPort; }
66 const char *Username() const { return mUsername.get(); }
67 nsProxyInfo *ProxyInfo() { return mProxyInfo; }
68 bool UsingHttpProxy() const { return mUsingHttpProxy; }
69 bool UsingSSL() const { return mUsingSSL; }
70 bool UsingConnect() const { return mUsingConnect; }
71 int32_t DefaultPort() const { return mUsingSSL ? NS_HTTPS_DEFAULT_PORT : NS_HTTP_DEFAULT_PORT; }
72 void SetAnonymous(bool anon)
73 { mHashKey.SetCharAt(anon ? 'A' : '.', 2); }
74 bool GetAnonymous() const { return mHashKey.CharAt(2) == 'A'; }
75 void SetPrivate(bool priv) { mHashKey.SetCharAt(priv ? 'P' : '.', 3); }
76 bool GetPrivate() const { return mHashKey.CharAt(3) == 'P'; }
77
78 const nsCString &GetHost() { return mHost; }
79
80 // Returns true for any kind of proxy (http, socks, etc..)
81 bool UsingProxy();
82
83 // Returns true when mHost is an RFC1918 literal.
84 bool HostIsLocalIPLiteral() const;
85
86 private:
87 nsCString mHashKey;
88 nsCString mHost;
89 int32_t mPort;
90 nsCString mUsername;
91 nsCOMPtr<nsProxyInfo> mProxyInfo;
92 bool mUsingHttpProxy;
93 bool mUsingSSL;
94 bool mUsingConnect; // if will use CONNECT with http proxy
95
96 // for nsRefPtr
97 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHttpConnectionInfo)
98 };
99
100 }} // namespace mozilla::net
101
102 #endif // nsHttpConnectionInfo_h__

mercurial