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>
|
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"
|
2005-02-25 20:46:35 +00:00
|
|
|
#include "nsIPrefBranch2.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"
|
2001-06-11 21:20:29 +00:00
|
|
|
#include "nsAutoLock.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
#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"
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
#if defined(XP_UNIX) || defined(XP_BEOS)
|
|
|
|
#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
|
|
|
|
|
2001-08-30 02:58:03 +00:00
|
|
|
#if defined(XP_MAC)
|
|
|
|
#include <Gestalt.h>
|
|
|
|
#endif
|
|
|
|
|
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);
|
|
|
|
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_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."
|
|
|
|
#define UA_APPNAME "Mozilla"
|
|
|
|
#define UA_APPVERSION "5.0"
|
2001-05-11 21:04:09 +00:00
|
|
|
#define UA_APPSECURITY_FALLBACK "N"
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
#define HTTP_PREF_PREFIX "network.http."
|
|
|
|
#define INTL_ACCEPT_LANGUAGES "intl.accept_languages"
|
|
|
|
#define INTL_ACCEPT_CHARSET "intl.charset.default"
|
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."
|
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
|
|
|
|
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()
|
2003-01-18 02:15:14 +00:00
|
|
|
: mConnMgr(nsnull)
|
2001-05-11 21:04:09 +00:00
|
|
|
, mHttpVersion(NS_HTTP_VERSION_1_1)
|
2002-04-18 22:36:39 +00:00
|
|
|
, mProxyHttpVersion(NS_HTTP_VERSION_1_1)
|
2001-08-14 01:03:27 +00:00
|
|
|
, mCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
|
|
|
|
, mProxyCapabilities(NS_HTTP_ALLOW_KEEPALIVE)
|
2002-04-18 22:36:39 +00:00
|
|
|
, mReferrerLevel(0xff) // by default we always send a referrer
|
2001-05-11 21:04:09 +00:00
|
|
|
, mIdleTimeout(10)
|
2001-08-14 01:03:27 +00:00
|
|
|
, mMaxRequestAttempts(10)
|
2001-09-04 23:02:26 +00:00
|
|
|
, mMaxRequestDelay(10)
|
|
|
|
, 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)
|
2001-10-22 23:24:26 +00:00
|
|
|
, mLastUniqueID(NowInSeconds())
|
|
|
|
, mSessionStartTime(0)
|
2001-05-11 21:04:09 +00:00
|
|
|
, mUserAgentIsDirty(PR_TRUE)
|
2001-10-02 00:40:27 +00:00
|
|
|
, mUseCache(PR_TRUE)
|
2002-09-13 22:21:57 +00:00
|
|
|
, mSendSecureXSiteReferrer(PR_TRUE)
|
2003-09-15 22:12:52 +00:00
|
|
|
, mEnablePersistentHttpsCaching(PR_FALSE)
|
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()
|
|
|
|
{
|
2001-12-07 01:40:18 +00:00
|
|
|
// We do not deal with the timer cancellation in the destructor since
|
|
|
|
// it is taken care of in xpcom shutdown event in the Observe method.
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
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();
|
|
|
|
NS_RELEASE(mConnMgr);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
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;
|
|
|
|
|
2001-06-06 00:10:09 +00:00
|
|
|
mIOService = do_GetService(kIOServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("unable to continue without io service");
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
InitUserAgentComponents();
|
|
|
|
|
|
|
|
// monitor some preference changes
|
2005-02-25 20:46:35 +00:00
|
|
|
nsCOMPtr<nsIPrefBranch2> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
2001-10-02 00:40:27 +00:00
|
|
|
if (prefBranch) {
|
2004-01-28 23:45:17 +00:00
|
|
|
prefBranch->AddObserver(HTTP_PREF_PREFIX, this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver(UA_PREF_PREFIX, this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver(INTL_ACCEPT_LANGUAGES, this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver(INTL_ACCEPT_CHARSET, this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver(NETWORK_ENABLEIDN, this, PR_TRUE);
|
|
|
|
prefBranch->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, PR_TRUE);
|
|
|
|
|
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
|
|
|
|
2004-06-17 00:13:25 +00:00
|
|
|
mMisc.AssignLiteral("rv:" MOZILLA_VERSION);
|
2003-09-25 05:39:11 +00:00
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
#if DEBUG
|
|
|
|
// dump user agent prefs
|
|
|
|
LOG(("> app-name = %s\n", mAppName.get()));
|
|
|
|
LOG(("> app-version = %s\n", mAppVersion.get()));
|
|
|
|
LOG(("> platform = %s\n", mPlatform.get()));
|
|
|
|
LOG(("> oscpu = %s\n", mOscpu.get()));
|
|
|
|
LOG(("> security = %s\n", mSecurity.get()));
|
|
|
|
LOG(("> language = %s\n", mLanguage.get()));
|
|
|
|
LOG(("> misc = %s\n", mMisc.get()));
|
|
|
|
LOG(("> vendor = %s\n", mVendor.get()));
|
|
|
|
LOG(("> vendor-sub = %s\n", mVendorSub.get()));
|
|
|
|
LOG(("> vendor-comment = %s\n", mVendorComment.get()));
|
2005-04-07 18:11:59 +00:00
|
|
|
LOG(("> extra = %s\n", mExtraUA.get()));
|
2001-09-27 21:26:59 +00:00
|
|
|
LOG(("> product = %s\n", mProduct.get()));
|
|
|
|
LOG(("> product-sub = %s\n", mProductSub.get()));
|
|
|
|
LOG(("> product-comment = %s\n", mProductComment.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;
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
NS_STATIC_CAST(nsISupports*,NS_STATIC_CAST(void*,this)),
|
2001-10-19 20:52:59 +00:00
|
|
|
NS_HTTP_STARTUP_TOPIC);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2003-09-15 21:44:43 +00:00
|
|
|
mObserverService = do_GetService("@mozilla.org/observer-service;1");
|
|
|
|
if (mObserverService) {
|
|
|
|
mObserverService->AddObserver(this, "profile-change-net-teardown", PR_TRUE);
|
|
|
|
mObserverService->AddObserver(this, "profile-change-net-restore", PR_TRUE);
|
|
|
|
mObserverService->AddObserver(this, "session-logout", PR_TRUE);
|
|
|
|
mObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
|
2001-09-21 05:04:25 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
StartPruneDeadConnectionsTimer();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::InitConnectionMgr()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpHandler::StartPruneDeadConnectionsTimer()
|
|
|
|
{
|
|
|
|
LOG(("nsHttpHandler::StartPruneDeadConnectionsTimer\n"));
|
2001-12-07 01:40:18 +00:00
|
|
|
|
|
|
|
mTimer = do_CreateInstance("@mozilla.org/timer;1");
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_ASSERTION(mTimer, "no timer");
|
2001-12-07 01:40:18 +00:00
|
|
|
// failure to create a timer is not a fatal error, but idle connections
|
2003-02-09 20:13:46 +00:00
|
|
|
// will not be cleaned up until we try to use them.
|
2001-12-07 01:40:18 +00:00
|
|
|
if (mTimer)
|
2003-01-18 02:15:14 +00:00
|
|
|
mTimer->Init(this, 15*1000, // every 15 seconds
|
|
|
|
nsITimer::TYPE_REPEATING_SLACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpHandler::StopPruneDeadConnectionsTimer()
|
|
|
|
{
|
|
|
|
LOG(("nsHttpHandler::StopPruneDeadConnectionsTimer\n"));
|
|
|
|
|
|
|
|
if (mTimer) {
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = 0;
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::AddStandardRequestHeaders(nsHttpHeaderArray *request,
|
2001-08-14 01:03:27 +00:00
|
|
|
PRUint8 caps,
|
2001-07-17 20:22:19 +00:00
|
|
|
PRBool useProxy)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
LOG(("nsHttpHandler::AddStandardRequestHeaders\n"));
|
|
|
|
|
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
|
|
|
// Add the "Accept-Charset" header
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = request->SetHeader(nsHttp::Accept_Charset, mAcceptCharsets);
|
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
|
|
|
|
// we're talking to an http proxy, and "Connection:" otherwise
|
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-03-20 22:50:33 +00:00
|
|
|
rv = request->SetHeader(nsHttp::Keep_Alive, nsPrintfCString("%u", mIdleTimeout));
|
2001-05-11 21:04:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2001-06-19 00:25:02 +00:00
|
|
|
PRBool
|
|
|
|
nsHttpHandler::IsAcceptableEncoding(const char *enc)
|
|
|
|
{
|
|
|
|
if (!enc)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2001-10-24 23:47:43 +00:00
|
|
|
return PL_strcasestr(mAcceptEncodings.get(), enc) != 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;
|
|
|
|
|
|
|
|
if (!mCacheSession_ANY) {
|
|
|
|
nsCOMPtr<nsICacheService> serv = do_GetService(kCacheServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = serv->CreateSession("HTTP",
|
|
|
|
nsICache::STORE_ANYWHERE,
|
|
|
|
nsICache::STREAM_BASED,
|
|
|
|
getter_AddRefs(mCacheSession_ANY));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mCacheSession_ANY->SetDoomEntriesIfExpired(PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = serv->CreateSession("HTTP-memory-only",
|
|
|
|
nsICache::STORE_IN_MEMORY,
|
|
|
|
nsICache::STREAM_BASED,
|
|
|
|
getter_AddRefs(mCacheSession_MEM));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mCacheSession_MEM->SetDoomEntriesIfExpired(PR_FALSE);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (storagePolicy == nsICache::STORE_IN_MEMORY)
|
|
|
|
NS_ADDREF(*result = mCacheSession_MEM);
|
|
|
|
else
|
|
|
|
NS_ADDREF(*result = mCacheSession_ANY);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-04-20 00:56:29 +00:00
|
|
|
nsHttpHandler::GetCurrentEventQ(nsIEventQueue **result)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
|
|
|
if (!mEventQueueService) {
|
|
|
|
nsresult rv;
|
|
|
|
mEventQueueService = do_GetService(kEventQueueServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2004-04-20 00:56:29 +00:00
|
|
|
return mEventQueueService->ResolveEventQueue(NS_CURRENT_EVENTQ, result);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::GetStreamConverterService(nsIStreamConverterService **result)
|
|
|
|
{
|
|
|
|
if (!mStreamConvSvc) {
|
|
|
|
nsresult rv;
|
|
|
|
mStreamConvSvc = do_GetService(kStreamConverterServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
*result = mStreamConvSvc;
|
|
|
|
NS_ADDREF(*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-08-05 01:44:27 +00:00
|
|
|
nsICookieService *
|
|
|
|
nsHttpHandler::GetCookieService()
|
|
|
|
{
|
|
|
|
if (!mCookieService)
|
|
|
|
mCookieService = do_GetService(kCookieServiceCID);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// 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();
|
|
|
|
mUserAgentIsDirty = PR_FALSE;
|
|
|
|
}
|
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"));
|
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
NS_ASSERTION(!mAppName.IsEmpty() &&
|
|
|
|
!mAppVersion.IsEmpty() &&
|
|
|
|
!mPlatform.IsEmpty() &&
|
|
|
|
!mSecurity.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.
|
|
|
|
mUserAgent.SetCapacity(mAppName.Length() +
|
|
|
|
mAppVersion.Length() +
|
|
|
|
mPlatform.Length() +
|
|
|
|
mSecurity.Length() +
|
|
|
|
mOscpu.Length() +
|
|
|
|
mLanguage.Length() +
|
|
|
|
mMisc.Length() +
|
|
|
|
mProduct.Length() +
|
|
|
|
mProductSub.Length() +
|
|
|
|
mProductComment.Length() +
|
|
|
|
mVendor.Length() +
|
|
|
|
mVendorSub.Length() +
|
|
|
|
mVendorComment.Length() +
|
2005-04-07 18:11:59 +00:00
|
|
|
mExtraUA.Length() +
|
2002-03-20 22:50:33 +00:00
|
|
|
22);
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// Application portion
|
|
|
|
mUserAgent.Assign(mAppName);
|
|
|
|
mUserAgent += '/';
|
|
|
|
mUserAgent += mAppVersion;
|
|
|
|
mUserAgent += ' ';
|
|
|
|
|
|
|
|
// Application comment
|
|
|
|
mUserAgent += '(';
|
|
|
|
mUserAgent += mPlatform;
|
2004-12-04 10:19:29 +00:00
|
|
|
mUserAgent.AppendLiteral("; ");
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += mSecurity;
|
2004-12-04 10:19:29 +00:00
|
|
|
mUserAgent.AppendLiteral("; ");
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += mOscpu;
|
2002-03-20 22:50:33 +00:00
|
|
|
if (!mLanguage.IsEmpty()) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mUserAgent.AppendLiteral("; ");
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += mLanguage;
|
|
|
|
}
|
2002-03-20 22:50:33 +00:00
|
|
|
if (!mMisc.IsEmpty()) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mUserAgent.AppendLiteral("; ");
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += mMisc;
|
|
|
|
}
|
|
|
|
mUserAgent += ')';
|
|
|
|
|
|
|
|
// Product portion
|
2002-03-20 22:50:33 +00:00
|
|
|
if (!mProduct.IsEmpty()) {
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += ' ';
|
|
|
|
mUserAgent += mProduct;
|
2002-03-20 22:50:33 +00:00
|
|
|
if (!mProductSub.IsEmpty()) {
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += '/';
|
|
|
|
mUserAgent += mProductSub;
|
|
|
|
}
|
2002-03-20 22:50:33 +00:00
|
|
|
if (!mProductComment.IsEmpty()) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mUserAgent.AppendLiteral(" (");
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += mProductComment;
|
|
|
|
mUserAgent += ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Vendor portion
|
2002-03-20 22:50:33 +00:00
|
|
|
if (!mVendor.IsEmpty()) {
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += ' ';
|
|
|
|
mUserAgent += mVendor;
|
2002-03-20 22:50:33 +00:00
|
|
|
if (!mVendorSub.IsEmpty()) {
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += '/';
|
|
|
|
mUserAgent += mVendorSub;
|
|
|
|
}
|
2002-03-20 22:50:33 +00:00
|
|
|
if (!mVendorComment.IsEmpty()) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mUserAgent.AppendLiteral(" (");
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgent += mVendorComment;
|
|
|
|
mUserAgent += ')';
|
|
|
|
}
|
|
|
|
}
|
2005-04-07 18:11:59 +00:00
|
|
|
|
|
|
|
if (!mExtraUA.IsEmpty())
|
|
|
|
mUserAgent += mExtraUA;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpHandler::InitUserAgentComponents()
|
|
|
|
{
|
|
|
|
|
2001-06-17 05:23:38 +00:00
|
|
|
// Gather platform.
|
2004-12-04 10:19:29 +00:00
|
|
|
mPlatform.AssignLiteral(
|
2001-12-09 09:14:34 +00:00
|
|
|
#if defined(MOZ_WIDGET_PHOTON)
|
|
|
|
"Photon"
|
|
|
|
#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"
|
2001-10-27 07:38:18 +00:00
|
|
|
#elif defined(XP_MAC) || defined(XP_MACOSX)
|
2001-06-17 05:23:38 +00:00
|
|
|
"Macintosh"
|
2001-05-11 21:04:09 +00:00
|
|
|
#elif defined(XP_BEOS)
|
2001-06-17 05:23:38 +00:00
|
|
|
"BeOS"
|
2003-03-04 03:58:43 +00:00
|
|
|
#elif !defined(MOZ_X11)
|
2001-12-09 09:14:34 +00:00
|
|
|
"?"
|
|
|
|
#else
|
|
|
|
"X11"
|
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
|
|
|
|
|
|
|
// 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
|
|
|
|
2003-04-02 22:45:08 +00:00
|
|
|
#elif defined(XP_WIN)
|
2003-03-07 06:07:56 +00:00
|
|
|
OSVERSIONINFO info = { sizeof(OSVERSIONINFO) };
|
2001-05-11 21:04:09 +00:00
|
|
|
if (GetVersionEx(&info)) {
|
|
|
|
if (info.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
|
|
|
if (info.dwMajorVersion == 3)
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("WinNT3.51");
|
2001-05-11 21:04:09 +00:00
|
|
|
else if (info.dwMajorVersion == 4)
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("WinNT4.0");
|
2001-06-19 22:40:34 +00:00
|
|
|
else {
|
2001-05-11 21:04:09 +00:00
|
|
|
char *buf = PR_smprintf("Windows NT %ld.%ld",
|
|
|
|
info.dwMajorVersion,
|
|
|
|
info.dwMinorVersion);
|
|
|
|
if (buf) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu = buf;
|
2001-05-11 21:04:09 +00:00
|
|
|
PR_smprintf_free(buf);
|
|
|
|
}
|
|
|
|
}
|
2001-06-19 22:40:34 +00:00
|
|
|
} else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
|
|
|
|
info.dwMajorVersion == 4) {
|
2001-05-11 21:04:09 +00:00
|
|
|
if (info.dwMinorVersion == 90)
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("Win 9x 4.90"); // Windows Me
|
2001-05-11 21:04:09 +00:00
|
|
|
else if (info.dwMinorVersion > 0)
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("Win98");
|
2001-05-11 21:04:09 +00:00
|
|
|
else
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("Win95");
|
2001-06-19 22:40:34 +00:00
|
|
|
} else {
|
|
|
|
char *buf = PR_smprintf("Windows %ld.%ld",
|
|
|
|
info.dwMajorVersion,
|
|
|
|
info.dwMinorVersion);
|
|
|
|
if (buf) {
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu = buf;
|
2001-06-19 22:40:34 +00:00
|
|
|
PR_smprintf_free(buf);
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
2002-04-24 00:55:53 +00:00
|
|
|
#elif defined (XP_MACOSX)
|
2004-12-04 10:19:29 +00:00
|
|
|
mOscpu.AssignLiteral("PPC Mac OS X Mach-O");
|
2002-04-24 00:55:53 +00:00
|
|
|
#elif defined (XP_MAC)
|
|
|
|
long version;
|
|
|
|
if (::Gestalt(gestaltSystemVersion, &version) == noErr && version >= 0x00001000)
|
2005-03-03 01:27:36 +00:00
|
|
|
mOscpu.AssignLiteral("PPC Mac OS X");
|
2002-04-24 00:55:53 +00:00
|
|
|
else
|
2005-03-03 01:27:36 +00:00
|
|
|
mOscpu.AssignLiteral("PPC");
|
2001-05-11 21:04:09 +00:00
|
|
|
#elif defined (XP_UNIX) || defined (XP_BEOS)
|
|
|
|
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..
|
|
|
|
|
|
|
|
buf += " i686 (x86_64)";
|
|
|
|
} else {
|
|
|
|
buf += ' ';
|
|
|
|
|
|
|
|
buf += (char*)name.machine;
|
|
|
|
}
|
|
|
|
|
2001-11-28 05:22:57 +00:00
|
|
|
mOscpu.Assign(buf);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-04-07 18:11:59 +00:00
|
|
|
static int StringCompare(const void* s1, const void* s2, void*)
|
|
|
|
{
|
|
|
|
return nsCRT::strcmp(*NS_STATIC_CAST(const char *const *, s1),
|
|
|
|
*NS_STATIC_CAST(const char *const *, s2));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
//
|
|
|
|
|
2003-10-10 08:20:46 +00:00
|
|
|
// Gather application values.
|
|
|
|
if (PREF_CHANGED(UA_PREF("appName"))) {
|
|
|
|
prefs->GetCharPref(UA_PREF("appName"),
|
|
|
|
getter_Copies(mAppName));
|
2003-10-10 18:05:18 +00:00
|
|
|
if (mAppName.IsEmpty())
|
2004-12-04 10:19:29 +00:00
|
|
|
mAppName.AssignLiteral(UA_APPNAME);
|
2003-10-10 08:20:46 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (PREF_CHANGED(UA_PREF("appVersion"))) {
|
|
|
|
prefs->GetCharPref(UA_PREF("appVersion"),
|
|
|
|
getter_Copies(mAppVersion));
|
2003-10-10 18:05:18 +00:00
|
|
|
if (mAppVersion.IsEmpty())
|
2004-12-04 10:19:29 +00:00
|
|
|
mAppVersion.AssignLiteral(UA_APPVERSION);
|
2003-10-10 08:20:46 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
// Gather vendor values.
|
|
|
|
if (PREF_CHANGED(UA_PREF("vendor"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetCharPref(UA_PREF("vendor"),
|
2001-09-27 21:26:59 +00:00
|
|
|
getter_Copies(mVendor));
|
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (PREF_CHANGED(UA_PREF("vendorSub"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetCharPref(UA_PREF("vendorSub"),
|
2001-09-27 21:26:59 +00:00
|
|
|
getter_Copies(mVendorSub));
|
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (PREF_CHANGED(UA_PREF("vendorComment"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetCharPref(UA_PREF("vendorComment"),
|
2001-09-27 21:26:59 +00:00
|
|
|
getter_Copies(mVendorComment));
|
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2005-04-07 18:11:59 +00:00
|
|
|
if (MULTI_PREF_CHANGED(UA_PREF("extra."))) {
|
|
|
|
mExtraUA.Truncate();
|
|
|
|
|
|
|
|
// Unfortunately, we can't do this using the pref branch.
|
|
|
|
nsCOMPtr<nsIPrefService> service =
|
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIPrefBranch> branch;
|
|
|
|
service->GetBranch(UA_PREF("extra."), getter_AddRefs(branch));
|
|
|
|
if (branch) {
|
|
|
|
PRUint32 extraCount;
|
|
|
|
char **extraItems;
|
|
|
|
rv = branch->GetChildList("", &extraCount, &extraItems);
|
|
|
|
if (NS_SUCCEEDED(rv) && extraItems) {
|
|
|
|
NS_QuickSort(extraItems, extraCount, sizeof(extraItems[0]),
|
|
|
|
StringCompare, nsnull);
|
|
|
|
for (char **item = extraItems,
|
|
|
|
**item_end = extraItems + extraCount;
|
|
|
|
item < item_end; ++item) {
|
|
|
|
nsXPIDLCString valStr;
|
|
|
|
branch->GetCharPref(*item, getter_Copies(valStr));
|
|
|
|
if (!valStr.IsEmpty())
|
|
|
|
mExtraUA += NS_LITERAL_CSTRING(" ") + valStr;
|
|
|
|
}
|
|
|
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(extraCount, extraItems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
// Gather product values.
|
|
|
|
if (PREF_CHANGED(UA_PREF("product"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetCharPref(UA_PREF_PREFIX "product",
|
2001-09-27 21:26:59 +00:00
|
|
|
getter_Copies(mProduct));
|
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (PREF_CHANGED(UA_PREF("productSub"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetCharPref(UA_PREF("productSub"),
|
2001-09-27 21:26:59 +00:00
|
|
|
getter_Copies(mProductSub));
|
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (PREF_CHANGED(UA_PREF("productComment"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetCharPref(UA_PREF("productComment"),
|
2001-09-27 21:26:59 +00:00
|
|
|
getter_Copies(mProductComment));
|
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get Security level supported
|
|
|
|
if (PREF_CHANGED(UA_PREF("security"))) {
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetCharPref(UA_PREF("security"), getter_Copies(mSecurity));
|
2001-09-27 21:26:59 +00:00
|
|
|
if (!mSecurity)
|
2004-12-04 10:19:29 +00:00
|
|
|
mSecurity.AssignLiteral(UA_APPSECURITY_FALLBACK);
|
2001-09-27 21:26:59 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gather locale.
|
|
|
|
if (PREF_CHANGED(UA_PREF("locale"))) {
|
|
|
|
nsCOMPtr<nsIPrefLocalizedString> pls;
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetComplexValue(UA_PREF("locale"),
|
2004-09-15 19:49:30 +00:00
|
|
|
NS_GET_IID(nsIPrefLocalizedString),
|
|
|
|
getter_AddRefs(pls));
|
2001-09-27 21:26:59 +00:00
|
|
|
if (pls) {
|
|
|
|
nsXPIDLString uval;
|
|
|
|
pls->ToString(getter_Copies(uval));
|
|
|
|
if (uval)
|
2004-09-15 19:49:30 +00:00
|
|
|
CopyUTF16toUTF8(uval, mLanguage);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsXPIDLCString cval;
|
|
|
|
rv = prefs->GetCharPref(UA_PREF("locale"), getter_Copies(cval));
|
|
|
|
if (cval)
|
|
|
|
mLanguage.Assign(cval);
|
|
|
|
}
|
|
|
|
|
2001-09-27 21:26:59 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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));
|
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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))
|
|
|
|
mIdleTimeout = (PRUint16) CLAMP(val, 1, 0xffff);
|
|
|
|
}
|
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))
|
|
|
|
mMaxRequestAttempts = (PRUint16) CLAMP(val, 1, 0xffff);
|
|
|
|
}
|
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)) {
|
2001-09-04 23:02:26 +00:00
|
|
|
mMaxRequestDelay = (PRUint16) CLAMP(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)) {
|
2001-08-14 01:03:27 +00:00
|
|
|
mMaxConnections = (PRUint16) CLAMP(val, 1, 0xffff);
|
2004-08-03 23:41:36 +00:00
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->UpdateParam(nsHttpConnectionMgr::MAX_CONNECTIONS,
|
|
|
|
mMaxRequestDelay);
|
|
|
|
}
|
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)) {
|
2001-08-14 01:03:27 +00:00
|
|
|
mMaxConnectionsPerServer = (PRUint8) CLAMP(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)) {
|
2001-09-04 23:02:26 +00:00
|
|
|
mMaxPersistentConnectionsPerServer = (PRUint8) CLAMP(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)) {
|
2001-11-04 05:46:06 +00:00
|
|
|
mMaxPersistentConnectionsPerProxy = (PRUint8) CLAMP(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))
|
|
|
|
mReferrerLevel = (PRUint8) CLAMP(val, 0, 0xff);
|
|
|
|
}
|
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))
|
|
|
|
mRedirectionLimit = (PRUint8) CLAMP(val, 0, 0xff);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool cVar = PR_FALSE;
|
|
|
|
|
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)) {
|
2002-04-19 22:25:23 +00:00
|
|
|
mMaxPipelinedRequests = CLAMP(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
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (!mUseCache) {
|
|
|
|
// release our references to the cache
|
|
|
|
mCacheSession_ANY = 0;
|
|
|
|
mCacheSession_MEM = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
do_GetService(kSocketProviderServiceCID, &rv));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-15 22:12:52 +00:00
|
|
|
// enable Persistent caching for HTTPS - bug#205921
|
|
|
|
if (PREF_CHANGED(BROWSER_PREF("disk_cache_ssl"))) {
|
|
|
|
cVar = PR_FALSE;
|
|
|
|
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))
|
|
|
|
mPhishyUserPassLength = (PRUint8) CLAMP(val, 0, 0xff);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
SetAcceptLanguages(NS_ConvertUCS2toUTF8(uval).get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PREF_CHANGED(INTL_ACCEPT_CHARSET)) {
|
|
|
|
nsCOMPtr<nsIPrefLocalizedString> pls;
|
2001-10-02 00:40:27 +00:00
|
|
|
prefs->GetComplexValue(INTL_ACCEPT_CHARSET,
|
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)
|
|
|
|
SetAcceptCharsets(NS_ConvertUCS2toUTF8(uval).get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-05 07:50:21 +00:00
|
|
|
//
|
|
|
|
// IDN options
|
|
|
|
//
|
|
|
|
|
|
|
|
if (PREF_CHANGED(NETWORK_ENABLEIDN)) {
|
|
|
|
PRBool enableIDN = PR_FALSE;
|
|
|
|
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) {
|
|
|
|
mIDNConverter = do_GetService(NS_IDNSERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "idnSDK not installed");
|
|
|
|
}
|
|
|
|
else if (!enableIDN && mIDNConverter)
|
|
|
|
mIDNConverter = nsnull;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
if (nsnull == 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 ((char *) 0 == q_Accept)
|
|
|
|
return nsnull;
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocates a C string into that contains a character set/encoding list
|
|
|
|
* notated with HTTP "q" values for output with a HTTP Accept-Charset
|
|
|
|
* header. If the UTF-8 character set is not present, it will be added.
|
|
|
|
* If a wildcard catch-all is not present, it will be added. If more than
|
|
|
|
* one charset is set (as of 2001-02-07, only one is used), they will be
|
|
|
|
* comma delimited and with q values set for each charset in decending order.
|
|
|
|
*
|
|
|
|
* Ex: passing: "euc-jp"
|
2002-11-20 20:51:12 +00:00
|
|
|
* returns: "euc-jp,utf-8;q=0.6,*;q=0.6"
|
2001-05-11 21:04:09 +00:00
|
|
|
*
|
|
|
|
* passing: "UTF-8"
|
|
|
|
* returns: "UTF-8, *"
|
|
|
|
*/
|
|
|
|
static nsresult
|
|
|
|
PrepareAcceptCharsets(const char *i_AcceptCharset, nsACString &o_AcceptCharset)
|
|
|
|
{
|
2003-03-26 01:21:26 +00:00
|
|
|
PRUint32 n, size, wrote, u;
|
2001-05-11 21:04:09 +00:00
|
|
|
PRInt32 available;
|
|
|
|
double q, dec;
|
|
|
|
char *p, *p2, *token, *q_Accept, *o_Accept;
|
|
|
|
const char *acceptable, *comma;
|
|
|
|
PRBool add_utf = PR_FALSE;
|
2001-12-23 23:23:41 +00:00
|
|
|
PRBool add_asterisk = PR_FALSE;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
if (!i_AcceptCharset)
|
|
|
|
acceptable = "";
|
|
|
|
else
|
|
|
|
acceptable = i_AcceptCharset;
|
|
|
|
o_Accept = nsCRT::strdup(acceptable);
|
|
|
|
if (nsnull == o_Accept)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
for (p = o_Accept, n = size = 0; '\0' != *p; p++) {
|
|
|
|
if (*p == ',') n++;
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only add "utf-8" and "*" to the list if they aren't
|
|
|
|
// already specified.
|
|
|
|
|
|
|
|
if (PL_strcasestr(acceptable, "utf-8") == NULL) {
|
|
|
|
n++;
|
|
|
|
add_utf = PR_TRUE;
|
|
|
|
}
|
|
|
|
if (PL_strstr(acceptable, "*") == NULL) {
|
|
|
|
n++;
|
2001-12-23 23:23:41 +00:00
|
|
|
add_asterisk = PR_TRUE;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
available = size + ++n * 11 + 1;
|
|
|
|
q_Accept = new char[available];
|
|
|
|
if ((char *) 0 == q_Accept)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
*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
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (add_utf) {
|
2002-11-20 20:51:12 +00:00
|
|
|
comma = n++ != 0 ? "," : ""; // delimiter if not first item
|
2003-03-26 01:21:26 +00:00
|
|
|
u = QVAL_TO_UINT(q);
|
|
|
|
if (u < 10)
|
|
|
|
wrote = PR_snprintf(p2, available, "%sutf-8;q=0.%u", comma, u);
|
2001-05-11 21:04:09 +00:00
|
|
|
else
|
|
|
|
wrote = PR_snprintf(p2, available, "%sutf-8", comma);
|
|
|
|
q -= dec;
|
|
|
|
p2 += wrote;
|
|
|
|
available -= wrote;
|
|
|
|
NS_ASSERTION(available > 0, "allocated string not long enough");
|
|
|
|
}
|
2001-12-23 23:23:41 +00:00
|
|
|
if (add_asterisk) {
|
2002-11-20 20:51:12 +00:00
|
|
|
comma = n++ != 0 ? "," : ""; // delimiter if not first item
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
// keep q of "*" equal to the lowest q value
|
|
|
|
// in the event of a tie between the q of "*" and a non-wildcard
|
|
|
|
// the non-wildcard always receives preference.
|
|
|
|
|
|
|
|
q += dec;
|
2003-03-26 01:21:26 +00:00
|
|
|
u = QVAL_TO_UINT(q);
|
|
|
|
if (u < 10)
|
|
|
|
wrote = PR_snprintf(p2, available, "%s*;q=0.%u", comma, u);
|
2001-05-11 21:04:09 +00:00
|
|
|
else
|
|
|
|
wrote = PR_snprintf(p2, available, "%s*", comma);
|
|
|
|
available -= wrote;
|
|
|
|
p2 += wrote;
|
|
|
|
NS_ASSERTION(available > 0, "allocated string not long enough");
|
|
|
|
}
|
|
|
|
nsCRT::free(o_Accept);
|
|
|
|
|
|
|
|
// change alloc from C++ new/delete to nsCRT::strdup's way
|
|
|
|
o_AcceptCharset.Assign(q_Accept);
|
|
|
|
#if defined DEBUG_havill
|
|
|
|
printf("Accept-Charset: %s\n", q_Accept);
|
|
|
|
#endif
|
|
|
|
delete [] q_Accept;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsHttpHandler::SetAcceptCharsets(const char *aAcceptCharsets)
|
|
|
|
{
|
|
|
|
nsCString buf;
|
|
|
|
nsresult rv = PrepareAcceptCharsets(aAcceptCharsets, buf);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2002-03-20 22:50:33 +00:00
|
|
|
mAcceptCharsets.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
|
|
|
{
|
2001-09-13 02:21:05 +00:00
|
|
|
*result = URI_STD | ALLOWS_PROXY | ALLOWS_PROXY_HTTP;
|
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);
|
|
|
|
|
|
|
|
PRBool isHttp = PR_FALSE, isHttps = PR_FALSE;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
nsHttpHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval)
|
|
|
|
{
|
|
|
|
// don't override anything.
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
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
|
|
|
{
|
|
|
|
nsHttpChannel *httpChannel = nsnull;
|
|
|
|
|
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
|
|
|
|
2004-06-11 15:09:36 +00:00
|
|
|
PRBool https;
|
|
|
|
nsresult rv = uri->SchemeIs("https", &https);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
NS_NEWXPCOM(httpChannel, nsHttpChannel);
|
|
|
|
if (!httpChannel)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(httpChannel);
|
|
|
|
|
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) {
|
|
|
|
// HACK: make sure PSM gets initialized on the main thread.
|
|
|
|
nsCOMPtr<nsISocketProviderService> spserv =
|
|
|
|
do_GetService(kSocketProviderServiceCID);
|
|
|
|
if (spserv) {
|
|
|
|
nsCOMPtr<nsISocketProvider> provider;
|
|
|
|
spserv->GetSocketProvider("ssl", getter_AddRefs(provider));
|
|
|
|
}
|
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);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2002-04-18 22:36:39 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(httpChannel);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*result = httpChannel;
|
|
|
|
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
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mAppName;
|
|
|
|
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
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mAppVersion;
|
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetVendor(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mVendor;
|
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::SetVendor(const nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
mVendor = value;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetVendorSub(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mVendorSub;
|
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::SetVendorSub(const nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
mVendorSub = value;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetVendorComment(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mVendorComment;
|
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::SetVendorComment(const nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
mVendorComment = value;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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::SetProduct(const nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
mProduct = value;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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::SetProductSub(const nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
mProductSub = value;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::GetProductComment(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-22 21:25:58 +00:00
|
|
|
value = mProductComment;
|
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::SetProductComment(const nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
mProductComment = value;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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::GetLanguage(nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
value = mLanguage;
|
|
|
|
return NS_OK;
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::SetLanguage(const nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
mLanguage = value;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
nsHttpHandler::SetMisc(const nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2002-03-20 22:50:33 +00:00
|
|
|
mMisc = value;
|
2001-05-11 21:04:09 +00:00
|
|
|
mUserAgentIsDirty = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// 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)
|
|
|
|
PrefsChanged(prefBranch, NS_ConvertUCS2toUTF8(data).get());
|
|
|
|
}
|
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
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// kill off the "prune dead connections" timer
|
|
|
|
StopPruneDeadConnectionsTimer();
|
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();
|
|
|
|
|
|
|
|
// ensure connection manager is shutdown
|
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->Shutdown();
|
2002-04-20 05:40:24 +00:00
|
|
|
|
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();
|
|
|
|
}
|
2003-02-19 14:53:11 +00:00
|
|
|
else if (strcmp(topic, "session-logout") == 0) {
|
|
|
|
// clear cache of all authentication credentials.
|
|
|
|
mAuthCache.ClearAll();
|
|
|
|
|
|
|
|
// need to reset the session start time since cache validation may
|
|
|
|
// depend on this value.
|
|
|
|
mSessionStartTime = NowInSeconds();
|
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
else if (strcmp(topic, "profile-change-net-restore") == 0) {
|
|
|
|
// initialize connection manager
|
|
|
|
InitConnectionMgr();
|
2002-11-06 13:01:42 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// restart the "prune dead connections" timer
|
|
|
|
StartPruneDeadConnectionsTimer();
|
|
|
|
}
|
|
|
|
else if (strcmp(topic, "timer-callback") == 0) {
|
|
|
|
// prune dead connections
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsITimer> timer = do_QueryInterface(subject);
|
|
|
|
NS_ASSERTION(timer == mTimer, "unexpected timer-callback");
|
|
|
|
#endif
|
|
|
|
if (mConnMgr)
|
|
|
|
mConnMgr->PruneDeadConnections();
|
2001-12-07 01:40:18 +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)
|
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
return gHttpHandler->GetProtocolFlags(aProtocolFlags);
|
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)
|
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
return gHttpHandler->NewChannel(aURI, _retval);
|
2002-08-13 20:33:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHttpsHandler::AllowPort(PRInt32 aPort, const char *aScheme, PRBool *_retval)
|
|
|
|
{
|
|
|
|
// don't override anything.
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|