2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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
|
|
|
|
|
|
|
#include "nsHttpConnectionInfo.h"
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHttpConnectionInfo::SetOriginServer(const nsACString &host, int32_t port)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mHost = host;
|
|
|
|
mPort = port == -1 ? DefaultPort() : port;
|
|
|
|
|
|
|
|
//
|
|
|
|
// build hash key:
|
|
|
|
//
|
|
|
|
// the hash key uniquely identifies the connection type. two connections
|
2009-02-26 09:43:45 -08:00
|
|
|
// are "equal" if they end up talking the same protocol to the same server
|
|
|
|
// and are both used for anonymous or non-anonymous connection only;
|
|
|
|
// anonymity of the connection is setup later from nsHttpChannel::AsyncOpen
|
|
|
|
// where we know we use anonymous connection (LOAD_ANONYMOUS load flag)
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
|
|
|
|
const char *keyHost;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t keyPort;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-18 22:50:20 -07:00
|
|
|
if (mUsingHttpProxy && !mUsingConnect) {
|
2007-03-22 10:30:00 -07:00
|
|
|
keyHost = ProxyHost();
|
|
|
|
keyPort = ProxyPort();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
keyHost = Host();
|
|
|
|
keyPort = Port();
|
|
|
|
}
|
|
|
|
|
2012-05-24 08:31:53 -07:00
|
|
|
mHashKey.AssignLiteral("....");
|
2007-03-22 10:30:00 -07:00
|
|
|
mHashKey.Append(keyHost);
|
|
|
|
mHashKey.Append(':');
|
|
|
|
mHashKey.AppendInt(keyPort);
|
|
|
|
|
|
|
|
if (mUsingHttpProxy)
|
|
|
|
mHashKey.SetCharAt('P', 0);
|
|
|
|
if (mUsingSSL)
|
|
|
|
mHashKey.SetCharAt('S', 1);
|
|
|
|
|
|
|
|
// NOTE: for transparent proxies (e.g., SOCKS) we need to encode the proxy
|
2012-09-05 05:32:28 -07:00
|
|
|
// info in the hash key (this ensures that we will continue to speak the
|
2007-03-22 10:30:00 -07:00
|
|
|
// right protocol even if our proxy preferences change).
|
2012-09-05 05:34:43 -07:00
|
|
|
//
|
|
|
|
// NOTE: for SSL tunnels add the proxy information to the cache key.
|
|
|
|
// We cannot use the proxy as the host parameter (as we do for non SSL)
|
|
|
|
// because this is a single host tunnel, but we need to include the proxy
|
|
|
|
// information so that a change in proxy config will mean this connection
|
|
|
|
// is not reused
|
|
|
|
|
|
|
|
if ((!mUsingHttpProxy && ProxyHost()) ||
|
|
|
|
(mUsingHttpProxy && mUsingConnect)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mHashKey.AppendLiteral(" (");
|
|
|
|
mHashKey.Append(ProxyType());
|
2012-09-05 05:32:28 -07:00
|
|
|
mHashKey.Append(':');
|
|
|
|
mHashKey.Append(ProxyHost());
|
|
|
|
mHashKey.Append(':');
|
|
|
|
mHashKey.AppendInt(ProxyPort());
|
2007-03-22 10:30:00 -07:00
|
|
|
mHashKey.Append(')');
|
|
|
|
}
|
|
|
|
}
|
2010-01-26 05:33:03 -08:00
|
|
|
|
|
|
|
nsHttpConnectionInfo*
|
|
|
|
nsHttpConnectionInfo::Clone() const
|
|
|
|
{
|
|
|
|
nsHttpConnectionInfo* clone = new nsHttpConnectionInfo(mHost, mPort, mProxyInfo, mUsingSSL);
|
|
|
|
|
2012-05-24 08:31:53 -07:00
|
|
|
// Make sure the anonymous and private flags are transferred!
|
|
|
|
clone->SetAnonymous(GetAnonymous());
|
|
|
|
clone->SetPrivate(GetPrivate());
|
|
|
|
|
2010-01-26 05:33:03 -08:00
|
|
|
return clone;
|
|
|
|
}
|
2011-05-13 10:53:27 -07:00
|
|
|
|
2012-10-27 12:24:19 -07:00
|
|
|
bool
|
|
|
|
nsHttpConnectionInfo::UsingProxy()
|
|
|
|
{
|
|
|
|
if (!mProxyInfo)
|
|
|
|
return false;
|
|
|
|
return !mProxyInfo->IsDirect();
|
|
|
|
}
|
|
|
|
|