2013-06-22 20:01:06 +04: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 15:12:37 +04: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/. */
|
2001-10-02 04:31:30 +04:00
|
|
|
|
|
|
|
#ifndef nsHttpConnectionInfo_h__
|
|
|
|
#define nsHttpConnectionInfo_h__
|
|
|
|
|
|
|
|
#include "nsHttp.h"
|
2005-03-25 06:41:33 +03:00
|
|
|
#include "nsProxyInfo.h"
|
2001-10-02 04:31:30 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2013-09-23 07:35:52 +04:00
|
|
|
#include "nsStringFwd.h"
|
2001-10-02 04:31:30 +04:00
|
|
|
|
2013-06-22 20:01:06 +04:00
|
|
|
extern PRLogModuleInfo *gHttpLog;
|
|
|
|
|
2001-10-02 04:31:30 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpConnectionInfo - holds the properties of a connection
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsHttpConnectionInfo
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 19:56:38 +04:00
|
|
|
nsHttpConnectionInfo(const nsACString &host, int32_t port,
|
2005-03-25 06:41:33 +03:00
|
|
|
nsProxyInfo* proxyInfo,
|
2013-06-22 20:01:06 +04:00
|
|
|
bool usingSSL=false);
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2001-10-02 04:31:30 +04:00
|
|
|
~nsHttpConnectionInfo()
|
|
|
|
{
|
2013-06-22 20:01:06 +04:00
|
|
|
PR_LOG(gHttpLog, 4, ("Destroying nsHttpConnectionInfo @%x\n", this));
|
2001-10-02 04:31:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt AddRef()
|
|
|
|
{
|
2013-07-19 06:24:13 +04:00
|
|
|
nsrefcnt n = ++mRef;
|
2008-02-22 04:09:42 +03:00
|
|
|
NS_LOG_ADDREF(this, n, "nsHttpConnectionInfo", sizeof(*this));
|
|
|
|
return n;
|
2001-10-02 04:31:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsrefcnt Release()
|
|
|
|
{
|
2013-07-19 06:24:13 +04:00
|
|
|
nsrefcnt n = --mRef;
|
2008-02-22 04:09:42 +03:00
|
|
|
NS_LOG_RELEASE(this, n, "nsHttpConnectionInfo");
|
2001-10-02 04:31:30 +04:00
|
|
|
if (n == 0)
|
|
|
|
delete this;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
const nsAFlatCString &HashKey() const { return mHashKey; }
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetOriginServer(const nsACString &host, int32_t port);
|
2001-10-02 04:31:30 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void SetOriginServer(const char *host, int32_t port)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
SetOriginServer(nsDependentCString(host), port);
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2012-04-25 16:54:42 +04:00
|
|
|
// OK to treat this as an infalible allocation
|
2010-01-26 16:33:03 +03:00
|
|
|
nsHttpConnectionInfo* Clone() const;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
const char *ProxyHost() const { return mProxyInfo ? mProxyInfo->Host().get() : nullptr; }
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t ProxyPort() const { return mProxyInfo ? mProxyInfo->Port() : -1; }
|
2012-07-30 18:20:58 +04:00
|
|
|
const char *ProxyType() const { return mProxyInfo ? mProxyInfo->Type() : nullptr; }
|
2001-10-02 04:31:30 +04: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 17:30:42 +04:00
|
|
|
// Note that we don't care about transparent proxies -
|
2001-10-02 04:31:30 +04: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-29 10:19:26 +04:00
|
|
|
bool Equals(const nsHttpConnectionInfo *info)
|
2001-10-02 04:31:30 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
return mHashKey.Equals(info->HashKey());
|
2001-10-02 04:31:30 +04:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
const char *Host() const { return mHost.get(); }
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t Port() const { return mPort; }
|
2005-03-25 06:41:33 +03:00
|
|
|
nsProxyInfo *ProxyInfo() { return mProxyInfo; }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool UsingHttpProxy() const { return mUsingHttpProxy; }
|
|
|
|
bool UsingSSL() const { return mUsingSSL; }
|
2012-06-19 09:50:20 +04:00
|
|
|
bool UsingConnect() const { return mUsingConnect; }
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t DefaultPort() const { return mUsingSSL ? NS_HTTPS_DEFAULT_PORT : NS_HTTP_DEFAULT_PORT; }
|
2013-05-16 17:30:42 +04:00
|
|
|
void SetAnonymous(bool anon)
|
2010-01-26 16:33:03 +03:00
|
|
|
{ mHashKey.SetCharAt(anon ? 'A' : '.', 2); }
|
2012-05-24 19:31:53 +04: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-23 03:39:31 +04:00
|
|
|
|
2011-12-13 19:55:50 +04:00
|
|
|
const nsCString &GetHost() { return mHost; }
|
2011-05-13 21:53:27 +04:00
|
|
|
|
2012-10-27 23:24:19 +04:00
|
|
|
// Returns true for any kind of proxy (http, socks, etc..)
|
|
|
|
bool UsingProxy();
|
|
|
|
|
2001-10-02 04:31:30 +04:00
|
|
|
private:
|
2013-07-19 06:24:13 +04:00
|
|
|
mozilla::ThreadSafeAutoRefCnt mRef;
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCString mHashKey;
|
|
|
|
nsCString mHost;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mPort;
|
2005-03-25 06:41:33 +03:00
|
|
|
nsCOMPtr<nsProxyInfo> mProxyInfo;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mUsingHttpProxy;
|
|
|
|
bool mUsingSSL;
|
2012-06-19 09:50:20 +04:00
|
|
|
bool mUsingConnect; // if will use CONNECT with http proxy
|
2001-10-02 04:31:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsHttpConnectionInfo_h__
|