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: */
|
2004-04-18 22:01:16 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
2001-05-11 21:04:09 +00:00
|
|
|
* The Original Code is Mozilla.
|
2004-04-18 22:01:16 +00:00
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2001-05-11 21:04:09 +00:00
|
|
|
* Darin Fisher <darin@netscape.com> (original author)
|
|
|
|
* Gagan Saksena <gagan@netscape.com>
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
* Christopher Blizzard <blizzard@mozilla.org>
|
|
|
|
* Adrian Havill <havill@redhat.com>
|
2001-05-17 00:17:34 +00:00
|
|
|
* Gervase Markham <gerv@gerv.net>
|
2001-07-17 20:22:19 +00:00
|
|
|
* Bradley Baetz <bbaetz@netscape.com>
|
2004-09-15 19:49:30 +00:00
|
|
|
* Benjamin Smedberg <bsmedberg@covad.net>
|
2005-10-18 19:32:01 +00:00
|
|
|
* Josh Aas <josh@mozilla.com>
|
2010-08-27 07:02:10 +00:00
|
|
|
* Dão Gottwald <dao@mozilla.com>
|
2004-04-18 22:01:16 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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-01-26 05:15:26 +00:00
|
|
|
#include "SpdySession.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
|
|
|
#include "mozilla/FunctionTimer.h"
|
|
|
|
|
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"
|
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,
|
|
|
|
PRInt32 aDefaultPort,
|
|
|
|
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>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsHttpHandler *gHttpHandler = nsnull;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
nsHttpHandler::nsHttpHandler()
|
2008-08-20 09:35:26 +00:00
|
|
|
: mConnMgr(nsnull)
|
|
|
|
, 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)
|
|
|
|
, mProxyCapabilities(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)
|
2001-05-11 21:04:09 +00:00
|
|
|
, mIdleTimeout(10)
|
2011-12-13 15:55:50 +00:00
|
|
|
, mSpdyTimeout(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)
|
2001-09-04 23:02:26 +00:00
|
|
|
, mMaxConnections(24)
|
2001-05-11 21:04:09 +00:00
|
|
|
, mMaxConnectionsPerServer(8)
|
2001-09-04 23:02:26 +00:00
|
|
|
, mMaxPersistentConnectionsPerServer(2)
|
2001-11-04 05:46:06 +00:00
|
|
|
, mMaxPersistentConnectionsPerProxy(4)
|
2002-04-19 22:25:23 +00:00
|
|
|
, mMaxPipelinedRequests(2)
|
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)
|
2010-11-24 13:58:42 +00:00
|
|
|
, mInPrivateBrowsingMode(PRIVATE_BROWSING_UNKNOWN)
|
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)
|
2011-12-13 15:55:50 +00:00
|
|
|
, mEnableSpdy(false)
|
|
|
|
, mCoalesceSpdy(true)
|
|
|
|
, mUseAlternateProtocol(false)
|
2012-01-26 05:15:26 +00:00
|
|
|
, mSpdySendingChunkSize(SpdySession::kSendingChunkSize)
|
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();
|
2001-06-11 21:20:29 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
gHttpHandler = nsnull;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::Init()
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
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);
|
|
|
|
prefBranch->AddObserver(INTL_ACCEPT_LANGUAGES, this, true);
|
|
|
|
prefBranch->AddObserver(NETWORK_ENABLEIDN, this, true);
|
|
|
|
prefBranch->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, true);
|
|
|
|
prefBranch->AddObserver(DONOTTRACK_HEADER_ENABLED, this, true);
|
2004-01-28 23:45:17 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
PrefsChanged(prefBranch, nsnull);
|
2001-09-27 21:26:59 +00:00
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2012-02-21 00:29:36 +00:00
|
|
|
mMisc.AssignLiteral("rv:" MOZILLA_VERSION);
|
2003-09-25 05:39:11 +00:00
|
|
|
|
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) {
|
|
|
|
appInfo->GetName(mAppName);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
mSessionStartTime = NowInSeconds();
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
rv = mAuthCache.Init();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = InitConnectionMgr();
|
2001-05-11 21:04:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-02-21 00:29:38 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
mProductSub.AssignLiteral(MOZ_APP_UA_VERSION);
|
|
|
|
#else
|
|
|
|
mProductSub.AssignLiteral(MOZ_UA_BUILDID);
|
|
|
|
#endif
|
|
|
|
if (mProductSub.IsEmpty() && appInfo)
|
|
|
|
appInfo->GetPlatformBuildID(mProductSub);
|
|
|
|
if (mProductSub.Length() > 8)
|
|
|
|
mProductSub.SetLength(8);
|
2007-07-02 18:20:24 +00:00
|
|
|
|
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)),
|
2001-10-19 20:52:59 +00:00
|
|
|
NS_HTTP_STARTUP_TOPIC);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
mObserverService = mozilla::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, NS_PRIVATE_BROWSING_SWITCH_TOPIC, true);
|
|
|
|
mObserverService->AddObserver(this, "net:prune-dead-connections", true);
|
2001-09-21 05:04:25 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::InitConnectionMgr()
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
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,
|
|
|
|
mMaxConnectionsPerServer,
|
|
|
|
mMaxConnectionsPerServer,
|
|
|
|
mMaxPersistentConnectionsPerServer,
|
|
|
|
mMaxPersistentConnectionsPerProxy,
|
|
|
|
mMaxRequestDelay,
|
|
|
|
mMaxPipelinedRequests);
|
|
|
|
return rv;
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
nsresult
|
|
|
|
nsHttpHandler::AddStandardRequestHeaders(nsHttpHeaderArray *request,
|
2001-08-14 01:03:27 +00:00
|
|
|
PRUint8 caps,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool useProxy)
|
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;
|
|
|
|
|
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
|
|
|
|
// user-agents. Otherwise, problems with proxy servers (especially
|
|
|
|
// transparent proxies) can result.
|
2001-08-14 01:03:27 +00:00
|
|
|
//
|
2001-07-17 20:22:19 +00:00
|
|
|
// However, we need to send something so that we can use keepalive
|
2001-08-14 01:03:27 +00:00
|
|
|
// with HTTP/1.0 servers/proxies. We use "Proxy-Connection:" when
|
2011-03-23 15:02:33 +00:00
|
|
|
// we're talking to an http proxy, and "Connection:" otherwise.
|
|
|
|
// We no longer send the Keep-Alive request header.
|
2001-07-17 20:22:19 +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-08-10 22:04:51 +00:00
|
|
|
} else if (useProxy) {
|
|
|
|
// Bug 92006
|
2002-11-22 07:40:16 +00:00
|
|
|
request->SetHeader(nsHttp::Connection, close);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
2001-07-17 20:22:19 +00:00
|
|
|
|
2011-01-05 19:53:21 +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;
|
|
|
|
}
|
|
|
|
|
2002-11-22 07:40:16 +00:00
|
|
|
const nsHttpAtom &header = useProxy ? nsHttp::Proxy_Connection
|
|
|
|
: nsHttp::Connection;
|
|
|
|
return request->SetHeader(header, *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;
|
|
|
|
|
2006-02-17 22:52:40 +00:00
|
|
|
return nsHttp::FindToken(mAcceptEncodings.get(), enc, HTTP_LWS ",") != nsnull;
|
2001-06-19 00:25:02 +00:00
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
nsresult
|
|
|
|
nsHttpHandler::GetCacheSession(nsCacheStoragePolicy storagePolicy,
|
|
|
|
nsICacheSession **result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Skip cache if disabled in preferences
|
2001-10-02 00:40:27 +00:00
|
|
|
if (!mUseCache)
|
2001-05-11 21:04:09 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2007-10-13 21:35:11 +00:00
|
|
|
// We want to get the pointer to the cache service each time we're called,
|
|
|
|
// because it's possible for some add-ons (such as Google Gears) to swap
|
|
|
|
// in new cache services on the fly, and we want to pick them up as
|
|
|
|
// appropriate.
|
|
|
|
nsCOMPtr<nsICacheService> serv = do_GetService(NS_CACHESERVICE_CONTRACTID,
|
|
|
|
&rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2007-10-13 21:35:11 +00:00
|
|
|
const char *sessionName = "HTTP";
|
|
|
|
switch (storagePolicy) {
|
|
|
|
case nsICache::STORE_IN_MEMORY:
|
|
|
|
sessionName = "HTTP-memory-only";
|
|
|
|
break;
|
|
|
|
case nsICache::STORE_OFFLINE:
|
|
|
|
sessionName = "HTTP-offline";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-03-14 01:52:07 +00:00
|
|
|
|
2007-10-13 21:35:11 +00:00
|
|
|
nsCOMPtr<nsICacheSession> cacheSession;
|
|
|
|
rv = serv->CreateSession(sessionName,
|
|
|
|
storagePolicy,
|
|
|
|
nsICache::STREAM_BASED,
|
|
|
|
getter_AddRefs(cacheSession));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2007-03-14 01:52:07 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = cacheSession->SetDoomEntriesIfExpired(false);
|
2007-10-13 21:35:11 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2007-10-13 21:35:11 +00:00
|
|
|
NS_ADDREF(*result = cacheSession);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-11-24 13:58:42 +00:00
|
|
|
nsHttpHandler::InPrivateBrowsingMode()
|
|
|
|
{
|
|
|
|
if (PRIVATE_BROWSING_UNKNOWN == mInPrivateBrowsingMode) {
|
|
|
|
// figure out if we're starting in private browsing mode
|
|
|
|
nsCOMPtr<nsIPrivateBrowsingService> pbs =
|
|
|
|
do_GetService(NS_PRIVATE_BROWSING_SERVICE_CONTRACTID);
|
|
|
|
if (!pbs)
|
|
|
|
return PRIVATE_BROWSING_OFF;
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool p = false;
|
2010-11-24 13:58:42 +00:00
|
|
|
pbs->GetPrivateBrowsingEnabled(&p);
|
|
|
|
mInPrivateBrowsingMode = p ? PRIVATE_BROWSING_ON : PRIVATE_BROWSING_OFF;
|
|
|
|
}
|
|
|
|
return PRIVATE_BROWSING_ON == mInPrivateBrowsingMode;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-06-06 00:10:09 +00:00
|
|
|
nsresult
|
|
|
|
nsHttpHandler::GetIOService(nsIIOService** result)
|
|
|
|
{
|
|
|
|
NS_ADDREF(*result = mIOService);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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)
|
2003-11-14 20:51:55 +00:00
|
|
|
mObserverService->NotifyObservers(chan, event, nsnull);
|
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,
|
2006-02-22 14:07:21 +00:00
|
|
|
PRUint32 flags)
|
|
|
|
{
|
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
|
|
|
|
nsHttpHandler::GenerateHostPort(const nsCString& host, PRInt32 port,
|
|
|
|
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() &&
|
|
|
|
!mLegacyAppVersion.IsEmpty() &&
|
2002-03-20 22:50:33 +00:00
|
|
|
!mPlatform.IsEmpty() &&
|
|
|
|
!mOscpu.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.
|
2010-08-27 07:02:10 +00:00
|
|
|
mUserAgent.SetCapacity(mLegacyAppName.Length() +
|
|
|
|
mLegacyAppVersion.Length() +
|
2010-08-05 07:09:42 +00:00
|
|
|
#ifndef UA_SPARE_PLATFORM
|
2002-03-20 22:50:33 +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
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += mPlatform;
|
2004-12-04 10:19:29 +00:00
|
|
|
mUserAgent.AppendLiteral("; ");
|
2010-08-05 07:09:42 +00:00
|
|
|
#endif
|
2012-02-01 04:04:23 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
if (!mCompatDevice.IsEmpty()) {
|
|
|
|
mUserAgent += mCompatDevice;
|
|
|
|
mUserAgent.AppendLiteral("; ");
|
|
|
|
}
|
|
|
|
#else
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += mOscpu;
|
2010-08-27 07:02:10 +00:00
|
|
|
mUserAgent.AppendLiteral("; ");
|
2012-02-01 04:04:23 +00:00
|
|
|
#endif
|
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
|
|
|
|
2010-08-27 07:03:10 +00:00
|
|
|
// "Firefox/x.y.z" compatibility token
|
|
|
|
if (!mCompatFirefox.IsEmpty()) {
|
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
|
|
|
}
|
2005-04-07 18:11:59 +00:00
|
|
|
|
2010-08-27 07:03:10 +00:00
|
|
|
// App portion
|
2010-08-27 07:02:10 +00:00
|
|
|
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
|
2012-02-08 21:04:21 +00:00
|
|
|
typedef BOOL (WINAPI *IsWow64ProcessP) (HANDLE, PBOOL);
|
|
|
|
|
2010-05-02 08:59:00 +00:00
|
|
|
#define WNT_BASE "Windows NT %ld.%ld"
|
|
|
|
#define W64_PREFIX "; Win64"
|
|
|
|
#endif
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
void
|
|
|
|
nsHttpHandler::InitUserAgentComponents()
|
|
|
|
{
|
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"
|
2009-08-20 15:30:25 +00:00
|
|
|
#else
|
|
|
|
"?"
|
2001-05-11 21:04:09 +00:00
|
|
|
#endif
|
2004-12-04 10:19:29 +00:00
|
|
|
);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2012-02-01 04:04:23 +00:00
|
|
|
#if defined(ANDROID)
|
|
|
|
nsCOMPtr<nsIPropertyBag2> infoService = do_GetService("@mozilla.org/system-info;1");
|
|
|
|
NS_ASSERTION(infoService, "Could not find a system info service");
|
|
|
|
|
2012-02-09 22:02:46 +00:00
|
|
|
bool isTablet = false;
|
2012-02-01 04:04:23 +00:00
|
|
|
infoService->GetPropertyAsBool(NS_LITERAL_STRING("tablet"), &isTablet);
|
|
|
|
if (isTablet)
|
|
|
|
mCompatDevice.AssignLiteral("Tablet");
|
|
|
|
else
|
|
|
|
mCompatDevice.AssignLiteral("Mobile");
|
|
|
|
#endif
|
|
|
|
|
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-08 21:04:21 +00:00
|
|
|
IsWow64ProcessP fnIsWow64Process = (IsWow64ProcessP)
|
|
|
|
GetProcAddress(GetModuleHandleW(L"kernel32"), "IsWow64Process");
|
|
|
|
if (fnIsWow64Process &&
|
|
|
|
!fnIsWow64Process(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;
|
|
|
|
|
|
|
|
int ret = uname(&name);
|
|
|
|
if (ret >= 0) {
|
2004-12-04 10:19:29 +00:00
|
|
|
nsCAutoString 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 &&
|
|
|
|
sizeof(void *) == sizeof(PRInt32)) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mUserAgentIsDirty = true;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2011-10-25 15:36:49 +00:00
|
|
|
PRUint32
|
|
|
|
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.
|
|
|
|
|
|
|
|
PRUint32 maxCount = nsSocketTransportService::gMaxCount;
|
|
|
|
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;
|
2001-08-14 01:03:27 +00:00
|
|
|
PRInt32 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
|
|
|
|
|
|
|
#define PREF_CHANGED(p) ((pref == nsnull) || !PL_strcmp(pref, p))
|
2005-04-07 18:11:59 +00:00
|
|
|
#define MULTI_PREF_CHANGED(p) \
|
|
|
|
((pref == nsnull) || !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);
|
|
|
|
if (NS_SUCCEEDED(rv) && cVar) {
|
2010-08-28 13:32:07 +00:00
|
|
|
mCompatFirefox.AssignLiteral("Firefox/" MOZ_UA_FIREFOX_VERSION);
|
2010-08-27 07:02:10 +00:00
|
|
|
} else {
|
|
|
|
mCompatFirefox.Truncate();
|
|
|
|
}
|
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))
|
2011-10-28 18:33:28 +00:00
|
|
|
mIdleTimeout = (PRUint16) 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))
|
2011-10-28 18:33:28 +00:00
|
|
|
mMaxRequestAttempts = (PRUint16) 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)) {
|
2011-10-28 18:33:28 +00:00
|
|
|
mMaxRequestDelay = (PRUint16) 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
|
|
|
|
2011-10-28 18:33:28 +00:00
|
|
|
mMaxConnections = (PRUint16) clamped((PRUint32)val,
|
|
|
|
(PRUint32)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-connections-per-server"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetIntPref(HTTP_PREF("max-connections-per-server"), &val);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2011-10-28 18:33:28 +00:00
|
|
|
mMaxConnectionsPerServer = (PRUint8) clamped(val, 1, 0xff);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (mConnMgr) {
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_CONNECTIONS_PER_HOST,
|
|
|
|
mMaxConnectionsPerServer);
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_CONNECTIONS_PER_PROXY,
|
|
|
|
mMaxConnectionsPerServer);
|
|
|
|
}
|
|
|
|
}
|
2001-08-14 01:03:27 +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)) {
|
2011-10-28 18:33:28 +00:00
|
|
|
mMaxPersistentConnectionsPerServer = (PRUint8) 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)) {
|
2011-10-28 18:33:28 +00:00
|
|
|
mMaxPersistentConnectionsPerProxy = (PRUint8) 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))
|
2011-10-28 18:33:28 +00:00
|
|
|
mReferrerLevel = (PRUint8) 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))
|
2011-10-28 18:33:28 +00:00
|
|
|
mRedirectionLimit = (PRUint8) 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))
|
2011-10-28 18:33:28 +00:00
|
|
|
mIdleSynTimeout = (PRUint16) 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("keep-alive"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("keep-alive"), &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_KEEPALIVE;
|
2001-05-11 21:04:09 +00:00
|
|
|
else
|
2001-08-14 01:03:27 +00:00
|
|
|
mCapabilities &= ~NS_HTTP_ALLOW_KEEPALIVE;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
if (PREF_CHANGED(HTTP_PREF("proxy.keep-alive"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
rv = prefs->GetBoolPref(HTTP_PREF("proxy.keep-alive"), &cVar);
|
2001-05-11 21:04:09 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (cVar)
|
2001-08-14 01:03:27 +00:00
|
|
|
mProxyCapabilities |= NS_HTTP_ALLOW_KEEPALIVE;
|
2001-05-11 21:04:09 +00:00
|
|
|
else
|
2001-08-14 01:03:27 +00:00
|
|
|
mProxyCapabilities &= ~NS_HTTP_ALLOW_KEEPALIVE;
|
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;
|
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)) {
|
2011-10-28 18:33:28 +00:00
|
|
|
mMaxPipelinedRequests = clamped(val, 1, NS_HTTP_MAX_PIPELINED_REQUESTS);
|
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
|
|
|
|
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);
|
2001-05-11 21:04:09 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (cVar)
|
2001-08-14 01:03:27 +00:00
|
|
|
mProxyCapabilities |= NS_HTTP_ALLOW_PIPELINING;
|
2001-05-11 21:04:09 +00:00
|
|
|
else
|
2001-08-14 01:03:27 +00:00
|
|
|
mProxyCapabilities &= ~NS_HTTP_ALLOW_PIPELINING;
|
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))
|
2011-10-28 18:33:28 +00:00
|
|
|
mQoSBits = (PRUint8) 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);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-15 22:12:52 +00:00
|
|
|
// enable Persistent caching for HTTPS - bug#205921
|
|
|
|
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))
|
2011-10-28 18:33:28 +00:00
|
|
|
mPhishyUserPassLength = (PRUint8) 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
|
|
|
mSpdyTimeout = (PRUint16) clamped(val, 1, 0xffff);
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
mSpdySendingChunkSize = (PRUint32) clamped(val, 1, 0x7fffffff);
|
|
|
|
}
|
|
|
|
|
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());
|
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)
|
|
|
|
mIDNConverter = nsnull;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
PRUint32 n, size, wrote;
|
|
|
|
double q, dec;
|
|
|
|
char *p, *p2, *token, *q_Accept, *o_Accept;
|
|
|
|
const char *comma;
|
|
|
|
PRInt32 available;
|
|
|
|
|
|
|
|
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;
|
|
|
|
n = 0;
|
|
|
|
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') {
|
2002-11-20 20:51:12 +00:00
|
|
|
comma = n++ != 0 ? "," : ""; // delimiter if not first item
|
2003-03-26 01:21:26 +00:00
|
|
|
PRUint32 u = QVAL_TO_UINT(q);
|
|
|
|
if (u < 10)
|
|
|
|
wrote = PR_snprintf(p2, available, "%s%s;q=0.%u", comma, token, u);
|
2001-05-11 21:04:09 +00:00
|
|
|
else
|
|
|
|
wrote = PR_snprintf(p2, available, "%s%s", comma, token);
|
|
|
|
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
|
|
|
|
nsHttpHandler::SetAcceptLanguages(const char *aAcceptLanguages)
|
|
|
|
{
|
2004-12-04 10:19:29 +00:00
|
|
|
nsCAutoString 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
|
|
|
|
nsHttpHandler::SetAccept(const char *aAccept)
|
|
|
|
{
|
|
|
|
mAccept = aAccept;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
nsresult
|
|
|
|
nsHttpHandler::SetAcceptEncodings(const char *aAcceptEncodings)
|
|
|
|
{
|
|
|
|
mAcceptEncodings = aAcceptEncodings;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpHandler::nsISupports
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2001-09-13 02:21:05 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS5(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,
|
|
|
|
nsISupportsWeakReference)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// 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
|
2002-08-13 20:33:45 +00:00
|
|
|
nsHttpHandler::GetDefaultPort(PRInt32 *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
|
2001-09-13 02:21:05 +00:00
|
|
|
nsHttpHandler::GetProtocolFlags(PRUint32 *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
|
|
|
{
|
|
|
|
LOG(("nsHttpHandler::NewURI\n"));
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-18 22:36:39 +00:00
|
|
|
return NewProxiedChannel(uri, nsnull, result);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2001-06-06 00:10:09 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHttpHandler::AllowPort(PRInt32 port, const char *scheme, bool *_retval)
|
2001-06-06 00:10:09 +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,
|
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));
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// select proxy caps if using a non-transparent proxy. SSL tunneling
|
|
|
|
// should not use proxy settings.
|
|
|
|
PRInt8 caps;
|
|
|
|
if (proxyInfo && !nsCRT::strcmp(proxyInfo->Type(), "http") && !https)
|
|
|
|
caps = mProxyCapabilities;
|
|
|
|
else
|
|
|
|
caps = mCapabilities;
|
|
|
|
|
|
|
|
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
|
|
|
|
2002-04-18 22:36:39 +00:00
|
|
|
rv = httpChannel->Init(uri, caps, proxyInfo);
|
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::GetProduct(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mProduct;
|
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetProductSub(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mProductSub;
|
|
|
|
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
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// clear cache of all authentication credentials.
|
2003-01-18 02:15:14 +00:00
|
|
|
mAuthCache.ClearAll();
|
|
|
|
|
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();
|
|
|
|
}
|
2010-06-03 21:03:17 +00:00
|
|
|
else if (strcmp(topic, NS_PRIVATE_BROWSING_SWITCH_TOPIC) == 0) {
|
|
|
|
if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_ENTER).Equals(data))
|
2010-11-24 13:58:42 +00:00
|
|
|
mInPrivateBrowsingMode = PRIVATE_BROWSING_ON;
|
2010-06-03 21:03:17 +00:00
|
|
|
else if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_LEAVE).Equals(data))
|
2010-11-24 13:58:42 +00:00
|
|
|
mInPrivateBrowsingMode = PRIVATE_BROWSING_OFF;
|
2011-07-25 20:25:01 +00:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->ClosePersistentConnections();
|
2010-06-03 21:03:17 +00:00
|
|
|
}
|
2010-10-15 00:28:45 +00:00
|
|
|
else if (strcmp(topic, "net:prune-dead-connections") == 0) {
|
|
|
|
if (mConnMgr) {
|
|
|
|
mConnMgr->PruneDeadConnections();
|
|
|
|
}
|
|
|
|
}
|
2010-06-03 21:03:17 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-08-13 20:33:45 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpsHandler implementation
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS4(nsHttpsHandler,
|
|
|
|
nsIHttpProtocolHandler,
|
|
|
|
nsIProxiedProtocolHandler,
|
|
|
|
nsIProtocolHandler,
|
|
|
|
nsISupportsWeakReference)
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpsHandler::Init()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIProtocolHandler> httpHandler(
|
|
|
|
do_GetService(NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "http"));
|
|
|
|
NS_ASSERTION(httpHandler.get() != nsnull, "no http handler?");
|
|
|
|
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
|
|
|
|
nsHttpsHandler::GetDefaultPort(PRInt32 *aPort)
|
|
|
|
{
|
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
|
|
|
|
nsHttpsHandler::GetProtocolFlags(PRUint32 *aProtocolFlags)
|
|
|
|
{
|
2009-11-07 02:40:13 +00:00
|
|
|
*aProtocolFlags = NS_HTTP_PROTOCOL_FLAGS;
|
|
|
|
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
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHttpsHandler::AllowPort(PRInt32 aPort, const char *aScheme, bool *_retval)
|
2002-08-13 20:33:45 +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;
|
|
|
|
}
|