2013-06-22 16:01:06 +00: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 11:12:37 +00: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/. */
|
2005-06-11 13:12:55 +00:00
|
|
|
|
2013-06-22 16:01:06 +00:00
|
|
|
// HttpLog.h should generally be included first
|
|
|
|
#include "HttpLog.h"
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
#include "nsHttpConnectionInfo.h"
|
2013-11-11 06:59:40 +00:00
|
|
|
#include "mozilla/net/DNS.h"
|
|
|
|
#include "prnetdb.h"
|
|
|
|
|
|
|
|
using namespace mozilla::net;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2013-06-22 16:01:06 +00:00
|
|
|
nsHttpConnectionInfo::nsHttpConnectionInfo(const nsACString &host, int32_t port,
|
|
|
|
nsProxyInfo* proxyInfo,
|
|
|
|
bool usingSSL)
|
2014-01-06 21:58:48 +00:00
|
|
|
: mProxyInfo(proxyInfo)
|
2013-06-22 16:01:06 +00:00
|
|
|
, mUsingSSL(usingSSL)
|
|
|
|
, mUsingConnect(false)
|
|
|
|
{
|
|
|
|
LOG(("Creating nsHttpConnectionInfo @%x\n", this));
|
|
|
|
|
|
|
|
mUsingHttpProxy = (proxyInfo && proxyInfo->IsHTTP());
|
|
|
|
|
|
|
|
if (mUsingHttpProxy) {
|
|
|
|
mUsingConnect = mUsingSSL; // SSL always uses CONNECT
|
|
|
|
uint32_t resolveFlags = 0;
|
|
|
|
if (NS_SUCCEEDED(mProxyInfo->GetResolveFlags(&resolveFlags)) &&
|
|
|
|
resolveFlags & nsIProtocolProxyService::RESOLVE_ALWAYS_TUNNEL) {
|
|
|
|
mUsingConnect = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetOriginServer(host, port);
|
|
|
|
}
|
|
|
|
|
2003-01-18 01:27:53 +00:00
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHttpConnectionInfo::SetOriginServer(const nsACString &host, int32_t port)
|
2003-01-18 01:27:53 +00:00
|
|
|
{
|
|
|
|
mHost = host;
|
|
|
|
mPort = port == -1 ? DefaultPort() : port;
|
|
|
|
|
|
|
|
//
|
|
|
|
// build hash key:
|
|
|
|
//
|
|
|
|
// the hash key uniquely identifies the connection type. two connections
|
2009-02-26 17:43:45 +00: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)
|
2003-01-18 01:27:53 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
const char *keyHost;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t keyPort;
|
2003-01-18 01:27:53 +00:00
|
|
|
|
2012-06-19 05:50:20 +00:00
|
|
|
if (mUsingHttpProxy && !mUsingConnect) {
|
2003-01-18 01:27:53 +00:00
|
|
|
keyHost = ProxyHost();
|
|
|
|
keyPort = ProxyPort();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
keyHost = Host();
|
|
|
|
keyPort = Port();
|
|
|
|
}
|
|
|
|
|
2012-05-24 15:31:53 +00:00
|
|
|
mHashKey.AssignLiteral("....");
|
2004-12-04 10:19:29 +00:00
|
|
|
mHashKey.Append(keyHost);
|
2004-12-04 14:19:39 +00:00
|
|
|
mHashKey.Append(':');
|
2004-12-04 10:19:29 +00:00
|
|
|
mHashKey.AppendInt(keyPort);
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
if (mUsingHttpProxy)
|
2003-03-01 02:18:05 +00:00
|
|
|
mHashKey.SetCharAt('P', 0);
|
2003-01-18 01:27:53 +00:00
|
|
|
if (mUsingSSL)
|
2003-03-01 02:18:05 +00:00
|
|
|
mHashKey.SetCharAt('S', 1);
|
2003-01-18 01:27:53 +00:00
|
|
|
|
|
|
|
// NOTE: for transparent proxies (e.g., SOCKS) we need to encode the proxy
|
2012-09-05 12:32:28 +00:00
|
|
|
// info in the hash key (this ensures that we will continue to speak the
|
2003-01-18 01:27:53 +00:00
|
|
|
// right protocol even if our proxy preferences change).
|
2012-09-05 12:34:43 +00: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)) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mHashKey.AppendLiteral(" (");
|
|
|
|
mHashKey.Append(ProxyType());
|
2012-09-05 12:32:28 +00:00
|
|
|
mHashKey.Append(':');
|
|
|
|
mHashKey.Append(ProxyHost());
|
|
|
|
mHashKey.Append(':');
|
|
|
|
mHashKey.AppendInt(ProxyPort());
|
2004-12-04 10:19:29 +00:00
|
|
|
mHashKey.Append(')');
|
|
|
|
}
|
2003-01-18 01:27:53 +00:00
|
|
|
}
|
2010-01-26 13:33:03 +00:00
|
|
|
|
|
|
|
nsHttpConnectionInfo*
|
|
|
|
nsHttpConnectionInfo::Clone() const
|
|
|
|
{
|
|
|
|
nsHttpConnectionInfo* clone = new nsHttpConnectionInfo(mHost, mPort, mProxyInfo, mUsingSSL);
|
|
|
|
|
2012-05-24 15:31:53 +00:00
|
|
|
// Make sure the anonymous and private flags are transferred!
|
|
|
|
clone->SetAnonymous(GetAnonymous());
|
|
|
|
clone->SetPrivate(GetPrivate());
|
|
|
|
|
2010-01-26 13:33:03 +00:00
|
|
|
return clone;
|
|
|
|
}
|
2011-05-13 17:53:27 +00:00
|
|
|
|
2012-10-27 19:24:19 +00:00
|
|
|
bool
|
|
|
|
nsHttpConnectionInfo::UsingProxy()
|
|
|
|
{
|
|
|
|
if (!mProxyInfo)
|
|
|
|
return false;
|
|
|
|
return !mProxyInfo->IsDirect();
|
|
|
|
}
|
|
|
|
|
2013-11-11 06:59:40 +00:00
|
|
|
bool
|
|
|
|
nsHttpConnectionInfo::HostIsLocalIPLiteral() const
|
|
|
|
{
|
|
|
|
PRNetAddr prAddr;
|
|
|
|
// If the host/proxy host is not an IP address literal, return false.
|
|
|
|
if (ProxyHost()) {
|
|
|
|
if (PR_StringToNetAddr(ProxyHost(), &prAddr) != PR_SUCCESS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (PR_StringToNetAddr(Host(), &prAddr) != PR_SUCCESS) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
NetAddr netAddr;
|
|
|
|
PRNetAddrToNetAddr(&prAddr, &netAddr);
|
|
|
|
return IsIPAddrLocal(&netAddr);
|
|
|
|
}
|