2001-05-11 21:04:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-08-03 23:41:36 +00:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 et cin: */
|
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/. */
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
#include "nsHttp.h"
|
|
|
|
#include "nsHttpHandler.h"
|
|
|
|
#include "nsHttpChannel.h"
|
|
|
|
#include "nsHttpConnection.h"
|
|
|
|
#include "nsHttpResponseHead.h"
|
|
|
|
#include "nsHttpTransaction.h"
|
|
|
|
#include "nsHttpAuthCache.h"
|
2002-10-06 02:20:35 +00:00
|
|
|
#include "nsStandardURL.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsIURL.h"
|
2002-03-06 07:48:55 +00:00
|
|
|
#include "nsIStandardURL.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
#include "nsICacheService.h"
|
|
|
|
#include "nsICategoryManager.h"
|
2002-07-18 05:09:10 +00:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
#include "nsICacheService.h"
|
2001-09-27 21:26:59 +00:00
|
|
|
#include "nsIPrefService.h"
|
2012-01-17 01:48:29 +00:00
|
|
|
#include "nsIPrefBranch.h"
|
2001-09-27 21:26:59 +00:00
|
|
|
#include "nsIPrefLocalizedString.h"
|
2002-09-06 06:36:17 +00:00
|
|
|
#include "nsISocketProviderService.h"
|
|
|
|
#include "nsISocketProvider.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "prprf.h"
|
2001-06-17 05:23:38 +00:00
|
|
|
#include "nsReadableUtils.h"
|
2005-04-07 18:11:59 +00:00
|
|
|
#include "nsQuickSort.h"
|
2006-02-22 14:07:21 +00:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsIOService.h"
|
2010-07-28 18:33:06 +00:00
|
|
|
#include "nsAsyncRedirectVerifyHelper.h"
|
2010-10-28 17:10:03 +00:00
|
|
|
#include "nsSocketTransportService2.h"
|
2011-10-28 18:33:28 +00:00
|
|
|
#include "nsAlgorithm.h"
|
2012-05-25 21:37:01 +00:00
|
|
|
#include "ASpdySession.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2007-07-02 18:20:24 +00:00
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
|
Bug 530952: Electrolysis HTTP Channel implementation. author=jduell, r=bsmedberg, sr=bz
- Supports only primitive xpcshell HTTP requests which don't set/get HTTP
headers, don't do redirects, observers, load groups, or anything else other
than basic things like looking at the reply body, Content-type, Content-length, etc.
- Tested with network/test/unit_ipc/test_simple_wrap.js (patch @ bug 521922)
- Only used if "NECKO_E10S_HTTP" set in environment.
- Force http.h to get #included before any IPDL files, to centralize #define
handling of LOG and to make sure FORCE_PR_LOGGING is set if needed (bug
545995)
2009-09-22 18:55:33 +00:00
|
|
|
#include "mozilla/net/NeckoChild.h"
|
|
|
|
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 19:10:24 +00:00
|
|
|
#if defined(XP_UNIX)
|
2001-05-11 21:04:09 +00:00
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif
|
|
|
|
|
2003-04-02 22:45:08 +00:00
|
|
|
#if defined(XP_WIN)
|
2001-05-11 21:04:09 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2007-10-30 15:47:30 +00:00
|
|
|
#if defined(XP_MACOSX)
|
2010-03-10 19:30:11 +00:00
|
|
|
#include <CoreServices/CoreServices.h>
|
2007-10-30 15:47:30 +00:00
|
|
|
#endif
|
|
|
|
|
2006-05-11 17:22:54 +00:00
|
|
|
#if defined(XP_OS2)
|
|
|
|
#define INCL_DOSMISC
|
|
|
|
#include <os2.h>
|
|
|
|
#endif
|
|
|
|
|
2009-08-18 19:05:15 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2011-10-28 18:33:28 +00:00
|
|
|
using namespace mozilla;
|
2009-08-18 19:05:15 +00:00
|
|
|
using namespace mozilla::net;
|
Bug 530952: Electrolysis HTTP Channel implementation. author=jduell, r=bsmedberg, sr=bz
- Supports only primitive xpcshell HTTP requests which don't set/get HTTP
headers, don't do redirects, observers, load groups, or anything else other
than basic things like looking at the reply body, Content-type, Content-length, etc.
- Tested with network/test/unit_ipc/test_simple_wrap.js (patch @ bug 521922)
- Only used if "NECKO_E10S_HTTP" set in environment.
- Force http.h to get #included before any IPDL files, to centralize #define
handling of LOG and to make sure FORCE_PR_LOGGING is set if needed (bug
545995)
2009-09-22 18:55:33 +00:00
|
|
|
#include "mozilla/net/HttpChannelChild.h"
|
2009-08-18 19:05:15 +00:00
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2001-09-04 23:02:26 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// defined by the socket transport service while active
|
2003-01-18 02:15:14 +00:00
|
|
|
extern PRThread *gSocketThread;
|
2001-09-04 23:02:26 +00:00
|
|
|
#endif
|
|
|
|
|
2001-06-06 00:10:09 +00:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
2001-05-11 21:04:09 +00:00
|
|
|
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
|
2003-08-05 01:44:27 +00:00
|
|
|
static NS_DEFINE_CID(kCookieServiceCID, NS_COOKIESERVICE_CID);
|
2001-05-11 21:04:09 +00:00
|
|
|
static NS_DEFINE_CID(kCacheServiceCID, NS_CACHESERVICE_CID);
|
2002-09-06 06:36:17 +00:00
|
|
|
static NS_DEFINE_CID(kSocketProviderServiceCID, NS_SOCKETPROVIDERSERVICE_CID);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
#define UA_PREF_PREFIX "general.useragent."
|
2010-08-05 07:09:42 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#define UA_SPARE_PLATFORM
|
|
|
|
#endif
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
#define HTTP_PREF_PREFIX "network.http."
|
|
|
|
#define INTL_ACCEPT_LANGUAGES "intl.accept_languages"
|
2001-10-05 07:50:21 +00:00
|
|
|
#define NETWORK_ENABLEIDN "network.enableIDN"
|
2003-09-15 22:12:52 +00:00
|
|
|
#define BROWSER_PREF_PREFIX "browser.cache."
|
2011-01-05 19:53:21 +00:00
|
|
|
#define DONOTTRACK_HEADER_ENABLED "privacy.donottrackheader.enabled"
|
2012-02-27 15:32:09 +00:00
|
|
|
#define TELEMETRY_ENABLED "toolkit.telemetry.enabled"
|
|
|
|
#define ALLOW_EXPERIMENTS "network.allow-experiments"
|
2001-09-27 21:26:59 +00:00
|
|
|
|
|
|
|
#define UA_PREF(_pref) UA_PREF_PREFIX _pref
|
|
|
|
#define HTTP_PREF(_pref) HTTP_PREF_PREFIX _pref
|
2003-09-15 22:12:52 +00:00
|
|
|
#define BROWSER_PREF(_pref) BROWSER_PREF_PREFIX _pref
|
2001-09-27 21:26:59 +00:00
|
|
|
|
2009-11-07 02:40:13 +00:00
|
|
|
#define NS_HTTP_PROTOCOL_FLAGS (URI_STD | ALLOWS_PROXY | ALLOWS_PROXY_HTTP | URI_LOADABLE_BY_ANYONE)
|
|
|
|
|
2003-03-01 02:18:05 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
NewURI(const nsACString &aSpec,
|
|
|
|
const char *aCharset,
|
|
|
|
nsIURI *aBaseURI,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aDefaultPort,
|
2003-03-01 02:18:05 +00:00
|
|
|
nsIURI **aURI)
|
|
|
|
{
|
|
|
|
nsStandardURL *url = new nsStandardURL();
|
|
|
|
if (!url)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(url);
|
|
|
|
|
|
|
|
nsresult rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY,
|
|
|
|
aDefaultPort, aSpec, aCharset, aBaseURI);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(url);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aURI = url; // no QI needed
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler <public>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
nsHttpHandler *gHttpHandler = nullptr;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
nsHttpHandler::nsHttpHandler()
|
2012-07-30 14:20:58 +00:00
|
|
|
: mConnMgr(nullptr)
|
2008-08-20 09:35:26 +00:00
|
|
|
, mHttpVersion(NS_HTTP_VERSION_1_1)
|
2002-04-18 22:36:39 +00:00
|
|
|
, mProxyHttpVersion(NS_HTTP_VERSION_1_1)
|
2001-08-14 01:03:27 +00:00
|
|
|
, mCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
|
2002-04-18 22:36:39 +00:00
|
|
|
, mReferrerLevel(0xff) // by default we always send a referrer
|
2011-10-17 14:59:28 +00:00
|
|
|
, mFastFallbackToIPv4(false)
|
2012-09-14 20:27:46 +00:00
|
|
|
, mProxyPipelining(true)
|
2012-02-24 01:58:43 +00:00
|
|
|
, mIdleTimeout(PR_SecondsToInterval(10))
|
|
|
|
, mSpdyTimeout(PR_SecondsToInterval(180))
|
2001-08-14 01:03:27 +00:00
|
|
|
, mMaxRequestAttempts(10)
|
2001-09-04 23:02:26 +00:00
|
|
|
, mMaxRequestDelay(10)
|
2011-03-31 19:38:30 +00:00
|
|
|
, mIdleSynTimeout(250)
|
2012-10-05 01:08:58 +00:00
|
|
|
, mPipeliningEnabled(false)
|
2001-09-04 23:02:26 +00:00
|
|
|
, mMaxConnections(24)
|
|
|
|
, mMaxPersistentConnectionsPerServer(2)
|
2001-11-04 05:46:06 +00:00
|
|
|
, mMaxPersistentConnectionsPerProxy(4)
|
2012-03-22 23:39:31 +00:00
|
|
|
, mMaxPipelinedRequests(32)
|
|
|
|
, mMaxOptimisticPipelinedRequests(4)
|
|
|
|
, mPipelineAggressive(false)
|
2012-03-22 23:39:31 +00:00
|
|
|
, mMaxPipelineObjectSize(300000)
|
2012-04-11 17:49:32 +00:00
|
|
|
, mPipelineRescheduleOnTimeout(true)
|
|
|
|
, mPipelineRescheduleTimeout(PR_MillisecondsToInterval(1500))
|
2012-04-03 00:36:11 +00:00
|
|
|
, mPipelineReadTimeout(PR_MillisecondsToInterval(30000))
|
2001-12-08 00:23:04 +00:00
|
|
|
, mRedirectionLimit(10)
|
2004-05-08 00:40:03 +00:00
|
|
|
, mPhishyUserPassLength(1)
|
2010-06-03 02:25:01 +00:00
|
|
|
, mQoSBits(0x00)
|
2011-10-17 14:59:28 +00:00
|
|
|
, mPipeliningOverSSL(false)
|
2012-03-22 23:39:31 +00:00
|
|
|
, mEnforceAssocReq(false)
|
2001-10-22 23:24:26 +00:00
|
|
|
, mLastUniqueID(NowInSeconds())
|
|
|
|
, mSessionStartTime(0)
|
2010-08-27 07:02:10 +00:00
|
|
|
, mLegacyAppName("Mozilla")
|
|
|
|
, mLegacyAppVersion("5.0")
|
2010-08-28 20:42:04 +00:00
|
|
|
, mProduct("Gecko")
|
2011-10-17 14:59:28 +00:00
|
|
|
, mUserAgentIsDirty(true)
|
|
|
|
, mUseCache(true)
|
|
|
|
, mPromptTempRedirect(true)
|
|
|
|
, mSendSecureXSiteReferrer(true)
|
|
|
|
, mEnablePersistentHttpsCaching(false)
|
|
|
|
, mDoNotTrackEnabled(false)
|
2012-02-27 15:32:09 +00:00
|
|
|
, mTelemetryEnabled(false)
|
|
|
|
, mAllowExperiments(true)
|
2012-09-14 20:27:46 +00:00
|
|
|
, mHandlerActive(false)
|
2011-12-13 15:55:50 +00:00
|
|
|
, mEnableSpdy(false)
|
2012-05-25 21:37:08 +00:00
|
|
|
, mSpdyV2(true)
|
|
|
|
, mSpdyV3(true)
|
2011-12-13 15:55:50 +00:00
|
|
|
, mCoalesceSpdy(true)
|
|
|
|
, mUseAlternateProtocol(false)
|
2012-05-25 21:37:01 +00:00
|
|
|
, mSpdySendingChunkSize(ASpdySession::kSendingChunkSize)
|
2012-10-07 00:48:20 +00:00
|
|
|
, mSpdySendBufferSize(ASpdySession::kTCPSendBufferSize)
|
2012-10-25 18:20:08 +00:00
|
|
|
, mSpdyPingThreshold(PR_SecondsToInterval(58))
|
2012-02-24 01:58:43 +00:00
|
|
|
, mSpdyPingTimeout(PR_SecondsToInterval(8))
|
2012-07-23 23:10:00 +00:00
|
|
|
, mConnectTimeout(90000)
|
2012-12-04 23:06:29 +00:00
|
|
|
, mParallelSpeculativeConnectLimit(6)
|
2012-12-04 23:06:29 +00:00
|
|
|
, mCritialRequestPrioritization(true)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
gHttpLog = PR_NewLogModule("nsHttp");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LOG(("Creating nsHttpHandler [this=%x].\n", this));
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_ASSERTION(!gHttpHandler, "HTTP handler already created!");
|
|
|
|
gHttpHandler = this;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpHandler::~nsHttpHandler()
|
|
|
|
{
|
|
|
|
LOG(("Deleting nsHttpHandler [this=%x]\n", this));
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// make sure the connection manager is shutdown
|
|
|
|
if (mConnMgr) {
|
|
|
|
mConnMgr->Shutdown();
|
2008-08-20 09:35:26 +00:00
|
|
|
NS_RELEASE(mConnMgr);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
Bug 530952: Electrolysis HTTP Channel implementation. author=jduell, r=bsmedberg, sr=bz
- Supports only primitive xpcshell HTTP requests which don't set/get HTTP
headers, don't do redirects, observers, load groups, or anything else other
than basic things like looking at the reply body, Content-type, Content-length, etc.
- Tested with network/test/unit_ipc/test_simple_wrap.js (patch @ bug 521922)
- Only used if "NECKO_E10S_HTTP" set in environment.
- Force http.h to get #included before any IPDL files, to centralize #define
handling of LOG and to make sure FORCE_PR_LOGGING is set if needed (bug
545995)
2009-09-22 18:55:33 +00:00
|
|
|
// Note: don't call NeckoChild::DestroyNeckoChild() here, as it's too late
|
|
|
|
// and it'll segfault. NeckoChild will get cleaned up by process exit.
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsHttp::DestroyAtomTable();
|
2012-10-05 01:08:58 +00:00
|
|
|
if (mPipelineTestTimer) {
|
|
|
|
mPipelineTestTimer->Cancel();
|
|
|
|
mPipelineTestTimer = nullptr;
|
|
|
|
}
|
2001-06-11 21:20:29 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
gHttpHandler = nullptr;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::Init()
|
|
|
|
{
|
2005-04-01 18:35:14 +00:00
|
|
|
nsresult rv;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
LOG(("nsHttpHandler::Init\n"));
|
|
|
|
|
2005-04-01 18:35:14 +00:00
|
|
|
rv = nsHttp::CreateAtomTable();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2009-06-28 01:42:51 +00:00
|
|
|
mIOService = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
2001-06-06 00:10:09 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("unable to continue without io service");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
Bug 530952: Electrolysis HTTP Channel implementation. author=jduell, r=bsmedberg, sr=bz
- Supports only primitive xpcshell HTTP requests which don't set/get HTTP
headers, don't do redirects, observers, load groups, or anything else other
than basic things like looking at the reply body, Content-type, Content-length, etc.
- Tested with network/test/unit_ipc/test_simple_wrap.js (patch @ bug 521922)
- Only used if "NECKO_E10S_HTTP" set in environment.
- Force http.h to get #included before any IPDL files, to centralize #define
handling of LOG and to make sure FORCE_PR_LOGGING is set if needed (bug
545995)
2009-09-22 18:55:33 +00:00
|
|
|
if (IsNeckoChild())
|
2009-08-18 19:05:15 +00:00
|
|
|
NeckoChild::InitNeckoChild();
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
InitUserAgentComponents();
|
|
|
|
|
|
|
|
// monitor some preference changes
|
2012-01-17 01:48:29 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
2001-10-02 00:40:27 +00:00
|
|
|
if (prefBranch) {
|
2011-10-17 14:59:28 +00:00
|
|
|
prefBranch->AddObserver(HTTP_PREF_PREFIX, this, true);
|
|
|
|
prefBranch->AddObserver(UA_PREF_PREFIX, this, true);
|
2012-08-28 01:21:20 +00:00
|
|
|
prefBranch->AddObserver(INTL_ACCEPT_LANGUAGES, this, true);
|
2011-10-17 14:59:28 +00:00
|
|
|
prefBranch->AddObserver(NETWORK_ENABLEIDN, this, true);
|
|
|
|
prefBranch->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, true);
|
|
|
|
prefBranch->AddObserver(DONOTTRACK_HEADER_ENABLED, this, true);
|
2012-02-27 15:32:09 +00:00
|
|
|
prefBranch->AddObserver(TELEMETRY_ENABLED, this, true);
|
2004-01-28 23:45:17 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
PrefsChanged(prefBranch, nullptr);
|
2001-09-27 21:26:59 +00:00
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2012-02-21 03:29:09 +00:00
|
|
|
mMisc.AssignLiteral("rv:" MOZILLA_UAVERSION);
|
2003-09-25 05:39:11 +00:00
|
|
|
|
2012-06-22 11:52:47 +00:00
|
|
|
mCompatFirefox.AssignLiteral("Firefox/" MOZILLA_UAVERSION);
|
|
|
|
|
2010-08-27 07:02:10 +00:00
|
|
|
nsCOMPtr<nsIXULAppInfo> appInfo =
|
|
|
|
do_GetService("@mozilla.org/xre/app-info;1");
|
|
|
|
|
|
|
|
mAppName.AssignLiteral(MOZ_APP_UA_NAME);
|
|
|
|
if (mAppName.Length() == 0 && appInfo) {
|
2012-04-23 20:09:23 +00:00
|
|
|
// Try to get the UA name from appInfo, falling back to the name
|
|
|
|
appInfo->GetUAName(mAppName);
|
|
|
|
if (mAppName.Length() == 0) {
|
|
|
|
appInfo->GetName(mAppName);
|
|
|
|
}
|
2010-08-27 07:02:10 +00:00
|
|
|
appInfo->GetVersion(mAppVersion);
|
2010-09-02 11:37:41 +00:00
|
|
|
mAppName.StripChars(" ()<>@,;:\\\"/[]?={}");
|
2010-08-27 07:02:10 +00:00
|
|
|
} else {
|
2010-08-30 15:54:46 +00:00
|
|
|
mAppVersion.AssignLiteral(MOZ_APP_UA_VERSION);
|
2010-08-27 07:02:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 21:07:42 +00:00
|
|
|
mSessionStartTime = NowInSeconds();
|
2012-09-14 20:27:46 +00:00
|
|
|
mHandlerActive = true;
|
2012-06-20 21:07:42 +00:00
|
|
|
|
|
|
|
rv = mAuthCache.Init();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-10-29 20:20:03 +00:00
|
|
|
rv = mPrivateAuthCache.Init();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-06-20 21:07:42 +00:00
|
|
|
rv = InitConnectionMgr();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-10 18:48:09 +00:00
|
|
|
#ifdef ANDROID
|
2012-06-20 21:07:42 +00:00
|
|
|
mProductSub.AssignLiteral(MOZILLA_UAVERSION);
|
2012-08-10 18:48:09 +00:00
|
|
|
#else
|
|
|
|
mProductSub.AssignLiteral(MOZ_UA_BUILDID);
|
|
|
|
#endif
|
|
|
|
if (mProductSub.IsEmpty() && appInfo)
|
|
|
|
appInfo->GetPlatformBuildID(mProductSub);
|
|
|
|
if (mProductSub.Length() > 8)
|
|
|
|
mProductSub.SetLength(8);
|
2012-06-20 21:07:42 +00:00
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
#if DEBUG
|
|
|
|
// dump user agent prefs
|
2010-08-27 07:02:10 +00:00
|
|
|
LOG(("> legacy-app-name = %s\n", mLegacyAppName.get()));
|
|
|
|
LOG(("> legacy-app-version = %s\n", mLegacyAppVersion.get()));
|
2001-09-27 21:26:59 +00:00
|
|
|
LOG(("> platform = %s\n", mPlatform.get()));
|
|
|
|
LOG(("> oscpu = %s\n", mOscpu.get()));
|
|
|
|
LOG(("> misc = %s\n", mMisc.get()));
|
|
|
|
LOG(("> product = %s\n", mProduct.get()));
|
|
|
|
LOG(("> product-sub = %s\n", mProductSub.get()));
|
2010-08-27 07:02:10 +00:00
|
|
|
LOG(("> app-name = %s\n", mAppName.get()));
|
|
|
|
LOG(("> app-version = %s\n", mAppVersion.get()));
|
|
|
|
LOG(("> compat-firefox = %s\n", mCompatFirefox.get()));
|
2002-03-20 22:50:33 +00:00
|
|
|
LOG(("> user-agent = %s\n", UserAgent().get()));
|
2001-09-27 21:26:59 +00:00
|
|
|
#endif
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// Startup the http category
|
|
|
|
// Bring alive the objects in the http-protocol-startup category
|
2001-08-28 22:22:27 +00:00
|
|
|
NS_CreateServicesFromCategory(NS_HTTP_STARTUP_CATEGORY,
|
2007-07-08 07:08:04 +00:00
|
|
|
static_cast<nsISupports*>(static_cast<void*>(this)),
|
2012-08-28 01:21:20 +00:00
|
|
|
NS_HTTP_STARTUP_TOPIC);
|
|
|
|
|
2012-10-25 01:00:27 +00:00
|
|
|
mObserverService = services::GetObserverService();
|
2003-09-15 21:44:43 +00:00
|
|
|
if (mObserverService) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mObserverService->AddObserver(this, "profile-change-net-teardown", true);
|
|
|
|
mObserverService->AddObserver(this, "profile-change-net-restore", true);
|
|
|
|
mObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, true);
|
|
|
|
mObserverService->AddObserver(this, "net:clear-active-logins", true);
|
|
|
|
mObserverService->AddObserver(this, "net:prune-dead-connections", true);
|
2012-04-09 14:22:07 +00:00
|
|
|
mObserverService->AddObserver(this, "net:failed-to-process-uri-content", true);
|
2012-10-29 20:20:03 +00:00
|
|
|
mObserverService->AddObserver(this, "last-pb-context-exited", true);
|
2001-09-21 05:04:25 +00:00
|
|
|
}
|
2012-08-28 01:21:20 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::InitConnectionMgr()
|
|
|
|
{
|
2008-08-20 09:35:26 +00:00
|
|
|
nsresult rv;
|
2008-08-20 06:43:43 +00:00
|
|
|
|
2008-08-20 09:35:26 +00:00
|
|
|
if (!mConnMgr) {
|
|
|
|
mConnMgr = new nsHttpConnectionMgr();
|
|
|
|
if (!mConnMgr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mConnMgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = mConnMgr->Init(mMaxConnections,
|
|
|
|
mMaxPersistentConnectionsPerServer,
|
|
|
|
mMaxPersistentConnectionsPerProxy,
|
|
|
|
mMaxRequestDelay,
|
2012-03-22 23:39:31 +00:00
|
|
|
mMaxPipelinedRequests,
|
|
|
|
mMaxOptimisticPipelinedRequests);
|
2008-08-20 09:35:26 +00:00
|
|
|
return rv;
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
nsresult
|
2012-09-14 20:27:46 +00:00
|
|
|
nsHttpHandler::AddStandardRequestHeaders(nsHttpHeaderArray *request)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2001-07-17 20:22:19 +00:00
|
|
|
// Add the "User-Agent" header
|
2001-05-11 21:04:09 +00:00
|
|
|
rv = request->SetHeader(nsHttp::User_Agent, UserAgent());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-05-17 00:17:34 +00:00
|
|
|
// MIME based content negotiation lives!
|
2001-07-17 20:22:19 +00:00
|
|
|
// Add the "Accept" header
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = request->SetHeader(nsHttp::Accept, mAccept);
|
2001-05-11 21:04:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-07-17 20:22:19 +00:00
|
|
|
// Add the "Accept-Language" header
|
2001-08-14 02:45:05 +00:00
|
|
|
if (!mAcceptLanguages.IsEmpty()) {
|
|
|
|
// Add the "Accept-Language" header
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = request->SetHeader(nsHttp::Accept_Language, mAcceptLanguages);
|
2001-08-14 02:45:05 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-07-17 20:22:19 +00:00
|
|
|
// Add the "Accept-Encoding" header
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = request->SetHeader(nsHttp::Accept_Encoding, mAcceptEncodings);
|
2001-05-11 21:04:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-09-14 20:27:46 +00:00
|
|
|
// Add the "Do-Not-Track" header
|
|
|
|
if (mDoNotTrackEnabled) {
|
|
|
|
rv = request->SetHeader(nsHttp::DoNotTrack,
|
|
|
|
NS_LITERAL_CSTRING("1"));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::AddConnectionHeader(nsHttpHeaderArray *request,
|
2012-11-30 01:34:35 +00:00
|
|
|
uint32_t caps)
|
2012-09-14 20:27:46 +00:00
|
|
|
{
|
2001-07-17 20:22:19 +00:00
|
|
|
// RFC2616 section 19.6.2 states that the "Connection: keep-alive"
|
|
|
|
// and "Keep-alive" request headers should not be sent by HTTP/1.1
|
2012-09-05 12:38:01 +00:00
|
|
|
// user-agents. But this is not a problem in practice, and the
|
|
|
|
// alternative proxy-connection is worse. see 570283
|
2012-08-28 01:21:20 +00:00
|
|
|
|
2002-11-22 07:40:16 +00:00
|
|
|
NS_NAMED_LITERAL_CSTRING(close, "close");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(keepAlive, "keep-alive");
|
|
|
|
|
|
|
|
const nsACString *connectionType = &close;
|
2001-08-14 01:03:27 +00:00
|
|
|
if (caps & NS_HTTP_ALLOW_KEEPALIVE) {
|
2002-11-22 07:40:16 +00:00
|
|
|
connectionType = &keepAlive;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
2001-07-17 20:22:19 +00:00
|
|
|
|
2012-09-05 12:38:01 +00:00
|
|
|
return request->SetHeader(nsHttp::Connection, *connectionType);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2001-06-19 00:25:02 +00:00
|
|
|
nsHttpHandler::IsAcceptableEncoding(const char *enc)
|
|
|
|
{
|
|
|
|
if (!enc)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2001-06-19 00:25:02 +00:00
|
|
|
|
|
|
|
// HTTP 1.1 allows servers to send x-gzip and x-compress instead
|
|
|
|
// of gzip and compress, for example. So, we'll always strip off
|
|
|
|
// an "x-" prefix before matching the encoding to one we claim
|
|
|
|
// to accept.
|
|
|
|
if (!PL_strncasecmp(enc, "x-", 2))
|
|
|
|
enc += 2;
|
2012-06-10 23:44:50 +00:00
|
|
|
|
2012-11-01 12:47:29 +00:00
|
|
|
// gzip and deflate are inherently acceptable in modern HTTP - always
|
|
|
|
// process them if a stream converter can also be found.
|
|
|
|
if (!PL_strcasecmp(enc, "gzip") || !PL_strcasecmp(enc, "deflate"))
|
|
|
|
return true;
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nsHttp::FindToken(mAcceptEncodings.get(), enc, HTTP_LWS ",") != nullptr;
|
2001-06-19 00:25:02 +00:00
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
nsresult
|
|
|
|
nsHttpHandler::GetStreamConverterService(nsIStreamConverterService **result)
|
|
|
|
{
|
|
|
|
if (!mStreamConvSvc) {
|
|
|
|
nsresult rv;
|
2009-06-28 01:42:51 +00:00
|
|
|
mStreamConvSvc = do_GetService(NS_STREAMCONVERTERSERVICE_CONTRACTID, &rv);
|
2001-05-11 21:04:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
*result = mStreamConvSvc;
|
|
|
|
NS_ADDREF(*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-03 21:03:17 +00:00
|
|
|
nsIStrictTransportSecurityService*
|
|
|
|
nsHttpHandler::GetSTSService()
|
|
|
|
{
|
|
|
|
if (!mSTSService)
|
|
|
|
mSTSService = do_GetService(NS_STSSERVICE_CONTRACTID);
|
|
|
|
return mSTSService;
|
|
|
|
}
|
|
|
|
|
2003-08-05 01:44:27 +00:00
|
|
|
nsICookieService *
|
|
|
|
nsHttpHandler::GetCookieService()
|
|
|
|
{
|
|
|
|
if (!mCookieService)
|
2009-06-28 01:42:51 +00:00
|
|
|
mCookieService = do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
2003-08-05 01:44:27 +00:00
|
|
|
return mCookieService;
|
|
|
|
}
|
|
|
|
|
2012-08-28 01:21:20 +00:00
|
|
|
nsresult
|
2001-06-06 00:10:09 +00:00
|
|
|
nsHttpHandler::GetIOService(nsIIOService** result)
|
|
|
|
{
|
|
|
|
NS_ADDREF(*result = mIOService);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2012-02-27 15:32:09 +00:00
|
|
|
nsHttpHandler::Get32BitsOfPseudoRandom()
|
|
|
|
{
|
|
|
|
// only confirm rand seeding on socket thread
|
|
|
|
NS_ABORT_IF_FALSE(PR_GetCurrentThread() == gSocketThread, "wrong thread");
|
|
|
|
|
|
|
|
// rand() provides different amounts of PRNG on different platforms.
|
|
|
|
// 15 or 31 bits are common amounts.
|
|
|
|
|
|
|
|
PR_STATIC_ASSERT(RAND_MAX >= 0xfff);
|
2012-08-28 01:21:20 +00:00
|
|
|
|
2012-02-27 15:32:09 +00:00
|
|
|
#if RAND_MAX < 0xffffU
|
2012-08-22 15:56:38 +00:00
|
|
|
return ((uint16_t) rand() << 20) |
|
|
|
|
(((uint16_t) rand() & 0xfff) << 8) |
|
|
|
|
((uint16_t) rand() & 0xff);
|
2012-02-27 15:32:09 +00:00
|
|
|
#elif RAND_MAX < 0xffffffffU
|
2012-08-22 15:56:38 +00:00
|
|
|
return ((uint16_t) rand() << 16) | ((uint16_t) rand() & 0xffff);
|
2012-02-27 15:32:09 +00:00
|
|
|
#else
|
2012-08-22 15:56:38 +00:00
|
|
|
return (uint32_t) rand();
|
2012-02-27 15:32:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
2001-06-06 00:10:09 +00:00
|
|
|
|
2003-11-14 20:51:55 +00:00
|
|
|
void
|
|
|
|
nsHttpHandler::NotifyObservers(nsIHttpChannel *chan, const char *event)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2003-11-14 20:51:55 +00:00
|
|
|
LOG(("nsHttpHandler::NotifyObservers [chan=%x event=\"%s\"]\n", chan, event));
|
2003-09-15 21:44:43 +00:00
|
|
|
if (mObserverService)
|
2012-07-30 14:20:58 +00:00
|
|
|
mObserverService->NotifyObservers(chan, event, nullptr);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2006-02-22 14:07:21 +00:00
|
|
|
nsresult
|
2010-07-28 18:33:06 +00:00
|
|
|
nsHttpHandler::AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t flags)
|
2006-02-22 14:07:21 +00:00
|
|
|
{
|
2010-07-28 18:33:06 +00:00
|
|
|
// TODO E10S This helper has to be initialized on the other process
|
|
|
|
nsRefPtr<nsAsyncRedirectVerifyHelper> redirectCallbackHelper =
|
|
|
|
new nsAsyncRedirectVerifyHelper();
|
2006-02-22 14:07:21 +00:00
|
|
|
|
2010-07-28 18:33:06 +00:00
|
|
|
return redirectCallbackHelper->Init(oldChan, newChan, flags);
|
2006-02-22 14:07:21 +00:00
|
|
|
}
|
|
|
|
|
2010-02-18 14:42:32 +00:00
|
|
|
/* static */ nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHttpHandler::GenerateHostPort(const nsCString& host, int32_t port,
|
2010-02-18 14:42:32 +00:00
|
|
|
nsCString& hostLine)
|
|
|
|
{
|
2011-12-23 02:21:20 +00:00
|
|
|
return NS_GenerateHostPort(host, port, hostLine);
|
2010-02-18 14:42:32 +00:00
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler <private>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
const nsAFlatCString &
|
2001-05-11 21:04:09 +00:00
|
|
|
nsHttpHandler::UserAgent()
|
|
|
|
{
|
2001-09-27 21:26:59 +00:00
|
|
|
if (mUserAgentOverride) {
|
|
|
|
LOG(("using general.useragent.override : %s\n", mUserAgentOverride.get()));
|
2002-03-20 22:50:33 +00:00
|
|
|
return mUserAgentOverride;
|
2001-09-27 21:26:59 +00:00
|
|
|
}
|
2001-05-18 22:45:34 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
if (mUserAgentIsDirty) {
|
|
|
|
BuildUserAgent();
|
2011-10-17 14:59:28 +00:00
|
|
|
mUserAgentIsDirty = false;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
2001-05-18 22:45:34 +00:00
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
return mUserAgent;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpHandler::BuildUserAgent()
|
|
|
|
{
|
|
|
|
LOG(("nsHttpHandler::BuildUserAgent\n"));
|
|
|
|
|
2010-08-27 07:02:10 +00:00
|
|
|
NS_ASSERTION(!mLegacyAppName.IsEmpty() &&
|
2012-07-31 15:37:26 +00:00
|
|
|
!mLegacyAppVersion.IsEmpty(),
|
2001-05-11 21:04:09 +00:00
|
|
|
"HTTP cannot send practical requests without this much");
|
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
// preallocate to worst-case size, which should always be better
|
|
|
|
// than if we didn't preallocate at all.
|
2012-08-28 01:21:20 +00:00
|
|
|
mUserAgent.SetCapacity(mLegacyAppName.Length() +
|
|
|
|
mLegacyAppVersion.Length() +
|
2010-08-05 07:09:42 +00:00
|
|
|
#ifndef UA_SPARE_PLATFORM
|
2012-08-28 01:21:20 +00:00
|
|
|
mPlatform.Length() +
|
2010-08-05 07:09:42 +00:00
|
|
|
#endif
|
2002-03-20 22:50:33 +00:00
|
|
|
mOscpu.Length() +
|
|
|
|
mMisc.Length() +
|
|
|
|
mProduct.Length() +
|
|
|
|
mProductSub.Length() +
|
2010-08-27 07:02:10 +00:00
|
|
|
mAppName.Length() +
|
|
|
|
mAppVersion.Length() +
|
|
|
|
mCompatFirefox.Length() +
|
2012-02-01 04:04:23 +00:00
|
|
|
mCompatDevice.Length() +
|
2010-10-15 09:11:19 +00:00
|
|
|
13);
|
2002-03-20 22:50:33 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// Application portion
|
2010-08-27 07:02:10 +00:00
|
|
|
mUserAgent.Assign(mLegacyAppName);
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += '/';
|
2010-08-27 07:02:10 +00:00
|
|
|
mUserAgent += mLegacyAppVersion;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += ' ';
|
|
|
|
|
|
|
|
// Application comment
|
|
|
|
mUserAgent += '(';
|
2010-08-05 07:09:42 +00:00
|
|
|
#ifndef UA_SPARE_PLATFORM
|
2012-07-31 15:37:26 +00:00
|
|
|
if (!mPlatform.IsEmpty()) {
|
|
|
|
mUserAgent += mPlatform;
|
|
|
|
mUserAgent.AppendLiteral("; ");
|
|
|
|
}
|
2010-08-05 07:09:42 +00:00
|
|
|
#endif
|
2012-02-01 04:04:23 +00:00
|
|
|
if (!mCompatDevice.IsEmpty()) {
|
|
|
|
mUserAgent += mCompatDevice;
|
|
|
|
mUserAgent.AppendLiteral("; ");
|
|
|
|
}
|
2012-07-31 15:37:26 +00:00
|
|
|
else if (!mOscpu.IsEmpty()) {
|
|
|
|
mUserAgent += mOscpu;
|
|
|
|
mUserAgent.AppendLiteral("; ");
|
|
|
|
}
|
2010-08-27 07:02:10 +00:00
|
|
|
mUserAgent += mMisc;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += ')';
|
|
|
|
|
|
|
|
// Product portion
|
2010-08-27 07:02:10 +00:00
|
|
|
mUserAgent += ' ';
|
|
|
|
mUserAgent += mProduct;
|
|
|
|
mUserAgent += '/';
|
|
|
|
mUserAgent += mProductSub;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2012-06-22 11:52:47 +00:00
|
|
|
bool isFirefox = mAppName.EqualsLiteral("Firefox");
|
|
|
|
if (isFirefox || mCompatFirefoxEnabled) {
|
|
|
|
// "Firefox/x.y" (compatibility) app token
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += ' ';
|
2010-08-27 07:03:10 +00:00
|
|
|
mUserAgent += mCompatFirefox;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
2012-06-22 11:52:47 +00:00
|
|
|
if (!isFirefox) {
|
|
|
|
// App portion
|
|
|
|
mUserAgent += ' ';
|
|
|
|
mUserAgent += mAppName;
|
|
|
|
mUserAgent += '/';
|
|
|
|
mUserAgent += mAppVersion;
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 08:59:00 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#define WNT_BASE "Windows NT %ld.%ld"
|
|
|
|
#define W64_PREFIX "; Win64"
|
|
|
|
#endif
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
void
|
|
|
|
nsHttpHandler::InitUserAgentComponents()
|
|
|
|
{
|
2012-07-31 15:37:26 +00:00
|
|
|
#ifndef MOZ_UA_OS_AGNOSTIC
|
2012-02-01 04:04:23 +00:00
|
|
|
// Gather platform.
|
2004-12-04 10:19:29 +00:00
|
|
|
mPlatform.AssignLiteral(
|
2010-05-11 17:27:36 +00:00
|
|
|
#if defined(ANDROID)
|
|
|
|
"Android"
|
2001-12-09 09:14:34 +00:00
|
|
|
#elif defined(XP_OS2)
|
2001-06-17 05:23:38 +00:00
|
|
|
"OS/2"
|
2001-12-09 09:14:34 +00:00
|
|
|
#elif defined(XP_WIN)
|
2001-06-17 05:23:38 +00:00
|
|
|
"Windows"
|
2005-10-18 19:32:01 +00:00
|
|
|
#elif defined(XP_MACOSX)
|
2001-06-17 05:23:38 +00:00
|
|
|
"Macintosh"
|
2010-08-25 23:31:00 +00:00
|
|
|
#elif defined(MOZ_PLATFORM_MAEMO)
|
|
|
|
"Maemo"
|
2009-08-20 15:30:25 +00:00
|
|
|
#elif defined(MOZ_X11)
|
2001-12-09 09:14:34 +00:00
|
|
|
"X11"
|
2001-05-11 21:04:09 +00:00
|
|
|
#endif
|
2004-12-04 10:19:29 +00:00
|
|
|
);
|
2012-07-31 15:37:26 +00:00
|
|
|
#endif
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2012-05-19 15:31:17 +00:00
|
|
|
#if defined(ANDROID) || defined(MOZ_PLATFORM_MAEMO)
|
2012-02-01 04:04:23 +00:00
|
|
|
nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1");
|
|
|
|
NS_ASSERTION(infoService, "Could not find a system info service");
|
|
|
|
|
2012-08-20 19:25:09 +00:00
|
|
|
bool isTablet;
|
|
|
|
nsresult rv = infoService->GetPropertyAsBool(NS_LITERAL_STRING("tablet"), &isTablet);
|
|
|
|
if (NS_SUCCEEDED(rv) && isTablet)
|
2012-02-01 04:04:23 +00:00
|
|
|
mCompatDevice.AssignLiteral("Tablet");
|
|
|
|
else
|
|
|
|
mCompatDevice.AssignLiteral("Mobile");
|
|
|
|
#endif
|
|
|
|
|
2012-07-31 15:37:26 +00:00
|
|
|
#ifndef MOZ_UA_OS_AGNOSTIC
|
2001-05-11 21:04:09 +00:00
|
|
|
// Gather OS/CPU.
|
|
|
|
#if defined(XP_OS2)
|
|
|
|
ULONG os2ver = 0;
|
|
|
|
DosQuerySysInfo(QSV_VERSION_MINOR, QSV_VERSION_MINOR,
|
|
|
|
&os2ver, sizeof(os2ver));
|
|
|
|
if (os2ver == 11)
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("2.11");
|
2001-05-11 21:04:09 +00:00
|
|
|
else if (os2ver == 30)
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("Warp 3");
|
2001-05-11 21:04:09 +00:00
|
|
|
else if (os2ver == 40)
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("Warp 4");
|
2001-05-11 21:04:09 +00:00
|
|
|
else if (os2ver == 45)
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("Warp 4.5");
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2011-05-07 08:03:16 +00:00
|
|
|
#elif defined(XP_WIN)
|
2005-07-20 18:43:27 +00:00
|
|
|
OSVERSIONINFO info = { sizeof(OSVERSIONINFO) };
|
|
|
|
if (GetVersionEx(&info)) {
|
2010-05-02 08:59:00 +00:00
|
|
|
const char *format;
|
2011-05-07 08:03:16 +00:00
|
|
|
#if defined _M_IA64
|
2010-05-02 08:59:00 +00:00
|
|
|
format = WNT_BASE W64_PREFIX "; IA64";
|
|
|
|
#elif defined _M_X64 || defined _M_AMD64
|
|
|
|
format = WNT_BASE W64_PREFIX "; x64";
|
2009-08-20 15:30:25 +00:00
|
|
|
#else
|
2010-05-02 08:59:00 +00:00
|
|
|
BOOL isWow64 = FALSE;
|
2012-02-23 14:53:55 +00:00
|
|
|
if (!IsWow64Process(GetCurrentProcess(), &isWow64)) {
|
2010-05-02 08:59:00 +00:00
|
|
|
isWow64 = FALSE;
|
|
|
|
}
|
|
|
|
format = isWow64
|
|
|
|
? WNT_BASE "; WOW64"
|
|
|
|
: WNT_BASE;
|
2009-08-20 15:30:25 +00:00
|
|
|
#endif
|
2010-05-02 08:59:00 +00:00
|
|
|
char *buf = PR_smprintf(format,
|
2005-07-20 18:43:27 +00:00
|
|
|
info.dwMajorVersion,
|
|
|
|
info.dwMinorVersion);
|
|
|
|
if (buf) {
|
|
|
|
mOscpu = buf;
|
|
|
|
PR_smprintf_free(buf);
|
|
|
|
}
|
|
|
|
}
|
2007-10-30 15:47:30 +00:00
|
|
|
#elif defined (XP_MACOSX)
|
|
|
|
#if defined(__ppc__)
|
2007-12-05 01:07:00 +00:00
|
|
|
mOscpu.AssignLiteral("PPC Mac OS X");
|
2009-04-22 13:05:35 +00:00
|
|
|
#elif defined(__i386__) || defined(__x86_64__)
|
2005-10-18 19:32:01 +00:00
|
|
|
mOscpu.AssignLiteral("Intel Mac OS X");
|
2007-10-30 15:47:30 +00:00
|
|
|
#endif
|
2009-04-22 13:05:35 +00:00
|
|
|
SInt32 majorVersion, minorVersion;
|
2007-10-30 15:47:30 +00:00
|
|
|
if ((::Gestalt(gestaltSystemVersionMajor, &majorVersion) == noErr) &&
|
|
|
|
(::Gestalt(gestaltSystemVersionMinor, &minorVersion) == noErr)) {
|
2009-04-22 13:05:35 +00:00
|
|
|
mOscpu += nsPrintfCString(" %d.%d", majorVersion, minorVersion);
|
2007-10-30 15:47:30 +00:00
|
|
|
}
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 19:10:24 +00:00
|
|
|
#elif defined (XP_UNIX)
|
2001-05-11 21:04:09 +00:00
|
|
|
struct utsname name;
|
2012-08-28 01:21:20 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
int ret = uname(&name);
|
|
|
|
if (ret >= 0) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString buf;
|
2001-05-11 21:04:09 +00:00
|
|
|
buf = (char*)name.sysname;
|
2005-03-03 18:08:01 +00:00
|
|
|
|
|
|
|
if (strcmp(name.machine, "x86_64") == 0 &&
|
2012-08-22 15:56:38 +00:00
|
|
|
sizeof(void *) == sizeof(int32_t)) {
|
2005-03-03 18:08:01 +00:00
|
|
|
// We're running 32-bit code on x86_64. Make this browser
|
|
|
|
// look like it's running on i686 hardware, but append "
|
|
|
|
// (x86_64)" to the end of the oscpu identifier to be able
|
|
|
|
// to differentiate this from someone running 64-bit code
|
|
|
|
// on x86_64..
|
|
|
|
|
2010-08-27 15:12:01 +00:00
|
|
|
buf += " i686 on x86_64";
|
2005-03-03 18:08:01 +00:00
|
|
|
} else {
|
|
|
|
buf += ' ';
|
|
|
|
|
2005-06-02 23:17:50 +00:00
|
|
|
#ifdef AIX
|
|
|
|
// AIX uname returns machine specific info in the uname.machine
|
|
|
|
// field and does not return the cpu type like other platforms.
|
|
|
|
// We use the AIX version and release numbers instead.
|
|
|
|
buf += (char*)name.version;
|
|
|
|
buf += '.';
|
|
|
|
buf += (char*)name.release;
|
|
|
|
#else
|
2005-03-03 18:08:01 +00:00
|
|
|
buf += (char*)name.machine;
|
2005-06-02 23:17:50 +00:00
|
|
|
#endif
|
2005-03-03 18:08:01 +00:00
|
|
|
}
|
|
|
|
|
2001-11-28 05:22:57 +00:00
|
|
|
mOscpu.Assign(buf);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
2012-07-31 15:37:26 +00:00
|
|
|
#endif
|
2001-05-11 21:04:09 +00:00
|
|
|
#endif
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mUserAgentIsDirty = true;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2011-10-25 15:36:49 +00:00
|
|
|
nsHttpHandler::MaxSocketCount()
|
|
|
|
{
|
|
|
|
PR_CallOnce(&nsSocketTransportService::gMaxCountInitOnce,
|
|
|
|
nsSocketTransportService::DiscoverMaxCount);
|
|
|
|
// Don't use the full max count because sockets can be held in
|
|
|
|
// the persistent connection pool for a long time and that could
|
|
|
|
// starve other users.
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t maxCount = nsSocketTransportService::gMaxCount;
|
2011-10-25 15:36:49 +00:00
|
|
|
if (maxCount <= 8)
|
|
|
|
maxCount = 1;
|
|
|
|
else
|
|
|
|
maxCount -= 8;
|
|
|
|
|
|
|
|
return maxCount;
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
void
|
2001-10-02 00:40:27 +00:00
|
|
|
nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t val;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-10-04 01:40:35 +00:00
|
|
|
LOG(("nsHttpHandler::PrefsChanged [pref=%s]\n", pref));
|
2001-09-27 21:26:59 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
#define PREF_CHANGED(p) ((pref == nullptr) || !PL_strcmp(pref, p))
|
2005-04-07 18:11:59 +00:00
|
|
|
#define MULTI_PREF_CHANGED(p) \
|
2012-07-30 14:20:58 +00:00
|
|
|
((pref == nullptr) || !PL_strncmp(pref, p, sizeof(p) - 1))
|
2001-09-27 21:26:59 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// UA components
|
|
|
|
//
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool cVar = false;
|
2005-04-07 18:11:59 +00:00
|
|
|
|
2010-08-27 07:02:10 +00:00
|
|
|
if (PREF_CHANGED(UA_PREF("compatMode.firefox"))) {
|
|
|
|
rv = prefs->GetBoolPref(UA_PREF("compatMode.firefox"), &cVar);
|
2012-06-22 11:52:47 +00:00
|
|
|
mCompatFirefoxEnabled = (NS_SUCCEEDED(rv) && cVar);
|
2011-10-17 14:59:28 +00:00
|
|
|
mUserAgentIsDirty = true;
|
2001-09-27 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// general.useragent.override
|
|
|
|
if (PREF_CHANGED(UA_PREF("override"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetCharPref(UA_PREF("override"),
|
2001-09-27 21:26:59 +00:00
|
|
|
getter_Copies(mUserAgentOverride));
|
2011-10-17 14:59:28 +00:00
|
|
|
mUserAgentIsDirty = true;
|
2001-09-27 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// HTTP options
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("keep-alive.timeout"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("keep-alive.timeout"), &val);
|
2001-08-14 01:03:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-02-24 01:58:43 +00:00
|
|
|
mIdleTimeout = PR_SecondsToInterval(clamped(val, 1, 0xffff));
|
2001-08-14 01:03:27 +00:00
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("request.max-attempts"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("request.max-attempts"), &val);
|
2001-08-14 01:03:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 15:56:38 +00:00
|
|
|
mMaxRequestAttempts = (uint16_t) clamped(val, 1, 0xffff);
|
2001-08-14 01:03:27 +00:00
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("request.max-start-delay"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("request.max-start-delay"), &val);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
mMaxRequestDelay = (uint16_t) clamped(val, 0, 0xffff);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_REQUEST_DELAY,
|
|
|
|
mMaxRequestDelay);
|
|
|
|
}
|
2001-09-04 23:02:26 +00:00
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("max-connections"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("max-connections"), &val);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-25 15:36:49 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
mMaxConnections = (uint16_t) clamped((uint32_t)val,
|
|
|
|
(uint32_t)1, MaxSocketCount());
|
2011-10-25 15:36:49 +00:00
|
|
|
|
2004-08-03 23:41:36 +00:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_CONNECTIONS,
|
2006-04-18 14:24:09 +00:00
|
|
|
mMaxConnections);
|
2004-08-03 23:41:36 +00:00
|
|
|
}
|
2001-08-14 01:03:27 +00:00
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("max-persistent-connections-per-server"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("max-persistent-connections-per-server"), &val);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
mMaxPersistentConnectionsPerServer = (uint8_t) clamped(val, 1, 0xff);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_PERSISTENT_CONNECTIONS_PER_HOST,
|
|
|
|
mMaxPersistentConnectionsPerServer);
|
|
|
|
}
|
2001-08-14 01:03:27 +00:00
|
|
|
}
|
|
|
|
|
2001-11-04 05:46:06 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("max-persistent-connections-per-proxy"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("max-persistent-connections-per-proxy"), &val);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
mMaxPersistentConnectionsPerProxy = (uint8_t) clamped(val, 1, 0xff);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_PERSISTENT_CONNECTIONS_PER_PROXY,
|
|
|
|
mMaxPersistentConnectionsPerProxy);
|
|
|
|
}
|
2001-11-04 05:46:06 +00:00
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("sendRefererHeader"))) {
|
2001-12-08 00:23:04 +00:00
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("sendRefererHeader"), &val);
|
2001-08-14 01:03:27 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 15:56:38 +00:00
|
|
|
mReferrerLevel = (uint8_t) clamped(val, 0, 0xff);
|
2001-08-14 01:03:27 +00:00
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-12-08 00:23:04 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("redirection-limit"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("redirection-limit"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 15:56:38 +00:00
|
|
|
mRedirectionLimit = (uint8_t) clamped(val, 0, 0xff);
|
2001-12-08 00:23:04 +00:00
|
|
|
}
|
|
|
|
|
2011-03-31 19:38:30 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("connection-retry-timeout"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("connection-retry-timeout"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 15:56:38 +00:00
|
|
|
mIdleSynTimeout = (uint16_t) clamped(val, 0, 3000);
|
2011-03-31 19:38:30 +00:00
|
|
|
}
|
|
|
|
|
2011-08-27 10:49:40 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("fast-fallback-to-IPv4"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("fast-fallback-to-IPv4"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mFastFallbackToIPv4 = cVar;
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("version"))) {
|
2001-05-11 21:04:09 +00:00
|
|
|
nsXPIDLCString httpVersion;
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetCharPref(HTTP_PREF("version"), getter_Copies(httpVersion));
|
2001-05-11 21:04:09 +00:00
|
|
|
if (httpVersion) {
|
2001-09-27 21:26:59 +00:00
|
|
|
if (!PL_strcmp(httpVersion, "1.1"))
|
2001-05-11 21:04:09 +00:00
|
|
|
mHttpVersion = NS_HTTP_VERSION_1_1;
|
2001-09-27 21:26:59 +00:00
|
|
|
else if (!PL_strcmp(httpVersion, "0.9"))
|
2001-05-11 21:04:09 +00:00
|
|
|
mHttpVersion = NS_HTTP_VERSION_0_9;
|
|
|
|
else
|
|
|
|
mHttpVersion = NS_HTTP_VERSION_1_0;
|
|
|
|
}
|
2002-04-18 22:36:39 +00:00
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2002-04-18 22:36:39 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("proxy.version"))) {
|
|
|
|
nsXPIDLCString httpVersion;
|
|
|
|
prefs->GetCharPref(HTTP_PREF("proxy.version"), getter_Copies(httpVersion));
|
|
|
|
if (httpVersion) {
|
|
|
|
if (!PL_strcmp(httpVersion, "1.1"))
|
|
|
|
mProxyHttpVersion = NS_HTTP_VERSION_1_1;
|
|
|
|
else
|
|
|
|
mProxyHttpVersion = NS_HTTP_VERSION_1_0;
|
|
|
|
// it does not make sense to issue a HTTP/0.9 request to a proxy server
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("pipelining"), &cVar);
|
2001-05-11 21:04:09 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (cVar)
|
2001-08-14 01:03:27 +00:00
|
|
|
mCapabilities |= NS_HTTP_ALLOW_PIPELINING;
|
2001-05-11 21:04:09 +00:00
|
|
|
else
|
2001-08-14 01:03:27 +00:00
|
|
|
mCapabilities &= ~NS_HTTP_ALLOW_PIPELINING;
|
2012-10-05 01:08:58 +00:00
|
|
|
mPipeliningEnabled = cVar;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-19 22:25:23 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.maxrequests"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("pipelining.maxrequests"), &val);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-22 23:39:31 +00:00
|
|
|
mMaxPipelinedRequests = clamped(val, 1, 0xffff);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_PIPELINED_REQUESTS,
|
|
|
|
mMaxPipelinedRequests);
|
|
|
|
}
|
2002-04-19 22:25:23 +00:00
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2012-03-22 23:39:31 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.max-optimistic-requests"))) {
|
|
|
|
rv = prefs->
|
|
|
|
GetIntPref(HTTP_PREF("pipelining.max-optimistic-requests"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mMaxOptimisticPipelinedRequests = clamped(val, 1, 0xffff);
|
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam
|
|
|
|
(nsHttpConnectionMgr::MAX_OPTIMISTIC_PIPELINED_REQUESTS,
|
|
|
|
mMaxOptimisticPipelinedRequests);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.aggressive"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("pipelining.aggressive"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mPipelineAggressive = cVar;
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:39:31 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.maxsize"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("pipelining.maxsize"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mMaxPipelineObjectSize =
|
2012-08-22 15:56:38 +00:00
|
|
|
static_cast<int64_t>(clamped(val, 1000, 100000000));
|
2012-03-22 23:39:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-11 17:49:32 +00:00
|
|
|
// Determines whether or not to actually reschedule after the
|
|
|
|
// reschedule-timeout has expired
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.reschedule-on-timeout"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("pipelining.reschedule-on-timeout"),
|
|
|
|
&cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mPipelineRescheduleOnTimeout = cVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The amount of time head of line blocking is allowed (in ms)
|
|
|
|
// before the blocked transactions are moved to another pipeline
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.reschedule-timeout"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("pipelining.reschedule-timeout"),
|
|
|
|
&val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mPipelineRescheduleTimeout =
|
2012-08-22 15:56:38 +00:00
|
|
|
PR_MillisecondsToInterval((uint16_t) clamped(val, 500, 0xffff));
|
2012-04-11 17:49:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The amount of time a pipelined transaction is allowed to wait before
|
|
|
|
// being canceled and retried in a non-pipeline connection
|
2012-03-22 23:39:31 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.read-timeout"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("pipelining.read-timeout"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-04-11 17:49:32 +00:00
|
|
|
mPipelineReadTimeout =
|
2012-08-22 15:56:38 +00:00
|
|
|
PR_MillisecondsToInterval((uint16_t) clamped(val, 5000,
|
2012-04-11 17:49:32 +00:00
|
|
|
0xffff));
|
2012-03-22 23:39:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-07 04:04:56 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.ssl"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("pipelining.ssl"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mPipeliningOverSSL = cVar;
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("proxy.pipelining"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("proxy.pipelining"), &cVar);
|
2012-09-14 20:27:46 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mProxyPipelining = cVar;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 02:25:01 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("qos"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("qos"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 15:56:38 +00:00
|
|
|
mQoSBits = (uint8_t) clamped(val, 0, 0xff);
|
2010-06-03 02:25:01 +00:00
|
|
|
}
|
|
|
|
|
2002-03-18 05:20:58 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("sendSecureXSiteReferrer"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("sendSecureXSiteReferrer"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSendSecureXSiteReferrer = cVar;
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("accept.default"))) {
|
2001-05-17 00:17:34 +00:00
|
|
|
nsXPIDLCString accept;
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetCharPref(HTTP_PREF("accept.default"),
|
2001-05-17 00:17:34 +00:00
|
|
|
getter_Copies(accept));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
SetAccept(accept);
|
|
|
|
}
|
2012-08-28 01:21:20 +00:00
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("accept-encoding"))) {
|
2001-05-11 21:04:09 +00:00
|
|
|
nsXPIDLCString acceptEncodings;
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetCharPref(HTTP_PREF("accept-encoding"),
|
2001-05-11 21:04:09 +00:00
|
|
|
getter_Copies(acceptEncodings));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
SetAcceptEncodings(acceptEncodings);
|
|
|
|
}
|
|
|
|
|
2001-10-02 00:40:27 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("use-cache"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("use-cache"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mUseCache = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-06 06:36:17 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("default-socket-type"))) {
|
2003-09-25 05:39:11 +00:00
|
|
|
nsXPIDLCString sval;
|
2002-09-06 06:36:17 +00:00
|
|
|
rv = prefs->GetCharPref(HTTP_PREF("default-socket-type"),
|
2003-09-25 05:39:11 +00:00
|
|
|
getter_Copies(sval));
|
2002-09-06 06:36:17 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-09-25 05:39:11 +00:00
|
|
|
if (sval.IsEmpty())
|
2002-09-06 06:36:17 +00:00
|
|
|
mDefaultSocketType.Adopt(0);
|
|
|
|
else {
|
|
|
|
// verify that this socket type is actually valid
|
|
|
|
nsCOMPtr<nsISocketProviderService> sps(
|
2009-06-28 01:42:51 +00:00
|
|
|
do_GetService(NS_SOCKETPROVIDERSERVICE_CONTRACTID));
|
2008-08-19 00:19:27 +00:00
|
|
|
if (sps) {
|
2002-09-06 06:36:17 +00:00
|
|
|
nsCOMPtr<nsISocketProvider> sp;
|
2003-09-25 05:39:11 +00:00
|
|
|
rv = sps->GetSocketProvider(sval, getter_AddRefs(sp));
|
2002-09-06 06:36:17 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// OK, this looks like a valid socket provider.
|
2003-09-25 05:39:11 +00:00
|
|
|
mDefaultSocketType.Assign(sval);
|
2002-09-06 06:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-24 19:46:51 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("prompt-temp-redirect"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("prompt-temp-redirect"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mPromptTempRedirect = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 23:39:31 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("assoc-req.enforce"))) {
|
|
|
|
cVar = false;
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("assoc-req.enforce"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mEnforceAssocReq = cVar;
|
|
|
|
}
|
|
|
|
|
2012-08-28 01:21:20 +00:00
|
|
|
// enable Persistent caching for HTTPS - bug#205921
|
2003-09-15 22:12:52 +00:00
|
|
|
if (PREF_CHANGED(BROWSER_PREF("disk_cache_ssl"))) {
|
2011-10-17 14:59:28 +00:00
|
|
|
cVar = false;
|
2003-09-15 22:12:52 +00:00
|
|
|
rv = prefs->GetBoolPref(BROWSER_PREF("disk_cache_ssl"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mEnablePersistentHttpsCaching = cVar;
|
|
|
|
}
|
|
|
|
|
2004-04-16 04:48:02 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("phishy-userpass-length"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("phishy-userpass-length"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 15:56:38 +00:00
|
|
|
mPhishyUserPassLength = (uint8_t) clamped(val, 0, 0xff);
|
2004-04-16 04:48:02 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 15:55:50 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.enabled"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.enabled"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mEnableSpdy = cVar;
|
|
|
|
}
|
|
|
|
|
2012-05-25 21:37:08 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.enabled.v2"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.enabled.v2"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSpdyV2 = cVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.enabled.v3"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.enabled.v3"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSpdyV3 = cVar;
|
|
|
|
}
|
|
|
|
|
2011-12-13 15:55:50 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.coalesce-hostnames"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.coalesce-hostnames"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mCoalesceSpdy = cVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.use-alternate-protocol"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.use-alternate-protocol"),
|
|
|
|
&cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mUseAlternateProtocol = cVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.timeout"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("spdy.timeout"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-02-24 01:58:43 +00:00
|
|
|
mSpdyTimeout = PR_SecondsToInterval(clamped(val, 1, 0xffff));
|
2011-12-13 15:55:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 05:15:26 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.chunk-size"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("spdy.chunk-size"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 15:56:38 +00:00
|
|
|
mSpdySendingChunkSize = (uint32_t) clamped(val, 1, 0x7fffffff);
|
2012-01-26 05:15:26 +00:00
|
|
|
}
|
|
|
|
|
2012-02-24 01:58:43 +00:00
|
|
|
// The amount of idle seconds on a spdy connection before initiating a
|
|
|
|
// server ping. 0 will disable.
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.ping-threshold"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("spdy.ping-threshold"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSpdyPingThreshold =
|
2012-08-22 15:56:38 +00:00
|
|
|
PR_SecondsToInterval((uint16_t) clamped(val, 0, 0x7fffffff));
|
2012-02-24 01:58:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The amount of seconds to wait for a spdy ping response before
|
|
|
|
// closing the session.
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.ping-timeout"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("spdy.ping-timeout"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSpdyPingTimeout =
|
2012-08-22 15:56:38 +00:00
|
|
|
PR_SecondsToInterval((uint16_t) clamped(val, 0, 0x7fffffff));
|
2012-02-24 01:58:43 +00:00
|
|
|
}
|
|
|
|
|
2012-10-07 00:48:20 +00:00
|
|
|
// The amount of seconds to wait for a spdy ping response before
|
|
|
|
// closing the session.
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.send-buffer-size"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("spdy.send-buffer-size"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSpdySendBufferSize = (uint32_t) clamped(val, 1500, 0x7fffffff);
|
|
|
|
}
|
|
|
|
|
2012-07-23 23:10:00 +00:00
|
|
|
// The maximum amount of time to wait for socket transport to be
|
|
|
|
// established
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("connection-timeout"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("connection-timeout"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
// the pref is in seconds, but the variable is in milliseconds
|
|
|
|
mConnectTimeout = clamped(val, 1, 0xffff) * PR_MSEC_PER_SEC;
|
|
|
|
}
|
|
|
|
|
2012-12-04 23:06:29 +00:00
|
|
|
// The maximum number of current global half open sockets allowable
|
|
|
|
// for starting a new speculative connection.
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("speculative-parallel-limit"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("speculative-parallel-limit"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mParallelSpeculativeConnectLimit = (uint32_t) clamped(val, 0, 1024);
|
|
|
|
}
|
|
|
|
|
2012-12-04 23:06:29 +00:00
|
|
|
// Whether or not to block requests for non head js/css items (e.g. media)
|
|
|
|
// while those elements load.
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("rendering-critical-requests-prioritization"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("rendering-critical-requests-prioritization"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mCritialRequestPrioritization = cVar;
|
|
|
|
}
|
|
|
|
|
2012-07-09 22:07:57 +00:00
|
|
|
// on transition of network.http.diagnostics to true print
|
|
|
|
// a bunch of information to the console
|
|
|
|
if (pref && PREF_CHANGED(HTTP_PREF("diagnostics"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("diagnostics"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv) && cVar) {
|
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->PrintDiagnostics();
|
|
|
|
}
|
|
|
|
}
|
2001-09-27 21:26:59 +00:00
|
|
|
//
|
|
|
|
// INTL options
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(INTL_ACCEPT_LANGUAGES)) {
|
|
|
|
nsCOMPtr<nsIPrefLocalizedString> pls;
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetComplexValue(INTL_ACCEPT_LANGUAGES,
|
2001-09-27 21:26:59 +00:00
|
|
|
NS_GET_IID(nsIPrefLocalizedString),
|
|
|
|
getter_AddRefs(pls));
|
|
|
|
if (pls) {
|
|
|
|
nsXPIDLString uval;
|
|
|
|
pls->ToString(getter_Copies(uval));
|
|
|
|
if (uval)
|
2006-02-03 14:18:39 +00:00
|
|
|
SetAcceptLanguages(NS_ConvertUTF16toUTF8(uval).get());
|
2012-08-28 01:21:20 +00:00
|
|
|
}
|
2001-09-27 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2001-10-05 07:50:21 +00:00
|
|
|
//
|
|
|
|
// IDN options
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(NETWORK_ENABLEIDN)) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool enableIDN = false;
|
2001-10-05 07:50:21 +00:00
|
|
|
prefs->GetBoolPref(NETWORK_ENABLEIDN, &enableIDN);
|
|
|
|
// No locking is required here since this method runs in the main
|
|
|
|
// UI thread, and so do all the methods in nsHttpChannel.cpp
|
|
|
|
// (mIDNConverter is used by nsHttpChannel)
|
|
|
|
if (enableIDN && !mIDNConverter) {
|
2008-08-19 00:19:27 +00:00
|
|
|
mIDNConverter = do_GetService(NS_IDNSERVICE_CONTRACTID);
|
|
|
|
NS_ASSERTION(mIDNConverter, "idnSDK not installed");
|
2001-10-05 07:50:21 +00:00
|
|
|
}
|
|
|
|
else if (!enableIDN && mIDNConverter)
|
2012-07-30 14:20:58 +00:00
|
|
|
mIDNConverter = nullptr;
|
2001-10-05 07:50:21 +00:00
|
|
|
}
|
|
|
|
|
2011-01-05 19:53:21 +00:00
|
|
|
//
|
|
|
|
// Tracking options
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(DONOTTRACK_HEADER_ENABLED)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
cVar = false;
|
2011-01-05 19:53:21 +00:00
|
|
|
rv = prefs->GetBoolPref(DONOTTRACK_HEADER_ENABLED, &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mDoNotTrackEnabled = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-27 15:32:09 +00:00
|
|
|
//
|
|
|
|
// Telemetry
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(TELEMETRY_ENABLED)) {
|
|
|
|
cVar = false;
|
|
|
|
rv = prefs->GetBoolPref(TELEMETRY_ENABLED, &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mTelemetryEnabled = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// network.allow-experiments
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(ALLOW_EXPERIMENTS)) {
|
|
|
|
cVar = true;
|
|
|
|
rv = prefs->GetBoolPref(ALLOW_EXPERIMENTS, &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mAllowExperiments = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-05 01:08:58 +00:00
|
|
|
//
|
|
|
|
// Test HTTP Pipelining (bug796192)
|
|
|
|
// If experiments are allowed and pipelining is Off,
|
|
|
|
// turn it On for just 10 minutes
|
|
|
|
//
|
|
|
|
if (mAllowExperiments && !mPipeliningEnabled &&
|
|
|
|
PREF_CHANGED(HTTP_PREF("pipelining.abtest"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("pipelining.abtest"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// If option is enabled, only test for ~1% of sessions
|
|
|
|
if (cVar && !(rand() % 128)) {
|
|
|
|
mCapabilities |= NS_HTTP_ALLOW_PIPELINING;
|
|
|
|
if (mPipelineTestTimer)
|
|
|
|
mPipelineTestTimer->Cancel();
|
|
|
|
mPipelineTestTimer =
|
|
|
|
do_CreateInstance("@mozilla.org/timer;1", &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = mPipelineTestTimer->InitWithFuncCallback(
|
|
|
|
TimerCallback, this, 10*60*1000, // 10 minutes
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mCapabilities &= ~NS_HTTP_ALLOW_PIPELINING;
|
|
|
|
if (mPipelineTestTimer) {
|
|
|
|
mPipelineTestTimer->Cancel();
|
|
|
|
mPipelineTestTimer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
#undef PREF_CHANGED
|
2005-04-07 18:11:59 +00:00
|
|
|
#undef MULTI_PREF_CHANGED
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2012-10-05 01:08:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Static method called by mPipelineTestTimer when it expires.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsHttpHandler::TimerCallback(nsITimer * aTimer, void * aClosure)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsHttpHandler> thisObject = static_cast<nsHttpHandler*>(aClosure);
|
|
|
|
if (!thisObject->mPipeliningEnabled)
|
|
|
|
thisObject->mCapabilities &= ~NS_HTTP_ALLOW_PIPELINING;
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
/**
|
|
|
|
* Allocates a C string into that contains a ISO 639 language list
|
|
|
|
* notated with HTTP "q" values for output with a HTTP Accept-Language
|
|
|
|
* header. Previous q values will be stripped because the order of
|
|
|
|
* the langs imply the q value. The q values are calculated by dividing
|
|
|
|
* 1.0 amongst the number of languages present.
|
|
|
|
*
|
|
|
|
* Ex: passing: "en, ja"
|
2002-11-20 20:51:12 +00:00
|
|
|
* returns: "en,ja;q=0.5"
|
2001-05-11 21:04:09 +00:00
|
|
|
*
|
|
|
|
* passing: "en, ja, fr_CA"
|
2002-11-20 20:51:12 +00:00
|
|
|
* returns: "en,ja;q=0.7,fr_CA;q=0.3"
|
2001-05-11 21:04:09 +00:00
|
|
|
*/
|
|
|
|
static nsresult
|
|
|
|
PrepareAcceptLanguages(const char *i_AcceptLanguages, nsACString &o_AcceptLanguages)
|
|
|
|
{
|
|
|
|
if (!i_AcceptLanguages)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-08-30 02:49:31 +00:00
|
|
|
uint32_t n, count_n, size, wrote;
|
2001-05-11 21:04:09 +00:00
|
|
|
double q, dec;
|
|
|
|
char *p, *p2, *token, *q_Accept, *o_Accept;
|
|
|
|
const char *comma;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t available;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
o_Accept = nsCRT::strdup(i_AcceptLanguages);
|
2005-06-30 22:01:15 +00:00
|
|
|
if (!o_Accept)
|
2001-05-11 21:04:09 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
for (p = o_Accept, n = size = 0; '\0' != *p; p++) {
|
|
|
|
if (*p == ',') n++;
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
available = size + ++n * 11 + 1;
|
|
|
|
q_Accept = new char[available];
|
2005-06-30 22:01:15 +00:00
|
|
|
if (!q_Accept) {
|
|
|
|
nsCRT::free(o_Accept);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
*q_Accept = '\0';
|
|
|
|
q = 1.0;
|
|
|
|
dec = q / (double) n;
|
2012-08-30 02:49:31 +00:00
|
|
|
count_n = 0;
|
2001-05-11 21:04:09 +00:00
|
|
|
p2 = q_Accept;
|
|
|
|
for (token = nsCRT::strtok(o_Accept, ",", &p);
|
|
|
|
token != (char *) 0;
|
|
|
|
token = nsCRT::strtok(p, ",", &p))
|
|
|
|
{
|
2003-06-18 23:16:17 +00:00
|
|
|
token = net_FindCharNotInSet(token, HTTP_LWS);
|
2001-05-11 21:04:09 +00:00
|
|
|
char* trim;
|
2003-06-18 23:16:17 +00:00
|
|
|
trim = net_FindCharInSet(token, ";" HTTP_LWS);
|
2001-05-11 21:04:09 +00:00
|
|
|
if (trim != (char*)0) // remove "; q=..." if present
|
|
|
|
*trim = '\0';
|
|
|
|
|
|
|
|
if (*token != '\0') {
|
2012-08-30 02:49:31 +00:00
|
|
|
comma = count_n++ != 0 ? "," : ""; // delimiter if not first item
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t u = QVAL_TO_UINT(q);
|
2012-08-30 02:49:31 +00:00
|
|
|
|
|
|
|
// Only display q-value if less than 1.00.
|
|
|
|
if (u < 100) {
|
|
|
|
const char *qval_str;
|
|
|
|
|
|
|
|
// With a small number of languages, one decimal place is enough to prevent duplicate q-values.
|
|
|
|
// Also, trailing zeroes do not add any information, so they can be removed.
|
|
|
|
if ((n < 10) || ((u % 10) == 0)) {
|
|
|
|
u = (u + 5) / 10;
|
|
|
|
qval_str = "%s%s;q=0.%u";
|
|
|
|
} else {
|
|
|
|
// Values below 10 require zero padding.
|
|
|
|
qval_str = "%s%s;q=0.%02u";
|
|
|
|
}
|
|
|
|
|
|
|
|
wrote = PR_snprintf(p2, available, qval_str, comma, token, u);
|
|
|
|
} else {
|
2001-05-11 21:04:09 +00:00
|
|
|
wrote = PR_snprintf(p2, available, "%s%s", comma, token);
|
2012-08-30 02:49:31 +00:00
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
q -= dec;
|
|
|
|
p2 += wrote;
|
|
|
|
available -= wrote;
|
|
|
|
NS_ASSERTION(available > 0, "allocated string not long enough");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsCRT::free(o_Accept);
|
|
|
|
|
|
|
|
o_AcceptLanguages.Assign((const char *) q_Accept);
|
|
|
|
delete [] q_Accept;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-28 01:21:20 +00:00
|
|
|
nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString buf;
|
2001-05-11 21:04:09 +00:00
|
|
|
nsresult rv = PrepareAcceptLanguages(aAcceptLanguages, buf);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-03-20 22:50:33 +00:00
|
|
|
mAcceptLanguages.Assign(buf);
|
2001-05-11 21:04:09 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-05-17 00:17:34 +00:00
|
|
|
nsresult
|
2012-08-28 01:21:20 +00:00
|
|
|
nsHttpHandler::SetAccept(const char *aAccept)
|
2001-05-17 00:17:34 +00:00
|
|
|
{
|
|
|
|
mAccept = aAccept;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
nsresult
|
2012-08-28 01:21:20 +00:00
|
|
|
nsHttpHandler::SetAcceptEncodings(const char *aAcceptEncodings)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
|
|
|
mAcceptEncodings = aAcceptEncodings;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsISupports
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-04-25 12:54:42 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS6(nsHttpHandler,
|
2001-05-11 21:04:09 +00:00
|
|
|
nsIHttpProtocolHandler,
|
2001-09-13 02:21:05 +00:00
|
|
|
nsIProxiedProtocolHandler,
|
2001-05-11 21:04:09 +00:00
|
|
|
nsIProtocolHandler,
|
|
|
|
nsIObserver,
|
2012-04-25 12:54:42 +00:00
|
|
|
nsISupportsWeakReference,
|
|
|
|
nsISpeculativeConnect)
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsIProtocolHandler
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 07:48:55 +00:00
|
|
|
nsHttpHandler::GetScheme(nsACString &aScheme)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2004-06-17 00:13:25 +00:00
|
|
|
aScheme.AssignLiteral("http");
|
2002-08-13 20:33:45 +00:00
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHttpHandler::GetDefaultPort(int32_t *result)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2003-03-01 02:18:05 +00:00
|
|
|
*result = NS_HTTP_DEFAULT_PORT;
|
2002-08-13 20:33:45 +00:00
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2001-08-07 20:42:57 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHttpHandler::GetProtocolFlags(uint32_t *result)
|
2001-08-07 20:42:57 +00:00
|
|
|
{
|
2009-11-07 02:40:13 +00:00
|
|
|
*result = NS_HTTP_PROTOCOL_FLAGS;
|
2001-08-07 20:42:57 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 07:48:55 +00:00
|
|
|
nsHttpHandler::NewURI(const nsACString &aSpec,
|
|
|
|
const char *aCharset,
|
|
|
|
nsIURI *aBaseURI,
|
|
|
|
nsIURI **aURI)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2003-03-01 02:18:05 +00:00
|
|
|
return ::NewURI(aSpec, aCharset, aBaseURI, NS_HTTP_DEFAULT_PORT, aURI);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::NewChannel(nsIURI *uri, nsIChannel **result)
|
|
|
|
{
|
|
|
|
LOG(("nsHttpHandler::NewChannel\n"));
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(uri);
|
|
|
|
NS_ENSURE_ARG_POINTER(result);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isHttp = false, isHttps = false;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
// Verify that we have been given a valid scheme
|
|
|
|
nsresult rv = uri->SchemeIs("http", &isHttp);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!isHttp) {
|
|
|
|
rv = uri->SchemeIs("https", &isHttps);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!isHttps) {
|
|
|
|
NS_WARNING("Invalid URI scheme");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
}
|
2012-06-10 23:44:50 +00:00
|
|
|
|
2012-09-14 20:27:46 +00:00
|
|
|
return NewProxiedChannel(uri, nullptr, 0, nullptr, result);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2012-08-28 01:21:20 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHttpHandler::AllowPort(int32_t port, const char *scheme, bool *_retval)
|
2001-06-06 00:10:09 +00:00
|
|
|
{
|
2012-08-28 01:21:20 +00:00
|
|
|
// don't override anything.
|
2011-10-17 14:59:28 +00:00
|
|
|
*_retval = false;
|
2001-06-06 00:10:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-09-13 02:21:05 +00:00
|
|
|
// nsHttpHandler::nsIProxiedProtocolHandler
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-09-13 02:21:05 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
NS_IMETHODIMP
|
2001-09-13 02:21:05 +00:00
|
|
|
nsHttpHandler::NewProxiedChannel(nsIURI *uri,
|
2005-03-25 03:41:33 +00:00
|
|
|
nsIProxyInfo* givenProxyInfo,
|
2012-09-14 20:27:46 +00:00
|
|
|
uint32_t proxyResolveFlags,
|
|
|
|
nsIURI *proxyURI,
|
2001-09-13 02:21:05 +00:00
|
|
|
nsIChannel **result)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2010-04-07 08:43:09 +00:00
|
|
|
nsRefPtr<HttpBaseChannel> httpChannel;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-09-13 02:21:05 +00:00
|
|
|
LOG(("nsHttpHandler::NewProxiedChannel [proxyInfo=%p]\n",
|
2005-03-25 03:41:33 +00:00
|
|
|
givenProxyInfo));
|
2012-08-28 01:21:20 +00:00
|
|
|
|
2005-03-25 03:41:33 +00:00
|
|
|
nsCOMPtr<nsProxyInfo> proxyInfo;
|
|
|
|
if (givenProxyInfo) {
|
|
|
|
proxyInfo = do_QueryInterface(givenProxyInfo);
|
|
|
|
NS_ENSURE_ARG(proxyInfo);
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool https;
|
2004-06-11 15:09:36 +00:00
|
|
|
nsresult rv = uri->SchemeIs("https", &https);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
Bug 530952: Electrolysis HTTP Channel implementation. author=jduell, r=bsmedberg, sr=bz
- Supports only primitive xpcshell HTTP requests which don't set/get HTTP
headers, don't do redirects, observers, load groups, or anything else other
than basic things like looking at the reply body, Content-type, Content-length, etc.
- Tested with network/test/unit_ipc/test_simple_wrap.js (patch @ bug 521922)
- Only used if "NECKO_E10S_HTTP" set in environment.
- Force http.h to get #included before any IPDL files, to centralize #define
handling of LOG and to make sure FORCE_PR_LOGGING is set if needed (bug
545995)
2009-09-22 18:55:33 +00:00
|
|
|
if (IsNeckoChild()) {
|
2010-04-07 08:43:09 +00:00
|
|
|
httpChannel = new HttpChannelChild();
|
2011-04-03 02:14:00 +00:00
|
|
|
} else {
|
2010-04-07 08:43:09 +00:00
|
|
|
httpChannel = new nsHttpChannel();
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2012-11-30 01:34:35 +00:00
|
|
|
uint32_t caps = mCapabilities;
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
if (https) {
|
2008-02-07 04:04:56 +00:00
|
|
|
// enable pipelining over SSL if requested
|
|
|
|
if (mPipeliningOverSSL)
|
|
|
|
caps |= NS_HTTP_ALLOW_PIPELINING;
|
|
|
|
|
2011-04-03 02:14:00 +00:00
|
|
|
if (!IsNeckoChild()) {
|
2010-10-01 06:57:01 +00:00
|
|
|
// HACK: make sure PSM gets initialized on the main thread.
|
2010-11-23 12:01:30 +00:00
|
|
|
net_EnsurePSMInit();
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
2002-04-18 22:36:39 +00:00
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2012-09-14 20:27:46 +00:00
|
|
|
rv = httpChannel->Init(uri, caps, proxyInfo, proxyResolveFlags, proxyURI);
|
2010-04-07 08:43:09 +00:00
|
|
|
if (NS_FAILED(rv))
|
2002-04-18 22:36:39 +00:00
|
|
|
return rv;
|
|
|
|
|
2010-04-07 08:43:09 +00:00
|
|
|
httpChannel.forget(result);
|
2002-04-18 22:36:39 +00:00
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2001-09-13 02:21:05 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsIHttpProtocolHandler
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetUserAgent(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = UserAgent();
|
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetAppName(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2010-08-27 07:02:10 +00:00
|
|
|
value = mLegacyAppName;
|
2002-03-20 22:50:33 +00:00
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetAppVersion(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2010-08-27 07:02:10 +00:00
|
|
|
value = mLegacyAppVersion;
|
2002-03-20 22:50:33 +00:00
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetPlatform(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-22 21:25:58 +00:00
|
|
|
value = mPlatform;
|
2002-03-20 22:50:33 +00:00
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetOscpu(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mOscpu;
|
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetMisc(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mMisc;
|
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsIObserver
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::Observe(nsISupports *subject,
|
2001-10-19 20:52:59 +00:00
|
|
|
const char *topic,
|
2001-05-11 21:04:09 +00:00
|
|
|
const PRUnichar *data)
|
|
|
|
{
|
2003-09-17 15:11:47 +00:00
|
|
|
LOG(("nsHttpHandler::Observe [topic=\"%s\"]\n", topic));
|
2002-04-19 22:25:23 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
if (strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0) {
|
2001-10-02 23:04:49 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(subject);
|
|
|
|
if (prefBranch)
|
2006-02-03 14:18:39 +00:00
|
|
|
PrefsChanged(prefBranch, NS_ConvertUTF16toUTF8(data).get());
|
2001-10-02 23:04:49 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
else if (strcmp(topic, "profile-change-net-teardown") == 0 ||
|
|
|
|
strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
2002-12-06 06:38:52 +00:00
|
|
|
|
2012-09-14 20:27:46 +00:00
|
|
|
mHandlerActive = false;
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// clear cache of all authentication credentials.
|
2003-01-18 02:15:14 +00:00
|
|
|
mAuthCache.ClearAll();
|
2012-10-29 20:20:03 +00:00
|
|
|
mPrivateAuthCache.ClearAll();
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2008-08-20 09:35:26 +00:00
|
|
|
// ensure connection manager is shutdown
|
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->Shutdown();
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// need to reset the session start time since cache validation may
|
|
|
|
// depend on this value.
|
|
|
|
mSessionStartTime = NowInSeconds();
|
|
|
|
}
|
2008-08-20 09:35:26 +00:00
|
|
|
else if (strcmp(topic, "profile-change-net-restore") == 0) {
|
2003-01-18 02:15:14 +00:00
|
|
|
// initialize connection manager
|
|
|
|
InitConnectionMgr();
|
2001-12-07 01:40:18 +00:00
|
|
|
}
|
2009-02-23 18:28:17 +00:00
|
|
|
else if (strcmp(topic, "net:clear-active-logins") == 0) {
|
|
|
|
mAuthCache.ClearAll();
|
2012-10-29 20:20:03 +00:00
|
|
|
mPrivateAuthCache.ClearAll();
|
2009-02-23 18:28:17 +00:00
|
|
|
}
|
2010-10-15 00:28:45 +00:00
|
|
|
else if (strcmp(topic, "net:prune-dead-connections") == 0) {
|
|
|
|
if (mConnMgr) {
|
|
|
|
mConnMgr->PruneDeadConnections();
|
|
|
|
}
|
|
|
|
}
|
2012-04-09 14:22:07 +00:00
|
|
|
else if (strcmp(topic, "net:failed-to-process-uri-content") == 0) {
|
2012-03-22 23:39:32 +00:00
|
|
|
nsCOMPtr<nsIURI> uri = do_QueryInterface(subject);
|
|
|
|
if (uri && mConnMgr)
|
|
|
|
mConnMgr->ReportFailedToProcess(uri);
|
|
|
|
}
|
2012-10-29 20:20:03 +00:00
|
|
|
else if (strcmp(topic, "last-pb-context-exited") == 0) {
|
|
|
|
mPrivateAuthCache.ClearAll();
|
|
|
|
}
|
2012-08-28 01:21:20 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-25 12:54:42 +00:00
|
|
|
// nsISpeculativeConnect
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::SpeculativeConnect(nsIURI *aURI,
|
2012-11-14 16:00:44 +00:00
|
|
|
nsIInterfaceRequestor *aCallbacks)
|
2012-04-25 12:54:42 +00:00
|
|
|
{
|
|
|
|
nsIStrictTransportSecurityService* stss = gHttpHandler->GetSTSService();
|
|
|
|
bool isStsHost = false;
|
|
|
|
if (!stss)
|
|
|
|
return NS_OK;
|
2012-08-28 01:21:20 +00:00
|
|
|
|
2012-06-30 14:34:17 +00:00
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(aCallbacks);
|
|
|
|
uint32_t flags = 0;
|
|
|
|
if (loadContext && loadContext->UsePrivateBrowsing())
|
|
|
|
flags |= nsISocketProvider::NO_PERMANENT_STORAGE;
|
2012-04-25 12:54:42 +00:00
|
|
|
nsCOMPtr<nsIURI> clone;
|
2012-06-30 14:34:17 +00:00
|
|
|
if (NS_SUCCEEDED(stss->IsStsURI(aURI, flags, &isStsHost)) && isStsHost) {
|
2012-04-25 12:54:42 +00:00
|
|
|
if (NS_SUCCEEDED(aURI->Clone(getter_AddRefs(clone)))) {
|
|
|
|
clone->SetScheme(NS_LITERAL_CSTRING("https"));
|
|
|
|
aURI = clone.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString scheme;
|
2012-04-25 12:54:42 +00:00
|
|
|
nsresult rv = aURI->GetScheme(scheme);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// If this is HTTPS, make sure PSM is initialized as the channel
|
|
|
|
// creation path may have been bypassed
|
|
|
|
if (scheme.EqualsLiteral("https")) {
|
|
|
|
if (!IsNeckoChild()) {
|
|
|
|
// make sure PSM gets initialized on the main thread.
|
|
|
|
net_EnsurePSMInit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Ensure that this is HTTP or HTTPS, otherwise we don't do preconnect here
|
|
|
|
else if (!scheme.EqualsLiteral("http"))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
// Construct connection info object
|
|
|
|
bool usingSSL = false;
|
|
|
|
rv = aURI->SchemeIs("https", &usingSSL);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString host;
|
2012-04-25 12:54:42 +00:00
|
|
|
rv = aURI->GetAsciiHost(host);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t port = -1;
|
2012-04-25 12:54:42 +00:00
|
|
|
rv = aURI->GetPort(&port);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsHttpConnectionInfo *ci =
|
2012-07-30 14:20:58 +00:00
|
|
|
new nsHttpConnectionInfo(host, port, nullptr, usingSSL);
|
2012-04-25 12:54:42 +00:00
|
|
|
|
2012-11-14 16:00:44 +00:00
|
|
|
return SpeculativeConnect(ci, aCallbacks);
|
2012-04-25 12:54:42 +00:00
|
|
|
}
|
|
|
|
|
2002-08-13 20:33:45 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpsHandler implementation
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-04-25 12:54:42 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS5(nsHttpsHandler,
|
2002-08-13 20:33:45 +00:00
|
|
|
nsIHttpProtocolHandler,
|
|
|
|
nsIProxiedProtocolHandler,
|
|
|
|
nsIProtocolHandler,
|
2012-04-25 12:54:42 +00:00
|
|
|
nsISupportsWeakReference,
|
|
|
|
nsISpeculativeConnect)
|
2002-08-13 20:33:45 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpsHandler::Init()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIProtocolHandler> httpHandler(
|
|
|
|
do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http"));
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(httpHandler.get() != nullptr, "no http handler?");
|
2002-08-13 20:33:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpsHandler::GetScheme(nsACString &aScheme)
|
|
|
|
{
|
2004-06-17 00:13:25 +00:00
|
|
|
aScheme.AssignLiteral("https");
|
2002-08-13 20:33:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHttpsHandler::GetDefaultPort(int32_t *aPort)
|
2002-08-13 20:33:45 +00:00
|
|
|
{
|
2003-03-01 02:18:05 +00:00
|
|
|
*aPort = NS_HTTPS_DEFAULT_PORT;
|
2002-08-13 20:33:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHttpsHandler::GetProtocolFlags(uint32_t *aProtocolFlags)
|
2002-08-13 20:33:45 +00:00
|
|
|
{
|
2012-11-16 20:40:07 +00:00
|
|
|
*aProtocolFlags = NS_HTTP_PROTOCOL_FLAGS | URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT;
|
2009-11-07 02:40:13 +00:00
|
|
|
return NS_OK;
|
2002-08-13 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpsHandler::NewURI(const nsACString &aSpec,
|
|
|
|
const char *aOriginCharset,
|
|
|
|
nsIURI *aBaseURI,
|
|
|
|
nsIURI **_retval)
|
|
|
|
{
|
2003-03-01 02:18:05 +00:00
|
|
|
return ::NewURI(aSpec, aOriginCharset, aBaseURI, NS_HTTPS_DEFAULT_PORT, _retval);
|
2002-08-13 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpsHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval)
|
|
|
|
{
|
2009-11-07 02:40:13 +00:00
|
|
|
NS_ABORT_IF_FALSE(gHttpHandler, "Should have a HTTP handler by now.");
|
|
|
|
if (!gHttpHandler)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-01-18 02:15:14 +00:00
|
|
|
return gHttpHandler->NewChannel(aURI, _retval);
|
2002-08-13 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHttpsHandler::AllowPort(int32_t aPort, const char *aScheme, bool *_retval)
|
2002-08-13 20:33:45 +00:00
|
|
|
{
|
2012-08-28 01:21:20 +00:00
|
|
|
// don't override anything.
|
2011-10-17 14:59:28 +00:00
|
|
|
*_retval = false;
|
2002-08-13 20:33:45 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|