michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set sw=4 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsHttpConnectionInfo_h__ michael@0: #define nsHttpConnectionInfo_h__ michael@0: michael@0: #include "nsHttp.h" michael@0: #include "nsProxyInfo.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsStringFwd.h" michael@0: michael@0: extern PRLogModuleInfo *gHttpLog; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // nsHttpConnectionInfo - holds the properties of a connection michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: namespace mozilla { namespace net { michael@0: michael@0: class nsHttpConnectionInfo michael@0: { michael@0: public: michael@0: nsHttpConnectionInfo(const nsACString &host, int32_t port, michael@0: const nsACString &username, michael@0: nsProxyInfo* proxyInfo, michael@0: bool usingSSL=false); michael@0: michael@0: virtual ~nsHttpConnectionInfo() michael@0: { michael@0: PR_LOG(gHttpLog, 4, ("Destroying nsHttpConnectionInfo @%x\n", this)); michael@0: } michael@0: michael@0: const nsAFlatCString &HashKey() const { return mHashKey; } michael@0: michael@0: void SetOriginServer(const nsACString &host, int32_t port); michael@0: michael@0: void SetOriginServer(const char *host, int32_t port) michael@0: { michael@0: SetOriginServer(nsDependentCString(host), port); michael@0: } michael@0: michael@0: // OK to treat this as an infalible allocation michael@0: nsHttpConnectionInfo* Clone() const; michael@0: michael@0: const char *ProxyHost() const { return mProxyInfo ? mProxyInfo->Host().get() : nullptr; } michael@0: int32_t ProxyPort() const { return mProxyInfo ? mProxyInfo->Port() : -1; } michael@0: const char *ProxyType() const { return mProxyInfo ? mProxyInfo->Type() : nullptr; } michael@0: michael@0: // Compare this connection info to another... michael@0: // Two connections are 'equal' if they end up talking the same michael@0: // protocol to the same server. This is needed to properly manage michael@0: // persistent connections to proxies michael@0: // Note that we don't care about transparent proxies - michael@0: // it doesn't matter if we're talking via socks or not, since michael@0: // a request will end up at the same host. michael@0: bool Equals(const nsHttpConnectionInfo *info) michael@0: { michael@0: return mHashKey.Equals(info->HashKey()); michael@0: } michael@0: michael@0: const char *Host() const { return mHost.get(); } michael@0: int32_t Port() const { return mPort; } michael@0: const char *Username() const { return mUsername.get(); } michael@0: nsProxyInfo *ProxyInfo() { return mProxyInfo; } michael@0: bool UsingHttpProxy() const { return mUsingHttpProxy; } michael@0: bool UsingSSL() const { return mUsingSSL; } michael@0: bool UsingConnect() const { return mUsingConnect; } michael@0: int32_t DefaultPort() const { return mUsingSSL ? NS_HTTPS_DEFAULT_PORT : NS_HTTP_DEFAULT_PORT; } michael@0: void SetAnonymous(bool anon) michael@0: { mHashKey.SetCharAt(anon ? 'A' : '.', 2); } michael@0: bool GetAnonymous() const { return mHashKey.CharAt(2) == 'A'; } michael@0: void SetPrivate(bool priv) { mHashKey.SetCharAt(priv ? 'P' : '.', 3); } michael@0: bool GetPrivate() const { return mHashKey.CharAt(3) == 'P'; } michael@0: michael@0: const nsCString &GetHost() { return mHost; } michael@0: michael@0: // Returns true for any kind of proxy (http, socks, etc..) michael@0: bool UsingProxy(); michael@0: michael@0: // Returns true when mHost is an RFC1918 literal. michael@0: bool HostIsLocalIPLiteral() const; michael@0: michael@0: private: michael@0: nsCString mHashKey; michael@0: nsCString mHost; michael@0: int32_t mPort; michael@0: nsCString mUsername; michael@0: nsCOMPtr mProxyInfo; michael@0: bool mUsingHttpProxy; michael@0: bool mUsingSSL; michael@0: bool mUsingConnect; // if will use CONNECT with http proxy michael@0: michael@0: // for nsRefPtr michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHttpConnectionInfo) michael@0: }; michael@0: michael@0: }} // namespace mozilla::net michael@0: michael@0: #endif // nsHttpConnectionInfo_h__