2013-06-22 09:01:06 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsHttpConnectionInfo_h__
|
|
|
|
#define nsHttpConnectionInfo_h__
|
|
|
|
|
|
|
|
#include "nsHttp.h"
|
|
|
|
#include "nsProxyInfo.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-09-22 20:35:52 -07:00
|
|
|
#include "nsStringFwd.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-06-22 09:01:06 -07:00
|
|
|
extern PRLogModuleInfo *gHttpLog;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpConnectionInfo - holds the properties of a connection
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-01-07 14:05:56 -08:00
|
|
|
namespace mozilla { namespace net {
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsHttpConnectionInfo
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHttpConnectionInfo(const nsACString &host, int32_t port,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsProxyInfo* proxyInfo,
|
2013-06-22 09:01:06 -07:00
|
|
|
bool usingSSL=false);
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2014-01-06 13:58:48 -08:00
|
|
|
virtual ~nsHttpConnectionInfo()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-06-22 09:01:06 -07:00
|
|
|
PR_LOG(gHttpLog, 4, ("Destroying nsHttpConnectionInfo @%x\n", this));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsAFlatCString &HashKey() const { return mHashKey; }
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetOriginServer(const nsACString &host, int32_t port);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void SetOriginServer(const char *host, int32_t port)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
SetOriginServer(nsDependentCString(host), port);
|
|
|
|
}
|
2013-05-16 06:30:42 -07:00
|
|
|
|
2012-04-25 05:54:42 -07:00
|
|
|
// OK to treat this as an infalible allocation
|
2010-01-26 05:33:03 -08:00
|
|
|
nsHttpConnectionInfo* Clone() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
const char *ProxyHost() const { return mProxyInfo ? mProxyInfo->Host().get() : nullptr; }
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t ProxyPort() const { return mProxyInfo ? mProxyInfo->Port() : -1; }
|
2012-07-30 07:20:58 -07:00
|
|
|
const char *ProxyType() const { return mProxyInfo ? mProxyInfo->Type() : nullptr; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Compare this connection info to another...
|
|
|
|
// Two connections are 'equal' if they end up talking the same
|
|
|
|
// protocol to the same server. This is needed to properly manage
|
|
|
|
// persistent connections to proxies
|
2013-05-16 06:30:42 -07:00
|
|
|
// Note that we don't care about transparent proxies -
|
2007-03-22 10:30:00 -07:00
|
|
|
// it doesn't matter if we're talking via socks or not, since
|
|
|
|
// a request will end up at the same host.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool Equals(const nsHttpConnectionInfo *info)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return mHashKey.Equals(info->HashKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Host() const { return mHost.get(); }
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t Port() const { return mPort; }
|
2007-03-22 10:30:00 -07:00
|
|
|
nsProxyInfo *ProxyInfo() { return mProxyInfo; }
|
2011-09-28 23:19:26 -07:00
|
|
|
bool UsingHttpProxy() const { return mUsingHttpProxy; }
|
|
|
|
bool UsingSSL() const { return mUsingSSL; }
|
2012-06-18 22:50:20 -07:00
|
|
|
bool UsingConnect() const { return mUsingConnect; }
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t DefaultPort() const { return mUsingSSL ? NS_HTTPS_DEFAULT_PORT : NS_HTTP_DEFAULT_PORT; }
|
2013-05-16 06:30:42 -07:00
|
|
|
void SetAnonymous(bool anon)
|
2010-01-26 05:33:03 -08:00
|
|
|
{ mHashKey.SetCharAt(anon ? 'A' : '.', 2); }
|
2012-05-24 08:31:53 -07:00
|
|
|
bool GetAnonymous() const { return mHashKey.CharAt(2) == 'A'; }
|
|
|
|
void SetPrivate(bool priv) { mHashKey.SetCharAt(priv ? 'P' : '.', 3); }
|
|
|
|
bool GetPrivate() const { return mHashKey.CharAt(3) == 'P'; }
|
2012-03-22 16:39:31 -07:00
|
|
|
|
2011-12-13 07:55:50 -08:00
|
|
|
const nsCString &GetHost() { return mHost; }
|
2011-05-13 10:53:27 -07:00
|
|
|
|
2012-10-27 12:24:19 -07:00
|
|
|
// Returns true for any kind of proxy (http, socks, etc..)
|
|
|
|
bool UsingProxy();
|
|
|
|
|
2013-11-10 22:59:40 -08:00
|
|
|
// Returns true when mHost is an RFC1918 literal.
|
|
|
|
bool HostIsLocalIPLiteral() const;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
nsCString mHashKey;
|
|
|
|
nsCString mHost;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mPort;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsProxyInfo> mProxyInfo;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mUsingHttpProxy;
|
|
|
|
bool mUsingSSL;
|
2012-06-18 22:50:20 -07:00
|
|
|
bool mUsingConnect; // if will use CONNECT with http proxy
|
2014-01-06 13:58:48 -08:00
|
|
|
|
|
|
|
// for nsRefPtr
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHttpConnectionInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2014-01-07 14:05:56 -08:00
|
|
|
}} // namespace mozilla::net
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif // nsHttpConnectionInfo_h__
|