2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:set ts=4 sw=4 sts=4 et cin: */
|
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
|
|
|
|
2013-06-22 09:01:06 -07:00
|
|
|
// HttpLog.h should generally be included first
|
|
|
|
#include "HttpLog.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsHttp.h"
|
|
|
|
#include "nsHttpHandler.h"
|
|
|
|
#include "nsHttpChannel.h"
|
|
|
|
#include "nsHttpAuthCache.h"
|
|
|
|
#include "nsStandardURL.h"
|
2013-07-11 08:39:36 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDOMNavigator.h"
|
2013-07-17 20:23:52 -07:00
|
|
|
#include "nsIMozNavigatorNetwork.h"
|
2013-07-11 08:39:36 -07:00
|
|
|
#include "nsINetworkProperties.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsIStandardURL.h"
|
2013-09-20 02:11:25 -07:00
|
|
|
#include "LoadContextInfo.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
|
|
|
#include "nsIPrefService.h"
|
2012-01-16 17:48:29 -08:00
|
|
|
#include "nsIPrefBranch.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIPrefLocalizedString.h"
|
|
|
|
#include "nsISocketProviderService.h"
|
|
|
|
#include "nsISocketProvider.h"
|
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsNetUtil.h"
|
2010-07-28 11:33:06 -07:00
|
|
|
#include "nsAsyncRedirectVerifyHelper.h"
|
2010-10-28 10:10:03 -07:00
|
|
|
#include "nsSocketTransportService2.h"
|
2011-10-28 11:33:28 -07:00
|
|
|
#include "nsAlgorithm.h"
|
2012-05-25 14:37:01 -07:00
|
|
|
#include "ASpdySession.h"
|
2012-12-28 09:50:23 -08:00
|
|
|
#include "mozIApplicationClearPrivateDataParams.h"
|
2013-04-15 05:50:35 -07:00
|
|
|
#include "EventTokenBucket.h"
|
2013-07-11 08:39:36 -07:00
|
|
|
#include "Tickler.h"
|
2007-07-02 11:20:24 -07:00
|
|
|
#include "nsIXULAppInfo.h"
|
2013-09-22 20:35:52 -07:00
|
|
|
#include "nsICacheSession.h"
|
|
|
|
#include "nsICookieService.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsISiteSecurityService.h"
|
|
|
|
#include "nsIStreamConverterService.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsCRT.h"
|
2014-03-20 11:22:17 -07:00
|
|
|
#include "SpdyZlibReporter.h"
|
|
|
|
#include "nsIMemoryReporter.h"
|
2007-07-02 11:20:24 -07: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 11:55:33 -07:00
|
|
|
#include "mozilla/net/NeckoChild.h"
|
2013-04-15 06:41:27 -07:00
|
|
|
#include "mozilla/Telemetry.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 11:55:33 -07: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 11:10:24 -08:00
|
|
|
#if defined(XP_UNIX)
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(XP_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2007-10-30 08:47:30 -07:00
|
|
|
#if defined(XP_MACOSX)
|
2010-03-10 11:30:11 -08:00
|
|
|
#include <CoreServices/CoreServices.h>
|
2013-12-19 08:42:19 -08:00
|
|
|
#include "nsCocoaFeatures.h"
|
2007-10-30 08:47:30 -07:00
|
|
|
#endif
|
|
|
|
|
2009-08-18 12:05:15 -07: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 11:55:33 -07:00
|
|
|
#include "mozilla/net/HttpChannelChild.h"
|
2009-08-18 12:05:15 -07:00
|
|
|
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
// defined by the socket transport service while active
|
|
|
|
extern PRThread *gSocketThread;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define UA_PREF_PREFIX "general.useragent."
|
2010-08-05 00:09:42 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#define UA_SPARE_PLATFORM
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define HTTP_PREF_PREFIX "network.http."
|
|
|
|
#define INTL_ACCEPT_LANGUAGES "intl.accept_languages"
|
|
|
|
#define BROWSER_PREF_PREFIX "browser.cache."
|
2011-01-05 11:53:21 -08:00
|
|
|
#define DONOTTRACK_HEADER_ENABLED "privacy.donottrackheader.enabled"
|
2012-06-14 14:19:27 -07:00
|
|
|
#define DONOTTRACK_HEADER_VALUE "privacy.donottrackheader.value"
|
2013-08-08 08:49:14 -07:00
|
|
|
#define DONOTTRACK_VALUE_UNSET 2
|
2012-02-27 07:32:09 -08:00
|
|
|
#define TELEMETRY_ENABLED "toolkit.telemetry.enabled"
|
|
|
|
#define ALLOW_EXPERIMENTS "network.allow-experiments"
|
2014-04-13 21:39:13 -07:00
|
|
|
#define SAFE_HINT_HEADER_VALUE "safeHint.enabled"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define UA_PREF(_pref) UA_PREF_PREFIX _pref
|
|
|
|
#define HTTP_PREF(_pref) HTTP_PREF_PREFIX _pref
|
|
|
|
#define BROWSER_PREF(_pref) BROWSER_PREF_PREFIX _pref
|
|
|
|
|
2009-11-06 18:40:13 -08:00
|
|
|
#define NS_HTTP_PROTOCOL_FLAGS (URI_STD | ALLOWS_PROXY | ALLOWS_PROXY_HTTP | URI_LOADABLE_BY_ANYONE)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-01-07 14:05:56 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult
|
|
|
|
NewURI(const nsACString &aSpec,
|
|
|
|
const char *aCharset,
|
|
|
|
nsIURI *aBaseURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aDefaultPort,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIURI **aURI)
|
|
|
|
{
|
2014-02-17 10:53:25 -08:00
|
|
|
nsStandardURL *url = new nsStandardURL();
|
|
|
|
if (!url)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(url);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult rv = url->Init(nsIStandardURL::URLTYPE_AUTHORITY,
|
|
|
|
aDefaultPort, aSpec, aCharset, aBaseURI);
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-02-17 10:53:25 -08:00
|
|
|
NS_RELEASE(url);
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2014-02-17 10:53:25 -08:00
|
|
|
|
|
|
|
*aURI = url; // no QI needed
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler <public>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsHttpHandler *gHttpHandler = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsHttpHandler::nsHttpHandler()
|
2014-02-17 10:53:25 -08:00
|
|
|
: mConnMgr(nullptr)
|
|
|
|
, mHttpVersion(NS_HTTP_VERSION_1_1)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mProxyHttpVersion(NS_HTTP_VERSION_1_1)
|
|
|
|
, mCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
|
|
|
|
, mReferrerLevel(0xff) // by default we always send a referrer
|
2013-11-15 18:46:37 -08:00
|
|
|
, mSpoofReferrerSource(false)
|
|
|
|
, mReferrerTrimmingPolicy(0)
|
|
|
|
, mReferrerXOriginPolicy(0)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mFastFallbackToIPv4(false)
|
2012-09-14 13:27:46 -07:00
|
|
|
, mProxyPipelining(true)
|
2012-02-23 17:58:43 -08:00
|
|
|
, mIdleTimeout(PR_SecondsToInterval(10))
|
|
|
|
, mSpdyTimeout(PR_SecondsToInterval(180))
|
2013-12-18 15:03:48 -08:00
|
|
|
, mResponseTimeout(PR_SecondsToInterval(600))
|
2007-03-22 10:30:00 -07:00
|
|
|
, mMaxRequestAttempts(10)
|
|
|
|
, mMaxRequestDelay(10)
|
2011-03-31 12:38:30 -07:00
|
|
|
, mIdleSynTimeout(250)
|
2012-10-04 18:08:58 -07:00
|
|
|
, mPipeliningEnabled(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mMaxConnections(24)
|
|
|
|
, mMaxPersistentConnectionsPerServer(2)
|
|
|
|
, mMaxPersistentConnectionsPerProxy(4)
|
2012-03-22 16:39:31 -07:00
|
|
|
, mMaxPipelinedRequests(32)
|
|
|
|
, mMaxOptimisticPipelinedRequests(4)
|
|
|
|
, mPipelineAggressive(false)
|
2012-03-22 16:39:31 -07:00
|
|
|
, mMaxPipelineObjectSize(300000)
|
2012-04-11 10:49:32 -07:00
|
|
|
, mPipelineRescheduleOnTimeout(true)
|
|
|
|
, mPipelineRescheduleTimeout(PR_MillisecondsToInterval(1500))
|
2012-04-02 17:36:11 -07:00
|
|
|
, mPipelineReadTimeout(PR_MillisecondsToInterval(30000))
|
2007-03-22 10:30:00 -07:00
|
|
|
, mRedirectionLimit(10)
|
|
|
|
, mPhishyUserPassLength(1)
|
2010-06-02 19:25:01 -07:00
|
|
|
, mQoSBits(0x00)
|
2011-10-17 07:59:28 -07:00
|
|
|
, mPipeliningOverSSL(false)
|
2012-03-22 16:39:31 -07:00
|
|
|
, mEnforceAssocReq(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mLastUniqueID(NowInSeconds())
|
|
|
|
, mSessionStartTime(0)
|
2010-08-27 00:02:10 -07:00
|
|
|
, mLegacyAppName("Mozilla")
|
|
|
|
, mLegacyAppVersion("5.0")
|
2010-08-28 13:42:04 -07:00
|
|
|
, mProduct("Gecko")
|
2011-10-17 07:59:28 -07:00
|
|
|
, mUserAgentIsDirty(true)
|
|
|
|
, mUseCache(true)
|
|
|
|
, mPromptTempRedirect(true)
|
|
|
|
, mSendSecureXSiteReferrer(true)
|
|
|
|
, mEnablePersistentHttpsCaching(false)
|
|
|
|
, mDoNotTrackEnabled(false)
|
2012-06-14 14:19:27 -07:00
|
|
|
, mDoNotTrackValue(1)
|
2014-04-13 21:39:13 -07:00
|
|
|
, mSafeHintEnabled(false)
|
2012-02-27 07:32:09 -08:00
|
|
|
, mTelemetryEnabled(false)
|
|
|
|
, mAllowExperiments(true)
|
2012-09-14 13:27:46 -07:00
|
|
|
, mHandlerActive(false)
|
2011-12-13 07:55:50 -08:00
|
|
|
, mEnableSpdy(false)
|
2012-05-25 14:37:08 -07:00
|
|
|
, mSpdyV3(true)
|
2013-07-26 14:22:46 -07:00
|
|
|
, mSpdyV31(true)
|
2013-10-09 17:21:49 -07:00
|
|
|
, mHttp2DraftEnabled(true)
|
|
|
|
, mEnforceHttp2TlsProfile(true)
|
2011-12-13 07:55:50 -08:00
|
|
|
, mCoalesceSpdy(true)
|
2013-01-30 17:34:25 -08:00
|
|
|
, mSpdyPersistentSettings(false)
|
2013-10-09 17:21:49 -07:00
|
|
|
, mAllowPush(true)
|
2012-05-25 14:37:01 -07:00
|
|
|
, mSpdySendingChunkSize(ASpdySession::kSendingChunkSize)
|
2012-10-06 17:48:20 -07:00
|
|
|
, mSpdySendBufferSize(ASpdySession::kTCPSendBufferSize)
|
2013-05-28 21:07:03 -07:00
|
|
|
, mSpdyPushAllowance(32768)
|
2012-10-25 11:20:08 -07:00
|
|
|
, mSpdyPingThreshold(PR_SecondsToInterval(58))
|
2012-02-23 17:58:43 -08:00
|
|
|
, mSpdyPingTimeout(PR_SecondsToInterval(8))
|
2012-07-23 16:10:00 -07:00
|
|
|
, mConnectTimeout(90000)
|
2013-05-12 07:01:13 -07:00
|
|
|
, mBypassCacheLockThreshold(250.0)
|
2012-12-04 15:06:29 -08:00
|
|
|
, mParallelSpeculativeConnectLimit(6)
|
2013-05-08 08:43:31 -07:00
|
|
|
, mRequestTokenBucketEnabled(true)
|
2013-04-15 05:50:35 -07:00
|
|
|
, mRequestTokenBucketMinParallelism(6)
|
|
|
|
, mRequestTokenBucketHz(100)
|
|
|
|
, mRequestTokenBucketBurst(32)
|
2014-02-06 11:51:38 -08:00
|
|
|
, mTCPKeepaliveShortLivedEnabled(false)
|
|
|
|
, mTCPKeepaliveShortLivedTimeS(60)
|
|
|
|
, mTCPKeepaliveShortLivedIdleTimeS(10)
|
|
|
|
, mTCPKeepaliveLongLivedEnabled(false)
|
|
|
|
, mTCPKeepaliveLongLivedIdleTimeS(600)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
gHttpLog = PR_NewLogModule("nsHttp");
|
|
|
|
#endif
|
|
|
|
|
2013-06-04 16:32:31 -07:00
|
|
|
LOG(("Creating nsHttpHandler [this=%p].\n", this));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-03-20 11:22:17 -07:00
|
|
|
RegisterStrongMemoryReporter(new SpdyZlibReporter());
|
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(!gHttpHandler, "HTTP handler already created!");
|
2007-03-22 10:30:00 -07:00
|
|
|
gHttpHandler = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpHandler::~nsHttpHandler()
|
|
|
|
{
|
2013-06-04 16:32:31 -07:00
|
|
|
LOG(("Deleting nsHttpHandler [this=%p]\n", this));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// make sure the connection manager is shutdown
|
|
|
|
if (mConnMgr) {
|
|
|
|
mConnMgr->Shutdown();
|
2014-02-17 10:53:25 -08:00
|
|
|
NS_RELEASE(mConnMgr);
|
2007-03-22 10:30:00 -07: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 11:55:33 -07: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.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHttp::DestroyAtomTable();
|
2012-10-04 18:08:58 -07:00
|
|
|
if (mPipelineTestTimer) {
|
|
|
|
mPipelineTestTimer->Cancel();
|
|
|
|
mPipelineTestTimer = nullptr;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
gHttpHandler = nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::Init()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
LOG(("nsHttpHandler::Init\n"));
|
|
|
|
|
|
|
|
rv = nsHttp::CreateAtomTable();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2013-08-13 12:36:59 -07:00
|
|
|
nsCOMPtr<nsIIOService> service = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("unable to continue without io service");
|
|
|
|
return rv;
|
|
|
|
}
|
2013-08-13 12:36:59 -07:00
|
|
|
mIOService = new nsMainThreadPtrHolder<nsIIOService>(service);
|
2007-03-22 10:30:00 -07: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 11:55:33 -07:00
|
|
|
if (IsNeckoChild())
|
2009-08-18 12:05:15 -07:00
|
|
|
NeckoChild::InitNeckoChild();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
InitUserAgentComponents();
|
|
|
|
|
|
|
|
// monitor some preference changes
|
2012-01-16 17:48:29 -08:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (prefBranch) {
|
2011-10-17 07:59:28 -07:00
|
|
|
prefBranch->AddObserver(HTTP_PREF_PREFIX, this, true);
|
|
|
|
prefBranch->AddObserver(UA_PREF_PREFIX, this, true);
|
2012-08-27 18:21:20 -07:00
|
|
|
prefBranch->AddObserver(INTL_ACCEPT_LANGUAGES, this, true);
|
2011-10-17 07:59:28 -07:00
|
|
|
prefBranch->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, true);
|
|
|
|
prefBranch->AddObserver(DONOTTRACK_HEADER_ENABLED, this, true);
|
2012-06-14 14:19:27 -07:00
|
|
|
prefBranch->AddObserver(DONOTTRACK_HEADER_VALUE, this, true);
|
2012-02-27 07:32:09 -08:00
|
|
|
prefBranch->AddObserver(TELEMETRY_ENABLED, this, true);
|
2014-02-06 11:51:38 -08:00
|
|
|
prefBranch->AddObserver(HTTP_PREF("tcp_keepalive.short_lived_connections"), this, true);
|
|
|
|
prefBranch->AddObserver(HTTP_PREF("tcp_keepalive.long_lived_connections"), this, true);
|
2014-04-13 21:39:13 -07:00
|
|
|
prefBranch->AddObserver(SAFE_HINT_HEADER_VALUE, this, true);
|
2012-07-30 07:20:58 -07:00
|
|
|
PrefsChanged(prefBranch, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-02-20 19:29:09 -08:00
|
|
|
mMisc.AssignLiteral("rv:" MOZILLA_UAVERSION);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-22 04:52:47 -07:00
|
|
|
mCompatFirefox.AssignLiteral("Firefox/" MOZILLA_UAVERSION);
|
|
|
|
|
2010-08-27 00:02:10 -07: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 13:09:23 -07: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 00:02:10 -07:00
|
|
|
appInfo->GetVersion(mAppVersion);
|
2010-09-02 04:37:41 -07:00
|
|
|
mAppName.StripChars(" ()<>@,;:\\\"/[]?={}");
|
2010-08-27 00:02:10 -07:00
|
|
|
} else {
|
2010-08-30 08:54:46 -07:00
|
|
|
mAppVersion.AssignLiteral(MOZ_APP_UA_VERSION);
|
2010-08-27 00:02:10 -07:00
|
|
|
}
|
|
|
|
|
2012-06-20 14:07:42 -07:00
|
|
|
mSessionStartTime = NowInSeconds();
|
2012-09-14 13:27:46 -07:00
|
|
|
mHandlerActive = true;
|
2012-06-20 14:07:42 -07:00
|
|
|
|
|
|
|
rv = mAuthCache.Init();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-10-29 13:20:03 -07:00
|
|
|
rv = mPrivateAuthCache.Init();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-06-20 14:07:42 -07:00
|
|
|
rv = InitConnectionMgr();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-10 11:48:09 -07:00
|
|
|
#ifdef ANDROID
|
2012-06-20 14:07:42 -07:00
|
|
|
mProductSub.AssignLiteral(MOZILLA_UAVERSION);
|
2012-08-10 11:48:09 -07:00
|
|
|
#else
|
2013-08-01 15:50:45 -07:00
|
|
|
mProductSub.AssignLiteral("20100101");
|
2012-08-10 11:48:09 -07:00
|
|
|
#endif
|
2012-06-20 14:07:42 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#if DEBUG
|
|
|
|
// dump user agent prefs
|
2010-08-27 00:02:10 -07:00
|
|
|
LOG(("> legacy-app-name = %s\n", mLegacyAppName.get()));
|
|
|
|
LOG(("> legacy-app-version = %s\n", mLegacyAppVersion.get()));
|
2007-03-22 10:30:00 -07: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 00:02:10 -07:00
|
|
|
LOG(("> app-name = %s\n", mAppName.get()));
|
|
|
|
LOG(("> app-version = %s\n", mAppVersion.get()));
|
|
|
|
LOG(("> compat-firefox = %s\n", mCompatFirefox.get()));
|
2007-03-22 10:30:00 -07:00
|
|
|
LOG(("> user-agent = %s\n", UserAgent().get()));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Startup the http category
|
|
|
|
// Bring alive the objects in the http-protocol-startup category
|
|
|
|
NS_CreateServicesFromCategory(NS_HTTP_STARTUP_CATEGORY,
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsISupports*>(static_cast<void*>(this)),
|
2012-08-27 18:21:20 -07:00
|
|
|
NS_HTTP_STARTUP_TOPIC);
|
|
|
|
|
2013-08-13 12:36:59 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
|
|
|
|
mObserverService = new nsMainThreadPtrHolder<nsIObserverService>(obsService);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mObserverService) {
|
2011-10-17 07:59:28 -07: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 07:22:07 -07:00
|
|
|
mObserverService->AddObserver(this, "net:failed-to-process-uri-content", true);
|
2012-10-29 13:20:03 -07:00
|
|
|
mObserverService->AddObserver(this, "last-pb-context-exited", true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-27 18:21:20 -07:00
|
|
|
|
2013-04-15 05:50:35 -07:00
|
|
|
MakeNewRequestTokenBucket();
|
2013-07-11 08:39:36 -07:00
|
|
|
mWifiTickler = new Tickler();
|
|
|
|
if (NS_FAILED(mWifiTickler->Init()))
|
|
|
|
mWifiTickler = nullptr;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-15 05:50:35 -07:00
|
|
|
void
|
|
|
|
nsHttpHandler::MakeNewRequestTokenBucket()
|
|
|
|
{
|
|
|
|
if (!mConnMgr)
|
|
|
|
return;
|
|
|
|
|
2014-01-07 14:05:56 -08:00
|
|
|
nsRefPtr<EventTokenBucket> tokenBucket =
|
|
|
|
new EventTokenBucket(RequestTokenBucketHz(),
|
2013-04-15 06:41:27 -07:00
|
|
|
RequestTokenBucketBurst());
|
2013-04-15 05:50:35 -07:00
|
|
|
mConnMgr->UpdateRequestTokenBucket(tokenBucket);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsHttpHandler::InitConnectionMgr()
|
|
|
|
{
|
2008-08-20 02:35:26 -07:00
|
|
|
nsresult rv;
|
2008-08-19 23:43:43 -07:00
|
|
|
|
2013-08-21 18:01:19 -07:00
|
|
|
if (!mConnMgr) {
|
2008-08-20 02:35:26 -07:00
|
|
|
mConnMgr = new nsHttpConnectionMgr();
|
2014-02-17 10:53:25 -08:00
|
|
|
if (!mConnMgr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mConnMgr);
|
2013-08-21 18:01:19 -07:00
|
|
|
}
|
2008-08-20 02:35:26 -07:00
|
|
|
|
|
|
|
rv = mConnMgr->Init(mMaxConnections,
|
|
|
|
mMaxPersistentConnectionsPerServer,
|
|
|
|
mMaxPersistentConnectionsPerProxy,
|
|
|
|
mMaxRequestDelay,
|
2012-03-22 16:39:31 -07:00
|
|
|
mMaxPipelinedRequests,
|
|
|
|
mMaxOptimisticPipelinedRequests);
|
2008-08-20 02:35:26 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-09-14 13:27:46 -07:00
|
|
|
nsHttpHandler::AddStandardRequestHeaders(nsHttpHeaderArray *request)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Add the "User-Agent" header
|
|
|
|
rv = request->SetHeader(nsHttp::User_Agent, UserAgent());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// MIME based content negotiation lives!
|
|
|
|
// Add the "Accept" header
|
|
|
|
rv = request->SetHeader(nsHttp::Accept, mAccept);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Add the "Accept-Language" header
|
|
|
|
if (!mAcceptLanguages.IsEmpty()) {
|
|
|
|
// Add the "Accept-Language" header
|
|
|
|
rv = request->SetHeader(nsHttp::Accept_Language, mAcceptLanguages);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the "Accept-Encoding" header
|
|
|
|
rv = request->SetHeader(nsHttp::Accept_Encoding, mAcceptEncodings);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-09-14 13:27:46 -07:00
|
|
|
// Add the "Do-Not-Track" header
|
|
|
|
if (mDoNotTrackEnabled) {
|
|
|
|
rv = request->SetHeader(nsHttp::DoNotTrack,
|
2012-06-14 14:19:27 -07:00
|
|
|
nsPrintfCString("%d", mDoNotTrackValue));
|
2012-09-14 13:27:46 -07:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2014-04-13 21:39:13 -07:00
|
|
|
// add the "Send Hint" header
|
|
|
|
if (mSafeHintEnabled) {
|
|
|
|
rv = request->SetHeader(nsHttp::Prefer, NS_LITERAL_CSTRING("safe"));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2012-09-14 13:27:46 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::AddConnectionHeader(nsHttpHeaderArray *request,
|
2012-11-29 17:34:35 -08:00
|
|
|
uint32_t caps)
|
2012-09-14 13:27:46 -07:00
|
|
|
{
|
2007-03-22 10:30:00 -07: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 05:38:01 -07:00
|
|
|
// user-agents. But this is not a problem in practice, and the
|
|
|
|
// alternative proxy-connection is worse. see 570283
|
2012-08-27 18:21:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_NAMED_LITERAL_CSTRING(close, "close");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(keepAlive, "keep-alive");
|
|
|
|
|
|
|
|
const nsACString *connectionType = &close;
|
|
|
|
if (caps & NS_HTTP_ALLOW_KEEPALIVE) {
|
|
|
|
connectionType = &keepAlive;
|
|
|
|
}
|
|
|
|
|
2012-09-05 05:38:01 -07:00
|
|
|
return request->SetHeader(nsHttp::Connection, *connectionType);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHttpHandler::IsAcceptableEncoding(const char *enc)
|
|
|
|
{
|
|
|
|
if (!enc)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07: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 16:44:50 -07:00
|
|
|
|
2012-11-01 05:47:29 -07: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 07:20:58 -07:00
|
|
|
return nsHttp::FindToken(mAcceptEncodings.get(), enc, HTTP_LWS ",") != nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::GetStreamConverterService(nsIStreamConverterService **result)
|
|
|
|
{
|
|
|
|
if (!mStreamConvSvc) {
|
|
|
|
nsresult rv;
|
2013-08-13 12:36:59 -07:00
|
|
|
nsCOMPtr<nsIStreamConverterService> service =
|
|
|
|
do_GetService(NS_STREAMCONVERTERSERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
mStreamConvSvc = new nsMainThreadPtrHolder<nsIStreamConverterService>(service);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
*result = mStreamConvSvc;
|
|
|
|
NS_ADDREF(*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-02 15:48:37 -07:00
|
|
|
nsISiteSecurityService*
|
|
|
|
nsHttpHandler::GetSSService()
|
2010-06-03 14:03:17 -07:00
|
|
|
{
|
2013-08-13 12:36:59 -07:00
|
|
|
if (!mSSService) {
|
|
|
|
nsCOMPtr<nsISiteSecurityService> service = do_GetService(NS_SSSERVICE_CONTRACTID);
|
|
|
|
mSSService = new nsMainThreadPtrHolder<nsISiteSecurityService>(service);
|
|
|
|
}
|
2013-08-02 15:48:37 -07:00
|
|
|
return mSSService;
|
2010-06-03 14:03:17 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsICookieService *
|
|
|
|
nsHttpHandler::GetCookieService()
|
|
|
|
{
|
2013-08-13 12:36:59 -07:00
|
|
|
if (!mCookieService) {
|
|
|
|
nsCOMPtr<nsICookieService> service = do_GetService(NS_COOKIESERVICE_CONTRACTID);
|
|
|
|
mCookieService = new nsMainThreadPtrHolder<nsICookieService>(service);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return mCookieService;
|
|
|
|
}
|
|
|
|
|
2012-08-27 18:21:20 -07:00
|
|
|
nsresult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsHttpHandler::GetIOService(nsIIOService** result)
|
|
|
|
{
|
|
|
|
NS_ADDREF(*result = mIOService);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2012-02-27 07:32:09 -08:00
|
|
|
nsHttpHandler::Get32BitsOfPseudoRandom()
|
|
|
|
{
|
|
|
|
// only confirm rand seeding on socket thread
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
|
2012-02-27 07:32:09 -08:00
|
|
|
|
|
|
|
// rand() provides different amounts of PRNG on different platforms.
|
|
|
|
// 15 or 31 bits are common amounts.
|
|
|
|
|
|
|
|
PR_STATIC_ASSERT(RAND_MAX >= 0xfff);
|
2012-08-27 18:21:20 -07:00
|
|
|
|
2012-02-27 07:32:09 -08:00
|
|
|
#if RAND_MAX < 0xffffU
|
2012-08-22 08:56:38 -07:00
|
|
|
return ((uint16_t) rand() << 20) |
|
|
|
|
(((uint16_t) rand() & 0xfff) << 8) |
|
|
|
|
((uint16_t) rand() & 0xff);
|
2012-02-27 07:32:09 -08:00
|
|
|
#elif RAND_MAX < 0xffffffffU
|
2012-08-22 08:56:38 -07:00
|
|
|
return ((uint16_t) rand() << 16) | ((uint16_t) rand() & 0xffff);
|
2012-02-27 07:32:09 -08:00
|
|
|
#else
|
2012-08-22 08:56:38 -07:00
|
|
|
return (uint32_t) rand();
|
2012-02-27 07:32:09 -08:00
|
|
|
#endif
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpHandler::NotifyObservers(nsIHttpChannel *chan, const char *event)
|
|
|
|
{
|
|
|
|
LOG(("nsHttpHandler::NotifyObservers [chan=%x event=\"%s\"]\n", chan, event));
|
|
|
|
if (mObserverService)
|
2012-07-30 07:20:58 -07:00
|
|
|
mObserverService->NotifyObservers(chan, event, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-07-28 11:33:06 -07:00
|
|
|
nsHttpHandler::AsyncOnChannelRedirect(nsIChannel* oldChan, nsIChannel* newChan,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t flags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-07-28 11:33:06 -07:00
|
|
|
// TODO E10S This helper has to be initialized on the other process
|
|
|
|
nsRefPtr<nsAsyncRedirectVerifyHelper> redirectCallbackHelper =
|
|
|
|
new nsAsyncRedirectVerifyHelper();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-28 11:33:06 -07:00
|
|
|
return redirectCallbackHelper->Init(oldChan, newChan, flags);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-18 06:42:32 -08:00
|
|
|
/* static */ nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHttpHandler::GenerateHostPort(const nsCString& host, int32_t port,
|
2010-02-18 06:42:32 -08:00
|
|
|
nsCString& hostLine)
|
|
|
|
{
|
2011-12-22 18:21:20 -08:00
|
|
|
return NS_GenerateHostPort(host, port, hostLine);
|
2010-02-18 06:42:32 -08:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler <private>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const nsAFlatCString &
|
|
|
|
nsHttpHandler::UserAgent()
|
|
|
|
{
|
|
|
|
if (mUserAgentOverride) {
|
|
|
|
LOG(("using general.useragent.override : %s\n", mUserAgentOverride.get()));
|
|
|
|
return mUserAgentOverride;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mUserAgentIsDirty) {
|
|
|
|
BuildUserAgent();
|
2011-10-17 07:59:28 -07:00
|
|
|
mUserAgentIsDirty = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return mUserAgent;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpHandler::BuildUserAgent()
|
|
|
|
{
|
|
|
|
LOG(("nsHttpHandler::BuildUserAgent\n"));
|
|
|
|
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(!mLegacyAppName.IsEmpty() &&
|
|
|
|
!mLegacyAppVersion.IsEmpty(),
|
|
|
|
"HTTP cannot send practical requests without this much");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// preallocate to worst-case size, which should always be better
|
|
|
|
// than if we didn't preallocate at all.
|
2012-08-27 18:21:20 -07:00
|
|
|
mUserAgent.SetCapacity(mLegacyAppName.Length() +
|
|
|
|
mLegacyAppVersion.Length() +
|
2010-08-05 00:09:42 -07:00
|
|
|
#ifndef UA_SPARE_PLATFORM
|
2012-08-27 18:21:20 -07:00
|
|
|
mPlatform.Length() +
|
2010-08-05 00:09:42 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
mOscpu.Length() +
|
|
|
|
mMisc.Length() +
|
|
|
|
mProduct.Length() +
|
|
|
|
mProductSub.Length() +
|
2010-08-27 00:02:10 -07:00
|
|
|
mAppName.Length() +
|
|
|
|
mAppVersion.Length() +
|
|
|
|
mCompatFirefox.Length() +
|
2012-01-31 20:04:23 -08:00
|
|
|
mCompatDevice.Length() +
|
2010-10-15 02:11:19 -07:00
|
|
|
13);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Application portion
|
2010-08-27 00:02:10 -07:00
|
|
|
mUserAgent.Assign(mLegacyAppName);
|
2007-03-22 10:30:00 -07:00
|
|
|
mUserAgent += '/';
|
2010-08-27 00:02:10 -07:00
|
|
|
mUserAgent += mLegacyAppVersion;
|
2007-03-22 10:30:00 -07:00
|
|
|
mUserAgent += ' ';
|
|
|
|
|
|
|
|
// Application comment
|
|
|
|
mUserAgent += '(';
|
2010-08-05 00:09:42 -07:00
|
|
|
#ifndef UA_SPARE_PLATFORM
|
2012-07-31 08:37:26 -07:00
|
|
|
if (!mPlatform.IsEmpty()) {
|
|
|
|
mUserAgent += mPlatform;
|
|
|
|
mUserAgent.AppendLiteral("; ");
|
|
|
|
}
|
2010-08-05 00:09:42 -07:00
|
|
|
#endif
|
2012-01-31 20:04:23 -08:00
|
|
|
if (!mCompatDevice.IsEmpty()) {
|
|
|
|
mUserAgent += mCompatDevice;
|
|
|
|
mUserAgent.AppendLiteral("; ");
|
|
|
|
}
|
2012-07-31 08:37:26 -07:00
|
|
|
else if (!mOscpu.IsEmpty()) {
|
|
|
|
mUserAgent += mOscpu;
|
|
|
|
mUserAgent.AppendLiteral("; ");
|
|
|
|
}
|
2010-08-27 00:02:10 -07:00
|
|
|
mUserAgent += mMisc;
|
2007-03-22 10:30:00 -07:00
|
|
|
mUserAgent += ')';
|
|
|
|
|
|
|
|
// Product portion
|
2010-08-27 00:02:10 -07:00
|
|
|
mUserAgent += ' ';
|
|
|
|
mUserAgent += mProduct;
|
|
|
|
mUserAgent += '/';
|
|
|
|
mUserAgent += mProductSub;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-06-22 04:52:47 -07:00
|
|
|
bool isFirefox = mAppName.EqualsLiteral("Firefox");
|
|
|
|
if (isFirefox || mCompatFirefoxEnabled) {
|
|
|
|
// "Firefox/x.y" (compatibility) app token
|
2007-03-22 10:30:00 -07:00
|
|
|
mUserAgent += ' ';
|
2010-08-27 00:03:10 -07:00
|
|
|
mUserAgent += mCompatFirefox;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-06-22 04:52:47 -07:00
|
|
|
if (!isFirefox) {
|
|
|
|
// App portion
|
|
|
|
mUserAgent += ' ';
|
|
|
|
mUserAgent += mAppName;
|
|
|
|
mUserAgent += '/';
|
|
|
|
mUserAgent += mAppVersion;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-02 01:59:00 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#define WNT_BASE "Windows NT %ld.%ld"
|
|
|
|
#define W64_PREFIX "; Win64"
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsHttpHandler::InitUserAgentComponents()
|
|
|
|
{
|
2012-07-31 08:37:26 -07:00
|
|
|
#ifndef MOZ_UA_OS_AGNOSTIC
|
2012-01-31 20:04:23 -08:00
|
|
|
// Gather platform.
|
2007-03-22 10:30:00 -07:00
|
|
|
mPlatform.AssignLiteral(
|
2010-05-11 10:27:36 -07:00
|
|
|
#if defined(ANDROID)
|
|
|
|
"Android"
|
2007-03-22 10:30:00 -07:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
"Windows"
|
|
|
|
#elif defined(XP_MACOSX)
|
|
|
|
"Macintosh"
|
2009-08-20 08:30:25 -07:00
|
|
|
#elif defined(MOZ_X11)
|
2007-03-22 10:30:00 -07:00
|
|
|
"X11"
|
|
|
|
#endif
|
|
|
|
);
|
2012-07-31 08:37:26 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-25 16:56:53 -07:00
|
|
|
#if defined(ANDROID) || defined(MOZ_B2G)
|
2012-01-31 20:04:23 -08:00
|
|
|
nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1");
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(infoService, "Could not find a system info service");
|
2012-01-31 20:04:23 -08:00
|
|
|
|
2012-08-20 12:25:09 -07:00
|
|
|
bool isTablet;
|
|
|
|
nsresult rv = infoService->GetPropertyAsBool(NS_LITERAL_STRING("tablet"), &isTablet);
|
2013-02-06 11:32:21 -08:00
|
|
|
if (NS_SUCCEEDED(rv) && isTablet)
|
|
|
|
mCompatDevice.AssignLiteral("Tablet");
|
|
|
|
else
|
2012-01-31 20:04:23 -08:00
|
|
|
mCompatDevice.AssignLiteral("Mobile");
|
|
|
|
#endif
|
|
|
|
|
2012-07-31 08:37:26 -07:00
|
|
|
#ifndef MOZ_UA_OS_AGNOSTIC
|
2007-03-22 10:30:00 -07:00
|
|
|
// Gather OS/CPU.
|
2014-02-10 14:57:01 -08:00
|
|
|
#if defined(XP_WIN)
|
2007-03-22 10:30:00 -07:00
|
|
|
OSVERSIONINFO info = { sizeof(OSVERSIONINFO) };
|
2013-10-17 15:25:23 -07:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4996)
|
2007-03-22 10:30:00 -07:00
|
|
|
if (GetVersionEx(&info)) {
|
2013-10-17 15:25:23 -07:00
|
|
|
#pragma warning(pop)
|
2010-05-02 01:59:00 -07:00
|
|
|
const char *format;
|
2011-05-07 01:03:16 -07:00
|
|
|
#if defined _M_IA64
|
2010-05-02 01:59:00 -07:00
|
|
|
format = WNT_BASE W64_PREFIX "; IA64";
|
|
|
|
#elif defined _M_X64 || defined _M_AMD64
|
|
|
|
format = WNT_BASE W64_PREFIX "; x64";
|
2009-08-20 08:30:25 -07:00
|
|
|
#else
|
2010-05-02 01:59:00 -07:00
|
|
|
BOOL isWow64 = FALSE;
|
2012-02-23 06:53:55 -08:00
|
|
|
if (!IsWow64Process(GetCurrentProcess(), &isWow64)) {
|
2010-05-02 01:59:00 -07:00
|
|
|
isWow64 = FALSE;
|
|
|
|
}
|
|
|
|
format = isWow64
|
|
|
|
? WNT_BASE "; WOW64"
|
|
|
|
: WNT_BASE;
|
2009-08-20 08:30:25 -07:00
|
|
|
#endif
|
2010-05-02 01:59:00 -07:00
|
|
|
char *buf = PR_smprintf(format,
|
2007-03-22 10:30:00 -07:00
|
|
|
info.dwMajorVersion,
|
|
|
|
info.dwMinorVersion);
|
|
|
|
if (buf) {
|
|
|
|
mOscpu = buf;
|
|
|
|
PR_smprintf_free(buf);
|
|
|
|
}
|
|
|
|
}
|
2007-10-30 08:47:30 -07:00
|
|
|
#elif defined (XP_MACOSX)
|
|
|
|
#if defined(__ppc__)
|
2007-12-04 17:07:00 -08:00
|
|
|
mOscpu.AssignLiteral("PPC Mac OS X");
|
2009-04-22 06:05:35 -07:00
|
|
|
#elif defined(__i386__) || defined(__x86_64__)
|
2007-03-22 10:30:00 -07:00
|
|
|
mOscpu.AssignLiteral("Intel Mac OS X");
|
2007-10-30 08:47:30 -07:00
|
|
|
#endif
|
2013-12-19 08:42:19 -08:00
|
|
|
SInt32 majorVersion = nsCocoaFeatures::OSXVersionMajor();
|
|
|
|
SInt32 minorVersion = nsCocoaFeatures::OSXVersionMinor();
|
|
|
|
mOscpu += nsPrintfCString(" %d.%d", majorVersion, minorVersion);
|
Bug 627277 - Remove (broken) BeOS support. r=biesi,dwitte,gavin,joe,jorendorff,josh,khuey,mfinkle,neil,Pike,roc,shaver,smontagu,taras
2011-02-19 11:10:24 -08:00
|
|
|
#elif defined (XP_UNIX)
|
2007-03-22 10:30:00 -07:00
|
|
|
struct utsname name;
|
2012-08-27 18:21:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
int ret = uname(&name);
|
|
|
|
if (ret >= 0) {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buf;
|
2007-03-22 10:30:00 -07:00
|
|
|
buf = (char*)name.sysname;
|
|
|
|
|
|
|
|
if (strcmp(name.machine, "x86_64") == 0 &&
|
2012-08-22 08:56:38 -07:00
|
|
|
sizeof(void *) == sizeof(int32_t)) {
|
2007-03-22 10:30:00 -07: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 08:12:01 -07:00
|
|
|
buf += " i686 on x86_64";
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
buf += ' ';
|
|
|
|
|
|
|
|
#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
|
|
|
|
buf += (char*)name.machine;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
mOscpu.Assign(buf);
|
|
|
|
}
|
2012-07-31 08:37:26 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mUserAgentIsDirty = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2011-10-25 08:36:49 -07: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 08:56:38 -07:00
|
|
|
uint32_t maxCount = nsSocketTransportService::gMaxCount;
|
2011-10-25 08:36:49 -07:00
|
|
|
if (maxCount <= 8)
|
|
|
|
maxCount = 1;
|
|
|
|
else
|
|
|
|
maxCount -= 8;
|
|
|
|
|
|
|
|
return maxCount;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void
|
|
|
|
nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t val;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
LOG(("nsHttpHandler::PrefsChanged [pref=%s]\n", pref));
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
#define PREF_CHANGED(p) ((pref == nullptr) || !PL_strcmp(pref, p))
|
2007-03-22 10:30:00 -07:00
|
|
|
#define MULTI_PREF_CHANGED(p) \
|
2012-07-30 07:20:58 -07:00
|
|
|
((pref == nullptr) || !PL_strncmp(pref, p, sizeof(p) - 1))
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// UA components
|
|
|
|
//
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool cVar = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-27 00:02:10 -07:00
|
|
|
if (PREF_CHANGED(UA_PREF("compatMode.firefox"))) {
|
|
|
|
rv = prefs->GetBoolPref(UA_PREF("compatMode.firefox"), &cVar);
|
2012-06-22 04:52:47 -07:00
|
|
|
mCompatFirefoxEnabled = (NS_SUCCEEDED(rv) && cVar);
|
2011-10-17 07:59:28 -07:00
|
|
|
mUserAgentIsDirty = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// general.useragent.override
|
|
|
|
if (PREF_CHANGED(UA_PREF("override"))) {
|
|
|
|
prefs->GetCharPref(UA_PREF("override"),
|
|
|
|
getter_Copies(mUserAgentOverride));
|
2011-10-17 07:59:28 -07:00
|
|
|
mUserAgentIsDirty = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// HTTP options
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("keep-alive.timeout"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("keep-alive.timeout"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-02-23 17:58:43 -08:00
|
|
|
mIdleTimeout = PR_SecondsToInterval(clamped(val, 1, 0xffff));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("request.max-attempts"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("request.max-attempts"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 08:56:38 -07:00
|
|
|
mMaxRequestAttempts = (uint16_t) clamped(val, 1, 0xffff);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("request.max-start-delay"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("request.max-start-delay"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
mMaxRequestDelay = (uint16_t) clamped(val, 0, 0xffff);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_REQUEST_DELAY,
|
|
|
|
mMaxRequestDelay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-18 15:03:48 -08:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("response.timeout"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("response.timeout"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mResponseTimeout = PR_SecondsToInterval(clamped(val, 0, 0xffff));
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("max-connections"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("max-connections"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-25 08:36:49 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
mMaxConnections = (uint16_t) clamped((uint32_t)val,
|
|
|
|
(uint32_t)1, MaxSocketCount());
|
2011-10-25 08:36:49 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_CONNECTIONS,
|
|
|
|
mMaxConnections);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("max-persistent-connections-per-server"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("max-persistent-connections-per-server"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
mMaxPersistentConnectionsPerServer = (uint8_t) clamped(val, 1, 0xff);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_PERSISTENT_CONNECTIONS_PER_HOST,
|
|
|
|
mMaxPersistentConnectionsPerServer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("max-persistent-connections-per-proxy"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("max-persistent-connections-per-proxy"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-08-22 08:56:38 -07:00
|
|
|
mMaxPersistentConnectionsPerProxy = (uint8_t) clamped(val, 1, 0xff);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_PERSISTENT_CONNECTIONS_PER_PROXY,
|
|
|
|
mMaxPersistentConnectionsPerProxy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("sendRefererHeader"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("sendRefererHeader"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 08:56:38 -07:00
|
|
|
mReferrerLevel = (uint8_t) clamped(val, 0, 0xff);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-11-15 18:46:37 -08:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("referer.spoofSource"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("referer.spoofSource"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSpoofReferrerSource = cVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("referer.trimmingPolicy"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("referer.trimmingPolicy"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mReferrerTrimmingPolicy = (uint8_t) clamped(val, 0, 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("referer.XOriginPolicy"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("referer.XOriginPolicy"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mReferrerXOriginPolicy = (uint8_t) clamped(val, 0, 0xff);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("redirection-limit"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("redirection-limit"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 08:56:38 -07:00
|
|
|
mRedirectionLimit = (uint8_t) clamped(val, 0, 0xff);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-03-31 12:38:30 -07: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 08:56:38 -07:00
|
|
|
mIdleSynTimeout = (uint16_t) clamped(val, 0, 3000);
|
2011-03-31 12:38:30 -07:00
|
|
|
}
|
|
|
|
|
2011-08-27 03:49:40 -07: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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("version"))) {
|
|
|
|
nsXPIDLCString httpVersion;
|
|
|
|
prefs->GetCharPref(HTTP_PREF("version"), getter_Copies(httpVersion));
|
|
|
|
if (httpVersion) {
|
|
|
|
if (!PL_strcmp(httpVersion, "1.1"))
|
|
|
|
mHttpVersion = NS_HTTP_VERSION_1_1;
|
|
|
|
else if (!PL_strcmp(httpVersion, "0.9"))
|
|
|
|
mHttpVersion = NS_HTTP_VERSION_0_9;
|
|
|
|
else
|
|
|
|
mHttpVersion = NS_HTTP_VERSION_1_0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("pipelining"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (cVar)
|
|
|
|
mCapabilities |= NS_HTTP_ALLOW_PIPELINING;
|
|
|
|
else
|
|
|
|
mCapabilities &= ~NS_HTTP_ALLOW_PIPELINING;
|
2012-10-04 18:08:58 -07:00
|
|
|
mPipeliningEnabled = cVar;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.maxrequests"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("pipelining.maxrequests"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-03-22 16:39:31 -07:00
|
|
|
mMaxPipelinedRequests = clamped(val, 1, 0xffff);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_PIPELINED_REQUESTS,
|
|
|
|
mMaxPipelinedRequests);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 16:39:31 -07: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 16:39:31 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.maxsize"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("pipelining.maxsize"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mMaxPipelineObjectSize =
|
2012-08-22 08:56:38 -07:00
|
|
|
static_cast<int64_t>(clamped(val, 1000, 100000000));
|
2012-03-22 16:39:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-11 10:49:32 -07: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 08:56:38 -07:00
|
|
|
PR_MillisecondsToInterval((uint16_t) clamped(val, 500, 0xffff));
|
2012-04-11 10:49:32 -07: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 16:39:31 -07: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 10:49:32 -07:00
|
|
|
mPipelineReadTimeout =
|
2012-08-22 08:56:38 -07:00
|
|
|
PR_MillisecondsToInterval((uint16_t) clamped(val, 5000,
|
2012-04-11 10:49:32 -07:00
|
|
|
0xffff));
|
2012-03-22 16:39:31 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 20:04:56 -08:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("pipelining.ssl"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("pipelining.ssl"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mPipeliningOverSSL = cVar;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("proxy.pipelining"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("proxy.pipelining"), &cVar);
|
2012-09-14 13:27:46 -07:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mProxyPipelining = cVar;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-02 19:25:01 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("qos"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("qos"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 08:56:38 -07:00
|
|
|
mQoSBits = (uint8_t) clamped(val, 0, 0xff);
|
2010-06-02 19:25:01 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("sendSecureXSiteReferrer"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("sendSecureXSiteReferrer"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSendSecureXSiteReferrer = cVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("accept.default"))) {
|
|
|
|
nsXPIDLCString accept;
|
|
|
|
rv = prefs->GetCharPref(HTTP_PREF("accept.default"),
|
|
|
|
getter_Copies(accept));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
SetAccept(accept);
|
|
|
|
}
|
2012-08-27 18:21:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("accept-encoding"))) {
|
|
|
|
nsXPIDLCString acceptEncodings;
|
|
|
|
rv = prefs->GetCharPref(HTTP_PREF("accept-encoding"),
|
|
|
|
getter_Copies(acceptEncodings));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
SetAcceptEncodings(acceptEncodings);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("use-cache"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("use-cache"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mUseCache = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("default-socket-type"))) {
|
|
|
|
nsXPIDLCString sval;
|
|
|
|
rv = prefs->GetCharPref(HTTP_PREF("default-socket-type"),
|
|
|
|
getter_Copies(sval));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (sval.IsEmpty())
|
|
|
|
mDefaultSocketType.Adopt(0);
|
|
|
|
else {
|
|
|
|
// verify that this socket type is actually valid
|
|
|
|
nsCOMPtr<nsISocketProviderService> sps(
|
2009-06-27 18:42:51 -07:00
|
|
|
do_GetService(NS_SOCKETPROVIDERSERVICE_CONTRACTID));
|
2008-08-18 17:19:27 -07:00
|
|
|
if (sps) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsISocketProvider> sp;
|
|
|
|
rv = sps->GetSocketProvider(sval, getter_AddRefs(sp));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// OK, this looks like a valid socket provider.
|
|
|
|
mDefaultSocketType.Assign(sval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-24 11:46:51 -08: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 16:39:31 -07: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-27 18:21:20 -07:00
|
|
|
// enable Persistent caching for HTTPS - bug#205921
|
2007-03-22 10:30:00 -07:00
|
|
|
if (PREF_CHANGED(BROWSER_PREF("disk_cache_ssl"))) {
|
2011-10-17 07:59:28 -07:00
|
|
|
cVar = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
rv = prefs->GetBoolPref(BROWSER_PREF("disk_cache_ssl"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mEnablePersistentHttpsCaching = cVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("phishy-userpass-length"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("phishy-userpass-length"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-08-22 08:56:38 -07:00
|
|
|
mPhishyUserPassLength = (uint8_t) clamped(val, 0, 0xff);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-12-13 07:55:50 -08: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 14:37:08 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.enabled.v3"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.enabled.v3"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSpdyV3 = cVar;
|
|
|
|
}
|
|
|
|
|
2013-07-26 14:22:46 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.enabled.v3-1"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.enabled.v3-1"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSpdyV31 = cVar;
|
|
|
|
}
|
|
|
|
|
2013-10-09 17:21:49 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.enabled.http2draft"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.enabled.http2draft"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mHttp2DraftEnabled = cVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.enforce-tls-profile"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.enforce-tls-profile"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mEnforceHttp2TlsProfile = cVar;
|
|
|
|
}
|
|
|
|
|
2011-12-13 07:55:50 -08:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.coalesce-hostnames"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.coalesce-hostnames"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mCoalesceSpdy = cVar;
|
|
|
|
}
|
|
|
|
|
2013-01-30 17:34:25 -08:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.persistent-settings"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.persistent-settings"),
|
|
|
|
&cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mSpdyPersistentSettings = cVar;
|
|
|
|
}
|
|
|
|
|
2011-12-13 07:55:50 -08:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.timeout"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("spdy.timeout"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-02-23 17:58:43 -08:00
|
|
|
mSpdyTimeout = PR_SecondsToInterval(clamped(val, 1, 0xffff));
|
2011-12-13 07:55:50 -08:00
|
|
|
}
|
|
|
|
|
2012-01-25 21:15:26 -08:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.chunk-size"))) {
|
2013-10-09 17:21:49 -07:00
|
|
|
// keep this within http/2 ranges of 1 to 2^14-1
|
2012-01-25 21:15:26 -08:00
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("spdy.chunk-size"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2013-10-09 17:21:49 -07:00
|
|
|
mSpdySendingChunkSize = (uint32_t) clamped(val, 1, 0x3fff);
|
2012-01-25 21:15:26 -08:00
|
|
|
}
|
|
|
|
|
2012-02-23 17:58:43 -08: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 08:56:38 -07:00
|
|
|
PR_SecondsToInterval((uint16_t) clamped(val, 0, 0x7fffffff));
|
2012-02-23 17:58:43 -08: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 08:56:38 -07:00
|
|
|
PR_SecondsToInterval((uint16_t) clamped(val, 0, 0x7fffffff));
|
2012-02-23 17:58:43 -08:00
|
|
|
}
|
|
|
|
|
2013-05-28 21:07:03 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.allow-push"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("spdy.allow-push"),
|
|
|
|
&cVar);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2013-10-09 17:21:49 -07:00
|
|
|
mAllowPush = cVar;
|
2013-05-28 21:07:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("spdy.push-allowance"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("spdy.push-allowance"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mSpdyPushAllowance =
|
|
|
|
static_cast<uint32_t>
|
|
|
|
(clamped(val, 1024, static_cast<int32_t>(ASpdySession::kInitialRwin)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-06 17:48:20 -07: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 16:10:00 -07: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;
|
|
|
|
}
|
|
|
|
|
2013-05-12 07:01:13 -07:00
|
|
|
// The maximum amount of time the cache session lock can be held
|
|
|
|
// before a new transaction bypasses the cache. In milliseconds.
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("bypass-cachelock-threshold"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("bypass-cachelock-threshold"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
// the pref and variable are both in milliseconds
|
|
|
|
mBypassCacheLockThreshold =
|
|
|
|
static_cast<double>(clamped(val, 0, 0x7ffffff));
|
|
|
|
}
|
|
|
|
|
2012-12-04 15:06:29 -08: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 15:06:29 -08: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))
|
2013-11-13 05:31:20 -08:00
|
|
|
mCriticalRequestPrioritization = cVar;
|
2012-12-04 15:06:29 -08:00
|
|
|
}
|
|
|
|
|
2012-07-09 15:07:57 -07: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();
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// INTL options
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(INTL_ACCEPT_LANGUAGES)) {
|
|
|
|
nsCOMPtr<nsIPrefLocalizedString> pls;
|
|
|
|
prefs->GetComplexValue(INTL_ACCEPT_LANGUAGES,
|
|
|
|
NS_GET_IID(nsIPrefLocalizedString),
|
|
|
|
getter_AddRefs(pls));
|
|
|
|
if (pls) {
|
|
|
|
nsXPIDLString uval;
|
|
|
|
pls->ToString(getter_Copies(uval));
|
|
|
|
if (uval)
|
|
|
|
SetAcceptLanguages(NS_ConvertUTF16toUTF8(uval).get());
|
2012-08-27 18:21:20 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-01-05 11:53:21 -08:00
|
|
|
//
|
|
|
|
// Tracking options
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(DONOTTRACK_HEADER_ENABLED)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
cVar = false;
|
2011-01-05 11:53:21 -08:00
|
|
|
rv = prefs->GetBoolPref(DONOTTRACK_HEADER_ENABLED, &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mDoNotTrackEnabled = cVar;
|
|
|
|
}
|
|
|
|
}
|
2012-06-14 14:19:27 -07:00
|
|
|
if (PREF_CHANGED(DONOTTRACK_HEADER_VALUE)) {
|
|
|
|
val = 1;
|
|
|
|
rv = prefs->GetIntPref(DONOTTRACK_HEADER_VALUE, &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mDoNotTrackValue = val;
|
|
|
|
}
|
|
|
|
}
|
2011-01-05 11:53:21 -08:00
|
|
|
|
2014-04-13 21:39:13 -07:00
|
|
|
// Hint option
|
|
|
|
if (PREF_CHANGED(SAFE_HINT_HEADER_VALUE)) {
|
|
|
|
cVar = false;
|
|
|
|
rv = prefs->GetBoolPref(SAFE_HINT_HEADER_VALUE, &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mSafeHintEnabled = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-15 06:41:27 -07:00
|
|
|
// toggle to true anytime a token bucket related pref is changed.. that
|
|
|
|
// includes telemetry and allow-experiments because of the abtest profile
|
|
|
|
bool requestTokenBucketUpdated = false;
|
|
|
|
|
2012-02-27 07:32:09 -08:00
|
|
|
//
|
|
|
|
// Telemetry
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(TELEMETRY_ENABLED)) {
|
|
|
|
cVar = false;
|
2013-04-15 06:41:27 -07:00
|
|
|
requestTokenBucketUpdated = true;
|
2012-02-27 07:32:09 -08:00
|
|
|
rv = prefs->GetBoolPref(TELEMETRY_ENABLED, &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mTelemetryEnabled = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// network.allow-experiments
|
|
|
|
//
|
|
|
|
if (PREF_CHANGED(ALLOW_EXPERIMENTS)) {
|
|
|
|
cVar = true;
|
2013-04-15 06:41:27 -07:00
|
|
|
requestTokenBucketUpdated = true;
|
2012-02-27 07:32:09 -08:00
|
|
|
rv = prefs->GetBoolPref(ALLOW_EXPERIMENTS, &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mAllowExperiments = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-04 18:08:58 -07: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-15 05:50:35 -07:00
|
|
|
if (requestTokenBucketUpdated) {
|
|
|
|
MakeNewRequestTokenBucket();
|
|
|
|
}
|
2012-10-04 18:08:58 -07:00
|
|
|
|
2013-04-15 06:41:27 -07:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("pacing.requests.enabled"))) {
|
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("pacing.requests.enabled"),
|
|
|
|
&cVar);
|
|
|
|
if (NS_SUCCEEDED(rv)){
|
|
|
|
requestTokenBucketUpdated = true;
|
|
|
|
mRequestTokenBucketEnabled = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("pacing.requests.min-parallelism"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("pacing.requests.min-parallelism"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mRequestTokenBucketMinParallelism = static_cast<uint16_t>(clamped(val, 1, 1024));
|
|
|
|
}
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("pacing.requests.hz"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("pacing.requests.hz"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mRequestTokenBucketHz = static_cast<uint32_t>(clamped(val, 1, 10000));
|
|
|
|
requestTokenBucketUpdated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("pacing.requests.burst"))) {
|
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("pacing.requests.burst"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mRequestTokenBucketBurst = val ? val : 1;
|
|
|
|
requestTokenBucketUpdated = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (requestTokenBucketUpdated) {
|
|
|
|
mRequestTokenBucket =
|
2014-01-07 14:05:56 -08:00
|
|
|
new EventTokenBucket(RequestTokenBucketHz(),
|
|
|
|
RequestTokenBucketBurst());
|
2013-04-15 06:41:27 -07:00
|
|
|
}
|
|
|
|
|
2014-02-06 11:51:38 -08:00
|
|
|
// Keepalive values for initial and idle connections.
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("tcp_keepalive.short_lived_connections"))) {
|
|
|
|
rv = prefs->GetBoolPref(
|
|
|
|
HTTP_PREF("tcp_keepalive.short_lived_connections"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv) && cVar != mTCPKeepaliveShortLivedEnabled) {
|
|
|
|
mTCPKeepaliveShortLivedEnabled = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("tcp_keepalive.short_lived_time"))) {
|
|
|
|
rv = prefs->GetIntPref(
|
|
|
|
HTTP_PREF("tcp_keepalive.short_lived_time"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv) && val > 0)
|
|
|
|
mTCPKeepaliveShortLivedTimeS = clamped(val, 1, 300); // Max 5 mins.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("tcp_keepalive.short_lived_idle_time"))) {
|
|
|
|
rv = prefs->GetIntPref(
|
|
|
|
HTTP_PREF("tcp_keepalive.short_lived_idle_time"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv) && val > 0)
|
|
|
|
mTCPKeepaliveShortLivedIdleTimeS = clamped(val,
|
|
|
|
1, kMaxTCPKeepIdle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keepalive values for Long-lived Connections.
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("tcp_keepalive.long_lived_connections"))) {
|
|
|
|
rv = prefs->GetBoolPref(
|
|
|
|
HTTP_PREF("tcp_keepalive.long_lived_connections"), &cVar);
|
|
|
|
if (NS_SUCCEEDED(rv) && cVar != mTCPKeepaliveLongLivedEnabled) {
|
|
|
|
mTCPKeepaliveLongLivedEnabled = cVar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(HTTP_PREF("tcp_keepalive.long_lived_idle_time"))) {
|
|
|
|
rv = prefs->GetIntPref(
|
|
|
|
HTTP_PREF("tcp_keepalive.long_lived_idle_time"), &val);
|
|
|
|
if (NS_SUCCEEDED(rv) && val > 0)
|
|
|
|
mTCPKeepaliveLongLivedIdleTimeS = clamped(val,
|
|
|
|
1, kMaxTCPKeepIdle);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#undef PREF_CHANGED
|
|
|
|
#undef MULTI_PREF_CHANGED
|
|
|
|
}
|
|
|
|
|
2012-10-04 18:08:58 -07: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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07: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"
|
|
|
|
* returns: "en,ja;q=0.5"
|
|
|
|
*
|
|
|
|
* passing: "en, ja, fr_CA"
|
|
|
|
* returns: "en,ja;q=0.7,fr_CA;q=0.3"
|
|
|
|
*/
|
|
|
|
static nsresult
|
|
|
|
PrepareAcceptLanguages(const char *i_AcceptLanguages, nsACString &o_AcceptLanguages)
|
|
|
|
{
|
|
|
|
if (!i_AcceptLanguages)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-08-29 19:49:31 -07:00
|
|
|
uint32_t n, count_n, size, wrote;
|
2007-03-22 10:30:00 -07:00
|
|
|
double q, dec;
|
|
|
|
char *p, *p2, *token, *q_Accept, *o_Accept;
|
|
|
|
const char *comma;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t available;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-08-22 03:31:48 -07:00
|
|
|
o_Accept = strdup(i_AcceptLanguages);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!o_Accept)
|
|
|
|
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];
|
|
|
|
if (!q_Accept) {
|
2013-08-22 03:31:48 -07:00
|
|
|
free(o_Accept);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
*q_Accept = '\0';
|
|
|
|
q = 1.0;
|
|
|
|
dec = q / (double) n;
|
2012-08-29 19:49:31 -07:00
|
|
|
count_n = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
p2 = q_Accept;
|
|
|
|
for (token = nsCRT::strtok(o_Accept, ",", &p);
|
|
|
|
token != (char *) 0;
|
|
|
|
token = nsCRT::strtok(p, ",", &p))
|
|
|
|
{
|
|
|
|
token = net_FindCharNotInSet(token, HTTP_LWS);
|
|
|
|
char* trim;
|
|
|
|
trim = net_FindCharInSet(token, ";" HTTP_LWS);
|
|
|
|
if (trim != (char*)0) // remove "; q=..." if present
|
|
|
|
*trim = '\0';
|
|
|
|
|
|
|
|
if (*token != '\0') {
|
2012-08-29 19:49:31 -07:00
|
|
|
comma = count_n++ != 0 ? "," : ""; // delimiter if not first item
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t u = QVAL_TO_UINT(q);
|
2012-08-29 19:49:31 -07: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 {
|
2007-03-22 10:30:00 -07:00
|
|
|
wrote = PR_snprintf(p2, available, "%s%s", comma, token);
|
2012-08-29 19:49:31 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
q -= dec;
|
|
|
|
p2 += wrote;
|
|
|
|
available -= wrote;
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(available > 0, "allocated string not long enough");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2013-08-22 03:31:48 -07:00
|
|
|
free(o_Accept);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
o_AcceptLanguages.Assign((const char *) q_Accept);
|
|
|
|
delete [] q_Accept;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-27 18:21:20 -07:00
|
|
|
nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buf;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv = PrepareAcceptLanguages(aAcceptLanguages, buf);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
mAcceptLanguages.Assign(buf);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-27 18:21:20 -07:00
|
|
|
nsHttpHandler::SetAccept(const char *aAccept)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mAccept = aAccept;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-27 18:21:20 -07:00
|
|
|
nsHttpHandler::SetAcceptEncodings(const char *aAcceptEncodings)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mAcceptEncodings = aAcceptEncodings;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsISupports
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsHttpHandler,
|
|
|
|
nsIHttpProtocolHandler,
|
|
|
|
nsIProxiedProtocolHandler,
|
|
|
|
nsIProtocolHandler,
|
|
|
|
nsIObserver,
|
|
|
|
nsISupportsWeakReference,
|
|
|
|
nsISpeculativeConnect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsIProtocolHandler
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::GetScheme(nsACString &aScheme)
|
|
|
|
{
|
|
|
|
aScheme.AssignLiteral("http");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHttpHandler::GetDefaultPort(int32_t *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*result = NS_HTTP_DEFAULT_PORT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHttpHandler::GetProtocolFlags(uint32_t *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-11-06 18:40:13 -08:00
|
|
|
*result = NS_HTTP_PROTOCOL_FLAGS;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::NewURI(const nsACString &aSpec,
|
|
|
|
const char *aCharset,
|
|
|
|
nsIURI *aBaseURI,
|
|
|
|
nsIURI **aURI)
|
|
|
|
{
|
2014-01-07 14:05:56 -08:00
|
|
|
return mozilla::net::NewURI(aSpec, aCharset, aBaseURI, NS_HTTP_DEFAULT_PORT, aURI);
|
2007-03-22 10:30:00 -07: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-28 23:19:26 -07:00
|
|
|
bool isHttp = false, isHttps = false;
|
2007-03-22 10:30:00 -07: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 16:44:50 -07:00
|
|
|
|
2012-09-14 13:27:46 -07:00
|
|
|
return NewProxiedChannel(uri, nullptr, 0, nullptr, result);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-27 18:21:20 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHttpHandler::AllowPort(int32_t port, const char *scheme, bool *_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-27 18:21:20 -07:00
|
|
|
// don't override anything.
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsIProxiedProtocolHandler
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::NewProxiedChannel(nsIURI *uri,
|
|
|
|
nsIProxyInfo* givenProxyInfo,
|
2012-09-14 13:27:46 -07:00
|
|
|
uint32_t proxyResolveFlags,
|
|
|
|
nsIURI *proxyURI,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIChannel **result)
|
|
|
|
{
|
2010-04-07 01:43:09 -07:00
|
|
|
nsRefPtr<HttpBaseChannel> httpChannel;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
LOG(("nsHttpHandler::NewProxiedChannel [proxyInfo=%p]\n",
|
|
|
|
givenProxyInfo));
|
2012-08-27 18:21:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsProxyInfo> proxyInfo;
|
|
|
|
if (givenProxyInfo) {
|
|
|
|
proxyInfo = do_QueryInterface(givenProxyInfo);
|
|
|
|
NS_ENSURE_ARG(proxyInfo);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool https;
|
2007-03-22 10:30:00 -07: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 11:55:33 -07:00
|
|
|
if (IsNeckoChild()) {
|
2010-04-07 01:43:09 -07:00
|
|
|
httpChannel = new HttpChannelChild();
|
2011-04-02 19:14:00 -07:00
|
|
|
} else {
|
2010-04-07 01:43:09 -07:00
|
|
|
httpChannel = new nsHttpChannel();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-29 17:34:35 -08:00
|
|
|
uint32_t caps = mCapabilities;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (https) {
|
2008-02-06 20:04:56 -08:00
|
|
|
// enable pipelining over SSL if requested
|
|
|
|
if (mPipeliningOverSSL)
|
|
|
|
caps |= NS_HTTP_ALLOW_PIPELINING;
|
2013-06-21 20:33:46 -07:00
|
|
|
}
|
2008-02-06 20:04:56 -08:00
|
|
|
|
2013-06-21 20:33:46 -07:00
|
|
|
if (!IsNeckoChild()) {
|
|
|
|
// HACK: make sure PSM gets initialized on the main thread.
|
|
|
|
net_EnsurePSMInit();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-09-14 13:27:46 -07:00
|
|
|
rv = httpChannel->Init(uri, caps, proxyInfo, proxyResolveFlags, proxyURI);
|
2010-04-07 01:43:09 -07:00
|
|
|
if (NS_FAILED(rv))
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
|
2010-04-07 01:43:09 -07:00
|
|
|
httpChannel.forget(result);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsIHttpProtocolHandler
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::GetUserAgent(nsACString &value)
|
|
|
|
{
|
|
|
|
value = UserAgent();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::GetAppName(nsACString &value)
|
|
|
|
{
|
2010-08-27 00:02:10 -07:00
|
|
|
value = mLegacyAppName;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::GetAppVersion(nsACString &value)
|
|
|
|
{
|
2010-08-27 00:02:10 -07:00
|
|
|
value = mLegacyAppVersion;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::GetPlatform(nsACString &value)
|
|
|
|
{
|
|
|
|
value = mPlatform;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::GetOscpu(nsACString &value)
|
|
|
|
{
|
|
|
|
value = mOscpu;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::GetMisc(nsACString &value)
|
|
|
|
{
|
|
|
|
value = mMisc;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-28 09:50:23 -08:00
|
|
|
/*static*/ void
|
|
|
|
nsHttpHandler::GetCacheSessionNameForStoragePolicy(
|
|
|
|
nsCacheStoragePolicy storagePolicy,
|
|
|
|
bool isPrivate,
|
|
|
|
uint32_t appId,
|
|
|
|
bool inBrowser,
|
|
|
|
nsACString& sessionName)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!isPrivate || storagePolicy == nsICache::STORE_IN_MEMORY);
|
|
|
|
|
|
|
|
switch (storagePolicy) {
|
|
|
|
case nsICache::STORE_IN_MEMORY:
|
|
|
|
sessionName.AssignASCII(isPrivate ? "HTTP-memory-only-PB" : "HTTP-memory-only");
|
|
|
|
break;
|
|
|
|
case nsICache::STORE_OFFLINE:
|
|
|
|
sessionName.AssignLiteral("HTTP-offline");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sessionName.AssignLiteral("HTTP");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (appId != NECKO_NO_APP_ID || inBrowser) {
|
|
|
|
sessionName.Append('~');
|
|
|
|
sessionName.AppendInt(appId);
|
|
|
|
sessionName.Append('~');
|
|
|
|
sessionName.AppendInt(inBrowser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsIObserver
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::Observe(nsISupports *subject,
|
|
|
|
const char *topic,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *data)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
LOG(("nsHttpHandler::Observe [topic=\"%s\"]\n", topic));
|
|
|
|
|
|
|
|
if (strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) == 0) {
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(subject);
|
|
|
|
if (prefBranch)
|
|
|
|
PrefsChanged(prefBranch, NS_ConvertUTF16toUTF8(data).get());
|
|
|
|
}
|
|
|
|
else if (strcmp(topic, "profile-change-net-teardown") == 0 ||
|
|
|
|
strcmp(topic, NS_XPCOM_SHUTDOWN_OBSERVER_ID) == 0) {
|
|
|
|
|
2012-09-14 13:27:46 -07:00
|
|
|
mHandlerActive = false;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// clear cache of all authentication credentials.
|
|
|
|
mAuthCache.ClearAll();
|
2012-10-29 13:20:03 -07:00
|
|
|
mPrivateAuthCache.ClearAll();
|
2013-07-11 08:39:36 -07:00
|
|
|
if (mWifiTickler)
|
|
|
|
mWifiTickler->Cancel();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-20 02:35:26 -07:00
|
|
|
// ensure connection manager is shutdown
|
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->Shutdown();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// need to reset the session start time since cache validation may
|
|
|
|
// depend on this value.
|
|
|
|
mSessionStartTime = NowInSeconds();
|
2014-03-20 16:37:47 -07:00
|
|
|
|
|
|
|
if (!mDoNotTrackEnabled) {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNT_USAGE, DONOTTRACK_VALUE_UNSET);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Telemetry::Accumulate(Telemetry::DNT_USAGE, mDoNotTrackValue);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-08-20 02:35:26 -07:00
|
|
|
else if (strcmp(topic, "profile-change-net-restore") == 0) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// initialize connection manager
|
|
|
|
InitConnectionMgr();
|
|
|
|
}
|
2009-02-23 10:28:17 -08:00
|
|
|
else if (strcmp(topic, "net:clear-active-logins") == 0) {
|
|
|
|
mAuthCache.ClearAll();
|
2012-10-29 13:20:03 -07:00
|
|
|
mPrivateAuthCache.ClearAll();
|
2009-02-23 10:28:17 -08:00
|
|
|
}
|
2010-10-14 17:28:45 -07:00
|
|
|
else if (strcmp(topic, "net:prune-dead-connections") == 0) {
|
|
|
|
if (mConnMgr) {
|
|
|
|
mConnMgr->PruneDeadConnections();
|
|
|
|
}
|
|
|
|
}
|
2012-04-09 07:22:07 -07:00
|
|
|
else if (strcmp(topic, "net:failed-to-process-uri-content") == 0) {
|
2012-03-22 16:39:32 -07:00
|
|
|
nsCOMPtr<nsIURI> uri = do_QueryInterface(subject);
|
|
|
|
if (uri && mConnMgr)
|
|
|
|
mConnMgr->ReportFailedToProcess(uri);
|
|
|
|
}
|
2012-10-29 13:20:03 -07:00
|
|
|
else if (strcmp(topic, "last-pb-context-exited") == 0) {
|
|
|
|
mPrivateAuthCache.ClearAll();
|
|
|
|
}
|
2012-08-27 18:21:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-04-25 05:54:42 -07:00
|
|
|
// nsISpeculativeConnect
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpHandler::SpeculativeConnect(nsIURI *aURI,
|
2012-11-14 08:00:44 -08:00
|
|
|
nsIInterfaceRequestor *aCallbacks)
|
2012-04-25 05:54:42 -07:00
|
|
|
{
|
2013-11-16 05:54:44 -08:00
|
|
|
if (!mHandlerActive)
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-08-02 15:48:37 -07:00
|
|
|
nsISiteSecurityService* sss = gHttpHandler->GetSSService();
|
2012-04-25 05:54:42 -07:00
|
|
|
bool isStsHost = false;
|
2013-08-02 15:48:37 -07:00
|
|
|
if (!sss)
|
2012-04-25 05:54:42 -07:00
|
|
|
return NS_OK;
|
2012-08-27 18:21:20 -07:00
|
|
|
|
2012-06-30 07:34:17 -07:00
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(aCallbacks);
|
|
|
|
uint32_t flags = 0;
|
|
|
|
if (loadContext && loadContext->UsePrivateBrowsing())
|
|
|
|
flags |= nsISocketProvider::NO_PERMANENT_STORAGE;
|
2012-04-25 05:54:42 -07:00
|
|
|
nsCOMPtr<nsIURI> clone;
|
2013-08-02 16:23:18 -07:00
|
|
|
if (NS_SUCCEEDED(sss->IsSecureURI(nsISiteSecurityService::HEADER_HSTS,
|
|
|
|
aURI, flags, &isStsHost)) && isStsHost) {
|
2012-04-25 05:54:42 -07:00
|
|
|
if (NS_SUCCEEDED(aURI->Clone(getter_AddRefs(clone)))) {
|
|
|
|
clone->SetScheme(NS_LITERAL_CSTRING("https"));
|
|
|
|
aURI = clone.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString scheme;
|
2012-04-25 05:54:42 -07: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-01 19:35:17 -07:00
|
|
|
nsAutoCString host;
|
2012-04-25 05:54:42 -07:00
|
|
|
rv = aURI->GetAsciiHost(host);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t port = -1;
|
2012-04-25 05:54:42 -07:00
|
|
|
rv = aURI->GetPort(&port);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2014-04-26 12:01:39 -07:00
|
|
|
nsAutoCString username;
|
|
|
|
aURI->GetUsername(username);
|
|
|
|
|
2012-04-25 05:54:42 -07:00
|
|
|
nsHttpConnectionInfo *ci =
|
2014-04-26 12:01:39 -07:00
|
|
|
new nsHttpConnectionInfo(host, port, username, nullptr, usingSSL);
|
2012-04-25 05:54:42 -07:00
|
|
|
|
2012-11-14 08:00:44 -08:00
|
|
|
return SpeculativeConnect(ci, aCallbacks);
|
2012-04-25 05:54:42 -07:00
|
|
|
}
|
|
|
|
|
2013-07-11 08:39:36 -07:00
|
|
|
void
|
2014-02-25 17:39:08 -08:00
|
|
|
nsHttpHandler::TickleWifi(nsIInterfaceRequestor *cb)
|
2013-07-11 08:39:36 -07:00
|
|
|
{
|
2014-02-25 17:39:08 -08:00
|
|
|
if (!cb || !mWifiTickler)
|
2013-07-11 08:39:36 -07:00
|
|
|
return;
|
2013-09-22 20:01:10 -07:00
|
|
|
|
2014-02-25 17:39:08 -08:00
|
|
|
// If B2G requires a similar mechanism nsINetworkManager, currently only avail
|
|
|
|
// on B2G, contains the necessary information on wifi and gateway
|
2013-07-11 08:39:36 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> domWindow;
|
|
|
|
cb->GetInterface(NS_GET_IID(nsIDOMWindow), getter_AddRefs(domWindow));
|
|
|
|
if (!domWindow)
|
2014-02-25 17:39:08 -08:00
|
|
|
return;
|
2013-09-22 20:01:10 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNavigator> domNavigator;
|
|
|
|
domWindow->GetNavigator(getter_AddRefs(domNavigator));
|
|
|
|
nsCOMPtr<nsIMozNavigatorNetwork> networkNavigator =
|
|
|
|
do_QueryInterface(domNavigator);
|
|
|
|
if (!networkNavigator)
|
2014-02-25 17:39:08 -08:00
|
|
|
return;
|
2013-09-22 20:01:10 -07:00
|
|
|
|
2014-03-04 19:54:55 -08:00
|
|
|
nsCOMPtr<nsINetworkProperties> networkProperties;
|
|
|
|
networkNavigator->GetProperties(getter_AddRefs(networkProperties));
|
2013-09-22 20:01:10 -07:00
|
|
|
if (!networkProperties)
|
2013-09-22 20:21:26 -07:00
|
|
|
return;
|
2013-09-22 20:01:10 -07:00
|
|
|
|
2013-09-22 20:01:10 -07:00
|
|
|
uint32_t gwAddress;
|
|
|
|
bool isWifi;
|
2014-02-25 17:39:08 -08:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = networkProperties->GetDhcpGateway(&gwAddress);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = networkProperties->GetIsWifi(&isWifi);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
2013-09-22 20:01:10 -07:00
|
|
|
|
2014-02-25 17:39:08 -08:00
|
|
|
if (!gwAddress || !isWifi)
|
2013-07-11 08:39:36 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
mWifiTickler->SetIPV4Address(gwAddress);
|
|
|
|
mWifiTickler->Tickle();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpsHandler implementation
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsHttpsHandler,
|
|
|
|
nsIHttpProtocolHandler,
|
|
|
|
nsIProxiedProtocolHandler,
|
|
|
|
nsIProtocolHandler,
|
|
|
|
nsISupportsWeakReference,
|
|
|
|
nsISpeculativeConnect)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpsHandler::Init()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIProtocolHandler> httpHandler(
|
|
|
|
do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http"));
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(httpHandler.get() != nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpsHandler::GetScheme(nsACString &aScheme)
|
|
|
|
{
|
|
|
|
aScheme.AssignLiteral("https");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHttpsHandler::GetDefaultPort(int32_t *aPort)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aPort = NS_HTTPS_DEFAULT_PORT;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHttpsHandler::GetProtocolFlags(uint32_t *aProtocolFlags)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-11-16 12:40:07 -08:00
|
|
|
*aProtocolFlags = NS_HTTP_PROTOCOL_FLAGS | URI_SAFE_TO_LOAD_IN_SECURE_CONTEXT;
|
2009-11-06 18:40:13 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpsHandler::NewURI(const nsACString &aSpec,
|
|
|
|
const char *aOriginCharset,
|
|
|
|
nsIURI *aBaseURI,
|
|
|
|
nsIURI **_retval)
|
|
|
|
{
|
2014-01-07 14:05:56 -08:00
|
|
|
return mozilla::net::NewURI(aSpec, aOriginCharset, aBaseURI, NS_HTTPS_DEFAULT_PORT, _retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpsHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval)
|
|
|
|
{
|
2013-05-16 06:30:41 -07:00
|
|
|
MOZ_ASSERT(gHttpHandler);
|
2009-11-06 18:40:13 -08:00
|
|
|
if (!gHttpHandler)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
return gHttpHandler->NewChannel(aURI, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHttpsHandler::AllowPort(int32_t aPort, const char *aScheme, bool *_retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-27 18:21:20 -07:00
|
|
|
// don't override anything.
|
2011-10-17 07:59:28 -07:00
|
|
|
*_retval = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-01-07 14:05:56 -08:00
|
|
|
|
|
|
|
} // namespace mozilla::net
|
|
|
|
} // namespace mozilla
|