2010-04-07 12:43:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
|
|
|
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2013-06-22 20:01:06 +04:00
|
|
|
// HttpLog.h should generally be included first
|
|
|
|
#include "HttpLog.h"
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
#include "mozilla/net/HttpBaseChannel.h"
|
|
|
|
|
|
|
|
#include "nsHttpHandler.h"
|
|
|
|
#include "nsMimeTypes.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsNetCID.h"
|
2010-04-07 12:43:09 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2010-08-11 07:11:57 +04:00
|
|
|
#include "nsICachingChannel.h"
|
2015-10-30 05:53:25 +03:00
|
|
|
#include "nsIDOMDocument.h"
|
2014-05-28 18:04:04 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2015-02-09 15:04:00 +03:00
|
|
|
#include "nsIScriptError.h"
|
2010-08-11 07:11:57 +04:00
|
|
|
#include "nsISeekableStream.h"
|
2015-09-15 20:15:45 +03:00
|
|
|
#include "nsIStorageStream.h"
|
2011-05-21 14:03:36 +04:00
|
|
|
#include "nsITimedChannel.h"
|
2010-08-11 07:11:57 +04:00
|
|
|
#include "nsIEncodedChannel.h"
|
|
|
|
#include "nsIApplicationCacheChannel.h"
|
2014-05-22 23:58:23 +04:00
|
|
|
#include "nsIMutableArray.h"
|
2010-08-11 07:07:09 +04:00
|
|
|
#include "nsEscape.h"
|
2012-05-10 22:58:48 +04:00
|
|
|
#include "nsStreamListenerWrapper.h"
|
2013-07-26 19:37:03 +04:00
|
|
|
#include "nsISecurityConsoleMessage.h"
|
2013-09-23 07:35:52 +04:00
|
|
|
#include "nsURLHelper.h"
|
|
|
|
#include "nsICookieService.h"
|
|
|
|
#include "nsIStreamConverterService.h"
|
|
|
|
#include "nsCRT.h"
|
2013-10-16 05:35:44 +04:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
2014-02-26 22:44:42 +04:00
|
|
|
#include "nsIObserverService.h"
|
2014-09-29 19:48:11 +04:00
|
|
|
#include "nsProxyRelease.h"
|
2014-10-06 15:33:13 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2015-12-08 11:27:00 +03:00
|
|
|
#include "nsIDocShell.h"
|
2014-10-06 15:33:13 +04:00
|
|
|
#include "nsPerformance.h"
|
2014-07-10 00:35:02 +04:00
|
|
|
#include "nsINetworkInterceptController.h"
|
2014-10-30 03:22:22 +03:00
|
|
|
#include "mozIThirdPartyUtil.h"
|
2015-05-04 23:53:40 +03:00
|
|
|
#include "nsStreamUtils.h"
|
2015-05-15 23:21:20 +03:00
|
|
|
#include "nsContentSecurityManager.h"
|
2015-11-01 01:22:01 +03:00
|
|
|
#include "nsIChannelEventSink.h"
|
2015-07-31 23:50:08 +03:00
|
|
|
#include "nsILoadGroupChild.h"
|
2015-10-30 05:53:25 +03:00
|
|
|
#include "mozilla/ConsoleReportCollector.h"
|
2015-11-01 01:22:01 +03:00
|
|
|
#include "LoadInfo.h"
|
2016-01-09 04:20:50 +03:00
|
|
|
#include "nsISSLSocketControl.h"
|
|
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIConsoleService.h"
|
2016-04-06 10:28:00 +03:00
|
|
|
#include "mozilla/BinarySearch.h"
|
2016-05-03 01:06:00 +03:00
|
|
|
#include "nsIHttpHeaderVisitor.h"
|
2010-08-11 07:11:57 +04:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2011-05-05 19:45:59 +04:00
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
HttpBaseChannel::HttpBaseChannel()
|
2012-09-28 23:55:23 +04:00
|
|
|
: mStartPos(UINT64_MAX)
|
2010-08-11 07:07:09 +04:00
|
|
|
, mStatus(NS_OK)
|
2010-04-07 12:43:09 +04:00
|
|
|
, mLoadFlags(LOAD_NORMAL)
|
|
|
|
, mCaps(0)
|
2014-12-06 22:26:50 +03:00
|
|
|
, mClassOfService(0)
|
2012-11-30 05:34:35 +04:00
|
|
|
, mPriority(PRIORITY_NORMAL)
|
2010-04-07 12:43:09 +04:00
|
|
|
, mRedirectionLimit(gHttpHandler->RedirectionLimit())
|
2011-10-17 18:59:28 +04:00
|
|
|
, mApplyConversion(true)
|
|
|
|
, mCanceled(false)
|
|
|
|
, mIsPending(false)
|
|
|
|
, mWasOpened(false)
|
2012-12-04 10:24:36 +04:00
|
|
|
, mRequestObserversCalled(false)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mResponseHeadersModified(false)
|
|
|
|
, mAllowPipelining(true)
|
2014-06-04 20:57:15 +04:00
|
|
|
, mAllowSTS(true)
|
2014-10-28 16:23:00 +03:00
|
|
|
, mThirdPartyFlags(0)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mUploadStreamHasHeaders(false)
|
|
|
|
, mInheritApplicationCache(true)
|
|
|
|
, mChooseApplicationCache(false)
|
|
|
|
, mLoadedFromApplicationCache(false)
|
|
|
|
, mChannelIsForDownload(false)
|
|
|
|
, mTracingEnabled(true)
|
|
|
|
, mTimingEnabled(false)
|
2011-12-13 19:55:50 +04:00
|
|
|
, mAllowSpdy(true)
|
2015-04-13 19:59:34 +03:00
|
|
|
, mAllowAltSvc(true)
|
2013-12-19 03:03:48 +04:00
|
|
|
, mResponseTimeoutEnabled(true)
|
2013-10-16 05:35:44 +04:00
|
|
|
, mAllRedirectsSameOrigin(true)
|
2014-05-15 09:26:07 +04:00
|
|
|
, mAllRedirectsPassTimingAllowCheck(true)
|
2015-08-17 23:18:41 +03:00
|
|
|
, mResponseCouldBeSynthesized(false)
|
2015-12-30 21:47:55 +03:00
|
|
|
, mBlockAuthPrompt(false)
|
2016-01-19 17:28:00 +03:00
|
|
|
, mAllowStaleCacheContent(false)
|
2011-06-12 05:37:03 +04:00
|
|
|
, mSuspendCount(0)
|
2015-09-11 22:53:27 +03:00
|
|
|
, mInitialRwin(0)
|
2012-09-15 00:27:46 +04:00
|
|
|
, mProxyResolveFlags(0)
|
2015-01-21 23:13:00 +03:00
|
|
|
, mProxyURI(nullptr)
|
2012-10-02 20:43:00 +04:00
|
|
|
, mContentDispositionHint(UINT32_MAX)
|
2013-08-13 23:36:58 +04:00
|
|
|
, mHttpHandler(gHttpHandler)
|
2014-11-18 16:46:29 +03:00
|
|
|
, mReferrerPolicy(REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE)
|
2013-10-16 05:35:44 +04:00
|
|
|
, mRedirectCount(0)
|
2014-06-27 05:51:49 +04:00
|
|
|
, mForcePending(false)
|
2015-03-17 18:47:02 +03:00
|
|
|
, mCorsIncludeCredentials(false)
|
|
|
|
, mCorsMode(nsIHttpChannelInternal::CORS_MODE_NO_CORS)
|
2015-09-01 00:26:29 +03:00
|
|
|
, mRedirectMode(nsIHttpChannelInternal::REDIRECT_MODE_FOLLOW)
|
2016-02-29 00:34:01 +03:00
|
|
|
, mFetchCacheMode(nsIHttpChannelInternal::FETCH_CACHE_MODE_DEFAULT)
|
2015-04-02 13:12:00 +03:00
|
|
|
, mOnStartRequestCalled(false)
|
2016-04-06 11:47:00 +03:00
|
|
|
, mOnStopRequestCalled(false)
|
2015-07-24 18:49:25 +03:00
|
|
|
, mTransferSize(0)
|
|
|
|
, mDecodedBodySize(0)
|
|
|
|
, mEncodedBodySize(0)
|
2015-08-22 00:31:56 +03:00
|
|
|
, mRequireCORSPreflight(false)
|
2015-10-30 05:53:25 +03:00
|
|
|
, mReportCollector(new ConsoleReportCollector())
|
2015-10-05 16:46:24 +03:00
|
|
|
, mForceMainDocumentChannel(false)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
LOG(("Creating HttpBaseChannel @%x\n", this));
|
|
|
|
|
2014-11-14 06:27:31 +03:00
|
|
|
// Subfields of unions cannot be targeted in an initializer list.
|
|
|
|
#ifdef MOZ_VALGRIND
|
|
|
|
// Zero the entire unions so that Valgrind doesn't complain when we send them
|
|
|
|
// to another process.
|
|
|
|
memset(&mSelfAddr, 0, sizeof(NetAddr));
|
|
|
|
memset(&mPeerAddr, 0, sizeof(NetAddr));
|
|
|
|
#endif
|
2011-06-10 01:02:09 +04:00
|
|
|
mSelfAddr.raw.family = PR_AF_UNSPEC;
|
|
|
|
mPeerAddr.raw.family = PR_AF_UNSPEC;
|
2016-04-21 17:59:17 +03:00
|
|
|
mRequestContextID.Clear();
|
2010-04-07 12:43:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
HttpBaseChannel::~HttpBaseChannel()
|
|
|
|
{
|
|
|
|
LOG(("Destroying HttpBaseChannel @%x\n", this));
|
|
|
|
|
2016-02-10 10:23:00 +03:00
|
|
|
NS_ReleaseOnMainThread(mLoadInfo.forget());
|
2014-09-29 19:48:11 +04:00
|
|
|
|
2011-03-24 06:36:53 +03:00
|
|
|
// Make sure we don't leak
|
|
|
|
CleanRedirectCacheChainIfNecessary();
|
2010-04-07 12:43:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HttpBaseChannel::Init(nsIURI *aURI,
|
2012-11-30 05:34:35 +04:00
|
|
|
uint32_t aCaps,
|
2012-09-15 00:27:46 +04:00
|
|
|
nsProxyInfo *aProxyInfo,
|
|
|
|
uint32_t aProxyResolveFlags,
|
|
|
|
nsIURI *aProxyURI)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
LOG(("HttpBaseChannel::Init [this=%p]\n", this));
|
|
|
|
|
|
|
|
NS_PRECONDITION(aURI, "null uri");
|
|
|
|
|
|
|
|
mURI = aURI;
|
|
|
|
mOriginalURI = aURI;
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocumentURI = nullptr;
|
2010-04-07 12:43:09 +04:00
|
|
|
mCaps = aCaps;
|
2012-09-15 00:27:46 +04:00
|
|
|
mProxyResolveFlags = aProxyResolveFlags;
|
|
|
|
mProxyURI = aProxyURI;
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
// Construct connection info object
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString host;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t port = -1;
|
2015-09-20 01:51:32 +03:00
|
|
|
bool isHTTPS = false;
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2015-09-20 01:51:32 +03:00
|
|
|
nsresult rv = mURI->SchemeIs("https", &isHTTPS);
|
2010-04-07 12:43:09 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mURI->GetAsciiHost(host);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Reject the URL if it doesn't specify a host
|
|
|
|
if (host.IsEmpty())
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
|
|
|
|
rv = mURI->GetPort(&port);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
LOG(("host=%s port=%d\n", host.get(), port));
|
|
|
|
|
|
|
|
rv = mURI->GetAsciiSpec(mSpec);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
LOG(("uri=%s\n", mSpec.get()));
|
|
|
|
|
2014-03-18 20:36:18 +04:00
|
|
|
// Assert default request method
|
|
|
|
MOZ_ASSERT(mRequestHead.EqualsMethod(nsHttpRequestHead::kMethod_Get));
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
// Set request headers
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString hostLine;
|
2010-04-07 12:43:09 +04:00
|
|
|
rv = nsHttpHandler::GenerateHostPort(host, port, hostLine);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mRequestHead.SetHeader(nsHttp::Host, hostLine);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2016-05-03 01:06:00 +03:00
|
|
|
rv = gHttpHandler->AddStandardRequestHeaders(&mRequestHead, isHTTPS);
|
2012-09-15 00:27:46 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsAutoCString type;
|
|
|
|
if (aProxyInfo && NS_SUCCEEDED(aProxyInfo->GetType(type)) &&
|
|
|
|
!type.EqualsLiteral("unknown"))
|
|
|
|
mProxyInfo = aProxyInfo;
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsISupports
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-04-21 17:34:33 +04:00
|
|
|
NS_IMPL_ADDREF(HttpBaseChannel)
|
|
|
|
NS_IMPL_RELEASE(HttpBaseChannel)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(HttpBaseChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequest)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIEncodedChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIHttpChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIHttpChannelInternal)
|
2014-07-10 18:13:00 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIForcePendingChannel)
|
2014-04-21 17:34:33 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIUploadChannel)
|
2016-01-28 13:38:34 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFormPOSTActionChannel)
|
2014-04-21 17:34:33 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIUploadChannel2)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsPriority)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITraceableChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIPrivateBrowsingChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsITimedChannel)
|
2015-10-30 05:53:25 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIConsoleReportCollector)
|
2014-04-21 17:34:33 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsHashPropertyBag)
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsIRequest
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetName(nsACString& aName)
|
|
|
|
{
|
|
|
|
aName = mSpec;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::IsPending(bool *aIsPending)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsPending);
|
2014-06-27 05:51:49 +04:00
|
|
|
*aIsPending = mIsPending || mForcePending;
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetStatus(nsresult *aStatus)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aStatus);
|
|
|
|
*aStatus = mStatus;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetLoadGroup(nsILoadGroup **aLoadGroup)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLoadGroup);
|
|
|
|
*aLoadGroup = mLoadGroup;
|
|
|
|
NS_IF_ADDREF(*aLoadGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetLoadGroup(nsILoadGroup *aLoadGroup)
|
|
|
|
{
|
2013-07-09 05:45:25 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
|
2015-12-08 11:27:00 +03:00
|
|
|
|
2012-09-26 18:36:38 +04:00
|
|
|
if (!CanSetLoadGroup(aLoadGroup)) {
|
2012-09-05 04:37:45 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
mLoadGroup = aLoadGroup;
|
2012-07-30 18:20:58 +04:00
|
|
|
mProgressSink = nullptr;
|
2015-12-31 01:51:21 +03:00
|
|
|
UpdatePrivateBrowsing();
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLoadFlags);
|
|
|
|
*aLoadFlags = mLoadFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
|
|
|
|
{
|
2015-10-22 16:23:39 +03:00
|
|
|
bool synthesized = false;
|
|
|
|
nsresult rv = GetResponseSynthesized(&synthesized);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If this channel is marked as awaiting a synthesized response,
|
|
|
|
// modifying certain load flags can interfere with the implementation
|
|
|
|
// of the network interception logic. This takes care of a couple
|
|
|
|
// known cases that attempt to mark channels as anonymous due
|
|
|
|
// to cross-origin redirects; since the response is entirely synthesized
|
|
|
|
// this is an unnecessary precaution.
|
|
|
|
// This should be removed when bug 1201683 is fixed.
|
|
|
|
if (synthesized && aLoadFlags != mLoadFlags) {
|
|
|
|
aLoadFlags &= ~LOAD_ANONYMOUS;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
mLoadFlags = aLoadFlags;
|
2015-10-05 16:46:24 +03:00
|
|
|
mForceMainDocumentChannel = (aLoadFlags & LOAD_DOCUMENT_URI);
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-12-08 11:27:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetDocshellUserAgentOverride()
|
|
|
|
{
|
|
|
|
// This sets the docshell specific user agent override, it will be overwritten
|
|
|
|
// by UserAgentOverrides.jsm if site-specific user agent overrides are set.
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext;
|
|
|
|
NS_QueryNotificationCallbacks(this, loadContext);
|
|
|
|
if (!loadContext) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> domWindow;
|
2015-12-08 11:27:00 +03:00
|
|
|
loadContext->GetAssociatedWindow(getter_AddRefs(domWindow));
|
|
|
|
if (!domWindow) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* pDomWindow = nsPIDOMWindowOuter::From(domWindow);
|
2015-12-08 11:27:00 +03:00
|
|
|
nsIDocShell* docshell = pDomWindow->GetDocShell();
|
|
|
|
if (!docshell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString customUserAgent;
|
|
|
|
docshell->GetCustomUserAgent(customUserAgent);
|
|
|
|
if (customUserAgent.IsEmpty()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 utf8CustomUserAgent(customUserAgent);
|
|
|
|
rv = SetRequestHeader(NS_LITERAL_CSTRING("User-Agent"), utf8CustomUserAgent, false);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsIChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetOriginalURI(nsIURI **aOriginalURI)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOriginalURI);
|
|
|
|
*aOriginalURI = mOriginalURI;
|
|
|
|
NS_ADDREF(*aOriginalURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetOriginalURI(nsIURI *aOriginalURI)
|
|
|
|
{
|
2012-12-04 10:24:36 +04:00
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aOriginalURI);
|
|
|
|
mOriginalURI = aOriginalURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetURI(nsIURI **aURI)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
*aURI = mURI;
|
|
|
|
NS_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-21 13:02:05 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetOwner(nsISupports **aOwner)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOwner);
|
|
|
|
*aOwner = mOwner;
|
|
|
|
NS_IF_ADDREF(*aOwner);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetOwner(nsISupports *aOwner)
|
|
|
|
{
|
|
|
|
mOwner = aOwner;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-10 10:56:36 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetLoadInfo(nsILoadInfo *aLoadInfo)
|
|
|
|
{
|
|
|
|
mLoadInfo = aLoadInfo;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetLoadInfo(nsILoadInfo **aLoadInfo)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aLoadInfo = mLoadInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks)
|
|
|
|
{
|
|
|
|
*aCallbacks = mCallbacks;
|
|
|
|
NS_IF_ADDREF(*aCallbacks);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks)
|
|
|
|
{
|
2013-07-09 05:45:25 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
|
2015-12-08 11:27:00 +03:00
|
|
|
|
2012-09-26 18:36:38 +04:00
|
|
|
if (!CanSetCallbacks(aCallbacks)) {
|
2012-09-05 04:37:45 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
mCallbacks = aCallbacks;
|
2012-07-30 18:20:58 +04:00
|
|
|
mProgressSink = nullptr;
|
2012-07-23 02:35:33 +04:00
|
|
|
|
2015-12-31 01:51:21 +03:00
|
|
|
UpdatePrivateBrowsing();
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetContentType(nsACString& aContentType)
|
|
|
|
{
|
|
|
|
if (!mResponseHead) {
|
|
|
|
aContentType.Truncate();
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mResponseHead->ContentType().IsEmpty()) {
|
|
|
|
aContentType = mResponseHead->ContentType();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
aContentType.AssignLiteral(UNKNOWN_CONTENT_TYPE);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetContentType(const nsACString& aContentType)
|
|
|
|
{
|
|
|
|
if (mListener || mWasOpened) {
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contentTypeBuf, charsetBuf;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hadCharset;
|
2010-04-07 12:43:09 +04:00
|
|
|
net_ParseContentType(aContentType, contentTypeBuf, charsetBuf, &hadCharset);
|
|
|
|
|
|
|
|
mResponseHead->SetContentType(contentTypeBuf);
|
|
|
|
|
|
|
|
// take care not to stomp on an existing charset
|
|
|
|
if (hadCharset)
|
|
|
|
mResponseHead->SetContentCharset(charsetBuf);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// We are being given a content-type hint.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dummy;
|
2010-04-07 12:43:09 +04:00
|
|
|
net_ParseContentType(aContentType, mContentTypeHint, mContentCharsetHint,
|
|
|
|
&dummy);
|
|
|
|
}
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetContentCharset(nsACString& aContentCharset)
|
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
aContentCharset = mResponseHead->ContentCharset();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetContentCharset(const nsACString& aContentCharset)
|
|
|
|
{
|
|
|
|
if (mListener) {
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
mResponseHead->SetContentCharset(aContentCharset);
|
|
|
|
} else {
|
|
|
|
// Charset hint
|
|
|
|
mContentCharsetHint = aContentCharset;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:41:04 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::GetContentDisposition(uint32_t *aContentDisposition)
|
2011-09-10 02:41:04 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCString header;
|
|
|
|
|
|
|
|
rv = GetContentDispositionHeader(header);
|
2012-10-02 20:43:00 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (mContentDispositionHint == UINT32_MAX)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*aContentDisposition = mContentDispositionHint;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-10 02:41:04 +04:00
|
|
|
|
|
|
|
*aContentDisposition = NS_GetContentDispositionFromHeader(header, this);
|
2012-10-02 20:43:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-10 02:41:04 +04:00
|
|
|
|
2012-10-02 20:43:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetContentDisposition(uint32_t aContentDisposition)
|
|
|
|
{
|
|
|
|
mContentDispositionHint = aContentDisposition;
|
2011-09-10 02:41:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetContentDispositionFilename(nsAString& aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
aContentDispositionFilename.Truncate();
|
|
|
|
nsresult rv;
|
|
|
|
nsCString header;
|
|
|
|
|
|
|
|
rv = GetContentDispositionHeader(header);
|
2012-10-02 20:43:00 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (!mContentDispositionFilename)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
aContentDispositionFilename = *mContentDispositionFilename;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-10 02:41:04 +04:00
|
|
|
|
|
|
|
return NS_GetFilenameFromDisposition(aContentDispositionFilename,
|
|
|
|
header, mURI);
|
|
|
|
}
|
|
|
|
|
2012-10-02 20:43:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetContentDispositionFilename(const nsAString& aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
mContentDispositionFilename = new nsString(aContentDispositionFilename);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:41:04 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetContentDispositionHeader(nsACString& aContentDispositionHeader)
|
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
nsresult rv = mResponseHead->GetHeader(nsHttp::Content_Disposition,
|
|
|
|
aContentDispositionHeader);
|
|
|
|
if (NS_FAILED(rv) || aContentDispositionHeader.IsEmpty())
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
2012-10-22 21:51:07 +04:00
|
|
|
HttpBaseChannel::GetContentLength(int64_t *aContentLength)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
2010-08-31 00:20:39 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aContentLength);
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
*aContentLength = mResponseHead->ContentLength();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-22 21:51:07 +04:00
|
|
|
HttpBaseChannel::SetContentLength(int64_t value)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
2010-09-16 02:55:08 +04:00
|
|
|
NS_NOTYETIMPLEMENTED("HttpBaseChannel::SetContentLength");
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::Open(nsIInputStream **aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(!mWasOpened, NS_ERROR_IN_PROGRESS);
|
2016-02-18 10:54:00 +03:00
|
|
|
|
|
|
|
if (!gHttpHandler->Active()) {
|
|
|
|
LOG(("HttpBaseChannel::Open after HTTP shutdown..."));
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_ImplementChannelOpen(this, aResult);
|
|
|
|
}
|
|
|
|
|
2015-05-15 23:21:20 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::Open2(nsIInputStream** aStream)
|
|
|
|
{
|
2016-02-18 10:54:00 +03:00
|
|
|
if (!gHttpHandler->Active()) {
|
|
|
|
LOG(("HttpBaseChannel::Open after HTTP shutdown..."));
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2015-05-15 23:21:20 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
|
|
|
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return Open(aStream);
|
|
|
|
}
|
|
|
|
|
2010-05-31 02:30:28 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsIUploadChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetUploadStream(nsIInputStream **stream)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(stream);
|
|
|
|
*stream = mUploadStream;
|
|
|
|
NS_IF_ADDREF(*stream);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetUploadStream(nsIInputStream *stream,
|
|
|
|
const nsACString &contentType,
|
2012-09-19 12:09:08 +04:00
|
|
|
int64_t contentLength)
|
2010-05-31 02:30:28 +04:00
|
|
|
{
|
|
|
|
// NOTE: for backwards compatibility and for compatibility with old style
|
|
|
|
// plugins, |stream| may include headers, specifically Content-Type and
|
|
|
|
// Content-Length headers. in this case, |contentType| and |contentLength|
|
|
|
|
// would be unspecified. this is traditionally the case of a POST request,
|
|
|
|
// and so we select POST as the request method if contentType and
|
|
|
|
// contentLength are unspecified.
|
|
|
|
|
|
|
|
if (stream) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString method;
|
2012-08-11 06:44:11 +04:00
|
|
|
bool hasHeaders;
|
|
|
|
|
2010-05-31 02:30:28 +04:00
|
|
|
if (contentType.IsEmpty()) {
|
2014-03-18 20:36:18 +04:00
|
|
|
method = NS_LITERAL_CSTRING("POST");
|
2012-08-11 06:44:11 +04:00
|
|
|
hasHeaders = true;
|
2010-05-31 02:30:28 +04:00
|
|
|
} else {
|
2014-03-18 20:36:18 +04:00
|
|
|
method = NS_LITERAL_CSTRING("PUT");
|
2012-08-11 06:44:11 +04:00
|
|
|
hasHeaders = false;
|
2010-05-31 02:30:28 +04:00
|
|
|
}
|
2012-08-11 06:44:11 +04:00
|
|
|
return ExplicitSetUploadStream(stream, contentType, contentLength,
|
|
|
|
method, hasHeaders);
|
2010-05-31 02:30:28 +04:00
|
|
|
}
|
2012-08-11 06:44:11 +04:00
|
|
|
|
|
|
|
// if stream is null, ExplicitSetUploadStream returns error.
|
|
|
|
// So we need special case for GET method.
|
|
|
|
mUploadStreamHasHeaders = false;
|
2014-03-18 20:36:18 +04:00
|
|
|
mRequestHead.SetMethod(NS_LITERAL_CSTRING("GET")); // revert to GET request
|
2010-05-31 02:30:28 +04:00
|
|
|
mUploadStream = stream;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-15 20:15:45 +03:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void
|
|
|
|
CopyComplete(void* aClosure, nsresult aStatus) {
|
|
|
|
// Called on the STS thread by NS_AsyncCopy
|
|
|
|
auto channel = static_cast<HttpBaseChannel*>(aClosure);
|
2016-05-05 11:45:00 +03:00
|
|
|
nsCOMPtr<nsIRunnable> runnable = NewRunnableMethod<nsresult>(
|
2015-09-15 20:15:45 +03:00
|
|
|
channel, &HttpBaseChannel::EnsureUploadStreamIsCloneableComplete, aStatus);
|
|
|
|
NS_DispatchToMainThread(runnable.forget());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::EnsureUploadStreamIsCloneable(nsIRunnable* aCallback)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
|
|
|
|
NS_ENSURE_ARG_POINTER(aCallback);
|
|
|
|
|
|
|
|
// We could in theory allow multiple callers to use this method,
|
|
|
|
// but the complexity does not seem worth it yet. Just fail if
|
|
|
|
// this is called more than once simultaneously.
|
|
|
|
NS_ENSURE_FALSE(mUploadCloneableCallback, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// If the CloneUploadStream() will succeed, then synchronously invoke
|
|
|
|
// the callback to indicate we're already cloneable.
|
|
|
|
if (!mUploadStream || NS_InputStreamIsCloneable(mUploadStream)) {
|
|
|
|
aCallback->Run();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStorageStream> storageStream;
|
|
|
|
nsresult rv = NS_NewStorageStream(4096, UINT32_MAX,
|
|
|
|
getter_AddRefs(storageStream));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> newUploadStream;
|
|
|
|
rv = storageStream->NewInputStream(0, getter_AddRefs(newUploadStream));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIOutputStream> sink;
|
|
|
|
rv = storageStream->GetOutputStream(0, getter_AddRefs(sink));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> source;
|
|
|
|
if (NS_InputStreamIsBuffered(mUploadStream)) {
|
|
|
|
source = mUploadStream;
|
|
|
|
} else {
|
|
|
|
rv = NS_NewBufferedInputStream(getter_AddRefs(source), mUploadStream, 4096);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEventTarget> target =
|
|
|
|
do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
mUploadCloneableCallback = aCallback;
|
|
|
|
|
|
|
|
rv = NS_AsyncCopy(source, sink, target, NS_ASYNCCOPY_VIA_READSEGMENTS,
|
|
|
|
4096, // copy segment size
|
|
|
|
CopyComplete, this);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
mUploadCloneableCallback = nullptr;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since we're consuming the old stream, replace it with the new
|
|
|
|
// stream immediately.
|
|
|
|
mUploadStream = newUploadStream;
|
|
|
|
|
|
|
|
// Explicity hold the stream alive until copying is complete. This will
|
|
|
|
// be released in EnsureUploadStreamIsCloneableComplete().
|
|
|
|
AddRef();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HttpBaseChannel::EnsureUploadStreamIsCloneableComplete(nsresult aStatus)
|
2015-05-04 23:53:40 +03:00
|
|
|
{
|
2015-09-15 20:15:45 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
|
|
|
|
MOZ_ASSERT(mUploadCloneableCallback);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mStatus)) {
|
|
|
|
mStatus = aStatus;
|
2015-05-04 23:53:40 +03:00
|
|
|
}
|
2015-09-15 20:15:45 +03:00
|
|
|
|
|
|
|
mUploadCloneableCallback->Run();
|
|
|
|
mUploadCloneableCallback = nullptr;
|
|
|
|
|
|
|
|
// Release the reference we grabbed in EnsureUploadStreamIsCloneable() now
|
|
|
|
// that the copying is complete.
|
|
|
|
Release();
|
2015-05-04 23:53:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::CloneUploadStream(nsIInputStream** aClonedStream)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aClonedStream);
|
|
|
|
*aClonedStream = nullptr;
|
|
|
|
|
|
|
|
if (!mUploadStream) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> clonedStream;
|
2015-09-15 20:15:45 +03:00
|
|
|
nsresult rv = NS_CloneInputStream(mUploadStream, getter_AddRefs(clonedStream));
|
2015-05-04 23:53:40 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
clonedStream.forget(aClonedStream);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-31 02:30:28 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsIUploadChannel2
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::ExplicitSetUploadStream(nsIInputStream *aStream,
|
|
|
|
const nsACString &aContentType,
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t aContentLength,
|
2010-05-31 02:30:28 +04:00
|
|
|
const nsACString &aMethod,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aStreamHasHeaders)
|
2010-05-31 02:30:28 +04:00
|
|
|
{
|
2013-05-16 17:30:42 +04:00
|
|
|
// Ensure stream is set and method is valid
|
2010-05-31 02:30:28 +04:00
|
|
|
NS_ENSURE_TRUE(aStream, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
if (aContentLength < 0 && !aStreamHasHeaders) {
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult rv = aStream->Available(reinterpret_cast<uint64_t*>(&aContentLength));
|
2012-08-11 06:44:11 +04:00
|
|
|
if (NS_FAILED(rv) || aContentLength < 0) {
|
2010-05-31 02:30:28 +04:00
|
|
|
NS_ERROR("unable to determine content length");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = SetRequestMethod(aMethod);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!aStreamHasHeaders) {
|
2013-05-16 17:30:42 +04:00
|
|
|
// SetRequestHeader propagates headers to chrome if HttpChannelChild
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contentLengthStr;
|
2010-05-31 02:30:28 +04:00
|
|
|
contentLengthStr.AppendInt(aContentLength);
|
2013-05-16 17:30:42 +04:00
|
|
|
SetRequestHeader(NS_LITERAL_CSTRING("Content-Length"), contentLengthStr,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
2015-10-14 06:50:33 +03:00
|
|
|
SetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), aContentType,
|
|
|
|
false);
|
2010-05-31 02:30:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mUploadStreamHasHeaders = aStreamHasHeaders;
|
|
|
|
mUploadStream = aStream;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-29 17:55:38 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::GetUploadStreamHasHeaders(bool *hasHeaders)
|
2011-05-29 17:55:38 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(hasHeaders);
|
|
|
|
|
|
|
|
*hasHeaders = mUploadStreamHasHeaders;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsIEncodedChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::GetApplyConversion(bool *value)
|
2010-09-16 02:55:08 +04:00
|
|
|
{
|
|
|
|
*value = mApplyConversion;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::SetApplyConversion(bool value)
|
2010-09-16 02:55:08 +04:00
|
|
|
{
|
|
|
|
LOG(("HttpBaseChannel::SetApplyConversion [this=%p value=%d]\n", this, value));
|
|
|
|
mApplyConversion = value;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-10-22 03:40:08 +04:00
|
|
|
nsresult
|
|
|
|
HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener,
|
|
|
|
nsIStreamListener** aNewNextListener)
|
|
|
|
{
|
|
|
|
return DoApplyContentConversions(aNextListener,
|
|
|
|
aNewNextListener,
|
|
|
|
mListenerContext);
|
|
|
|
}
|
|
|
|
|
2015-10-05 21:11:26 +03:00
|
|
|
// create a listener chain that looks like this
|
|
|
|
// http-channel -> decompressor (n times) -> InterceptFailedOnSTop -> channel-creator-listener
|
|
|
|
//
|
|
|
|
// we need to do this because not every decompressor has fully streamed output so
|
|
|
|
// may need a call to OnStopRequest to identify its completion state.. and if it
|
|
|
|
// creates an error there the channel status code needs to be updated before calling
|
|
|
|
// the terminal listener. Having the decompress do it via cancel() means channels cannot
|
|
|
|
// effectively be used in two contexts (specifically this one and a peek context for
|
|
|
|
// sniffing)
|
|
|
|
//
|
|
|
|
class InterceptFailedOnStop : public nsIStreamListener
|
|
|
|
{
|
|
|
|
virtual ~InterceptFailedOnStop() {}
|
|
|
|
nsCOMPtr<nsIStreamListener> mNext;
|
|
|
|
HttpBaseChannel *mChannel;
|
|
|
|
|
|
|
|
public:
|
|
|
|
InterceptFailedOnStop(nsIStreamListener *arg, HttpBaseChannel *chan)
|
|
|
|
: mNext(arg)
|
|
|
|
, mChannel(chan) {}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnStartRequest(nsIRequest *aRequest, nsISupports *aContext) override
|
|
|
|
{
|
|
|
|
return mNext->OnStartRequest(aRequest, aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnStopRequest(nsIRequest *aRequest, nsISupports *aContext, nsresult aStatusCode) override
|
|
|
|
{
|
|
|
|
if (NS_FAILED(aStatusCode) && NS_SUCCEEDED(mChannel->mStatus)) {
|
|
|
|
LOG(("HttpBaseChannel::InterceptFailedOnStop %p seting status %x", mChannel, aStatusCode));
|
|
|
|
mChannel->mStatus = aStatusCode;
|
|
|
|
}
|
|
|
|
return mNext->OnStopRequest(aRequest, aContext, aStatusCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP OnDataAvailable(nsIRequest *aRequest, nsISupports *aContext,
|
|
|
|
nsIInputStream *aInputStream, uint64_t aOffset,
|
|
|
|
uint32_t aCount) override
|
|
|
|
{
|
|
|
|
return mNext->OnDataAvailable(aRequest, aContext, aInputStream, aOffset, aCount);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(InterceptFailedOnStop, nsIStreamListener, nsIRequestObserver)
|
|
|
|
|
2014-08-13 18:52:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener,
|
|
|
|
nsIStreamListener** aNewNextListener,
|
|
|
|
nsISupports *aCtxt)
|
2010-09-16 02:55:08 +04:00
|
|
|
{
|
2014-08-13 18:52:00 +04:00
|
|
|
*aNewNextListener = nullptr;
|
2014-09-16 14:30:00 +04:00
|
|
|
if (!mResponseHead || ! aNextListener) {
|
2010-09-16 02:55:08 +04:00
|
|
|
return NS_OK;
|
2014-09-16 14:30:00 +04:00
|
|
|
}
|
|
|
|
|
2014-08-13 18:52:00 +04:00
|
|
|
LOG(("HttpBaseChannel::DoApplyContentConversions [this=%p]\n", this));
|
2010-09-16 02:55:08 +04:00
|
|
|
|
|
|
|
if (!mApplyConversion) {
|
|
|
|
LOG(("not applying conversion per mApplyConversion\n"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contentEncoding;
|
2014-10-22 03:40:08 +04:00
|
|
|
nsresult rv = mResponseHead->GetHeader(nsHttp::Content_Encoding, contentEncoding);
|
2012-02-08 07:46:43 +04:00
|
|
|
if (NS_FAILED(rv) || contentEncoding.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
2015-10-05 21:11:26 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> nextListener = new InterceptFailedOnStop(aNextListener, this);
|
|
|
|
|
2012-02-08 07:46:43 +04:00
|
|
|
// The encodings are listed in the order they were applied
|
|
|
|
// (see rfc 2616 section 14.11), so they need to removed in reverse
|
|
|
|
// order. This is accomplished because the converter chain ends up
|
|
|
|
// being a stack with the last converter created being the first one
|
|
|
|
// to accept the raw network data.
|
|
|
|
|
2014-10-22 03:40:08 +04:00
|
|
|
char* cePtr = contentEncoding.BeginWriting();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0;
|
2014-10-22 03:40:08 +04:00
|
|
|
while (char* val = nsCRT::strtok(cePtr, HTTP_LWS ",", &cePtr)) {
|
2012-02-08 07:46:43 +04:00
|
|
|
if (++count > 16) {
|
|
|
|
// That's ridiculous. We only understand 2 different ones :)
|
|
|
|
// but for compatibility with old code, we will just carry on without
|
|
|
|
// removing the encodings
|
|
|
|
LOG(("Too many Content-Encodings. Ignoring remainder.\n"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-09-20 01:51:32 +03:00
|
|
|
bool isHTTPS = false;
|
|
|
|
mURI->SchemeIs("https", &isHTTPS);
|
|
|
|
if (gHttpHandler->IsAcceptableEncoding(val, isHTTPS)) {
|
2012-02-08 07:46:43 +04:00
|
|
|
nsCOMPtr<nsIStreamConverterService> serv;
|
|
|
|
rv = gHttpHandler->GetStreamConverterService(getter_AddRefs(serv));
|
|
|
|
|
|
|
|
// we won't fail to load the page just because we couldn't load the
|
|
|
|
// stream converter service.. carry on..
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
if (val)
|
|
|
|
LOG(("Unknown content encoding '%s', ignoring\n", val));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> converter;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString from(val);
|
2010-09-16 02:55:08 +04:00
|
|
|
ToLowerCase(from);
|
|
|
|
rv = serv->AsyncConvertData(from.get(),
|
|
|
|
"uncompressed",
|
2014-08-13 18:52:00 +04:00
|
|
|
nextListener,
|
|
|
|
aCtxt,
|
2010-09-16 02:55:08 +04:00
|
|
|
getter_AddRefs(converter));
|
2012-02-08 07:46:43 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("Unexpected failure of AsyncConvertData %s\n", val));
|
|
|
|
return rv;
|
2010-09-16 02:55:08 +04:00
|
|
|
}
|
2012-02-08 07:46:43 +04:00
|
|
|
|
|
|
|
LOG(("converter removed '%s' content-encoding\n", val));
|
2015-09-22 19:55:23 +03:00
|
|
|
if (gHttpHandler->IsTelemetryEnabled()) {
|
|
|
|
int mode = 0;
|
|
|
|
if (from.Equals("gzip") || from.Equals("x-gzip")) {
|
|
|
|
mode = 1;
|
|
|
|
} else if (from.Equals("deflate") || from.Equals("x-deflate")) {
|
|
|
|
mode = 2;
|
2015-10-06 18:03:50 +03:00
|
|
|
} else if (from.Equals("br")) {
|
2015-09-22 19:55:23 +03:00
|
|
|
mode = 3;
|
|
|
|
}
|
|
|
|
Telemetry::Accumulate(Telemetry::HTTP_CONTENT_ENCODING, mode);
|
|
|
|
}
|
2014-08-13 18:52:00 +04:00
|
|
|
nextListener = converter;
|
2012-02-08 07:46:43 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (val)
|
|
|
|
LOG(("Unknown content encoding '%s', ignoring\n", val));
|
2010-09-16 02:55:08 +04:00
|
|
|
}
|
|
|
|
}
|
2014-08-13 18:52:00 +04:00
|
|
|
*aNewNextListener = nextListener;
|
2014-09-16 14:30:00 +04:00
|
|
|
NS_IF_ADDREF(*aNewNextListener);
|
2010-09-16 02:55:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetContentEncodings(nsIUTF8StringEnumerator** aEncodings)
|
|
|
|
{
|
|
|
|
if (!mResponseHead) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aEncodings = nullptr;
|
2010-09-16 02:55:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
const char *encoding = mResponseHead->PeekHeader(nsHttp::Content_Encoding);
|
|
|
|
if (!encoding) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aEncodings = nullptr;
|
2010-09-16 02:55:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsContentEncodings* enumerator = new nsContentEncodings(this, encoding);
|
|
|
|
NS_ADDREF(*aEncodings = enumerator);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsContentEncodings <public>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
HttpBaseChannel::nsContentEncodings::nsContentEncodings(nsIHttpChannel* aChannel,
|
|
|
|
const char* aEncodingHeader)
|
|
|
|
: mEncodingHeader(aEncodingHeader)
|
|
|
|
, mChannel(aChannel)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mReady(false)
|
2010-09-16 02:55:08 +04:00
|
|
|
{
|
|
|
|
mCurEnd = aEncodingHeader + strlen(aEncodingHeader);
|
|
|
|
mCurStart = mCurEnd;
|
|
|
|
}
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
HttpBaseChannel::nsContentEncodings::~nsContentEncodings()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsContentEncodings::nsISimpleEnumerator
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::nsContentEncodings::HasMore(bool* aMoreEncodings)
|
2010-09-16 02:55:08 +04:00
|
|
|
{
|
|
|
|
if (mReady) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aMoreEncodings = true;
|
2010-09-16 02:55:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = PrepareForNext();
|
|
|
|
*aMoreEncodings = NS_SUCCEEDED(rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::nsContentEncodings::GetNext(nsACString& aNextEncoding)
|
|
|
|
{
|
|
|
|
aNextEncoding.Truncate();
|
|
|
|
if (!mReady) {
|
|
|
|
nsresult rv = PrepareForNext();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsACString & encoding = Substring(mCurStart, mCurEnd);
|
|
|
|
|
|
|
|
nsACString::const_iterator start, end;
|
|
|
|
encoding.BeginReading(start);
|
|
|
|
encoding.EndReading(end);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool haveType = false;
|
2010-09-16 02:55:08 +04:00
|
|
|
if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("gzip"), start, end)) {
|
|
|
|
aNextEncoding.AssignLiteral(APPLICATION_GZIP);
|
2011-10-17 18:59:28 +04:00
|
|
|
haveType = true;
|
2010-09-16 02:55:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!haveType) {
|
|
|
|
encoding.BeginReading(start);
|
|
|
|
if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("compress"), start, end)) {
|
|
|
|
aNextEncoding.AssignLiteral(APPLICATION_COMPRESS);
|
2011-10-17 18:59:28 +04:00
|
|
|
haveType = true;
|
2010-09-16 02:55:08 +04:00
|
|
|
}
|
|
|
|
}
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
if (!haveType) {
|
|
|
|
encoding.BeginReading(start);
|
|
|
|
if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("deflate"), start, end)) {
|
|
|
|
aNextEncoding.AssignLiteral(APPLICATION_ZIP);
|
2011-10-17 18:59:28 +04:00
|
|
|
haveType = true;
|
2010-09-16 02:55:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-22 19:55:23 +03:00
|
|
|
if (!haveType) {
|
|
|
|
encoding.BeginReading(start);
|
2015-10-06 18:03:50 +03:00
|
|
|
if (CaseInsensitiveFindInReadable(NS_LITERAL_CSTRING("br"), start, end)) {
|
2015-09-22 19:55:23 +03:00
|
|
|
aNextEncoding.AssignLiteral(APPLICATION_BROTLI);
|
|
|
|
haveType = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
// Prepare to fetch the next encoding
|
|
|
|
mCurEnd = mCurStart;
|
2011-10-17 18:59:28 +04:00
|
|
|
mReady = false;
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
if (haveType)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
NS_WARNING("Unknown encoding type");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsContentEncodings::nsISupports
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(HttpBaseChannel::nsContentEncodings, nsIUTF8StringEnumerator)
|
2010-09-16 02:55:08 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsContentEncodings <private>
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
HttpBaseChannel::nsContentEncodings::PrepareForNext(void)
|
|
|
|
{
|
2013-05-16 17:30:41 +04:00
|
|
|
MOZ_ASSERT(mCurStart == mCurEnd, "Indeterminate state");
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
// At this point both mCurStart and mCurEnd point to somewhere
|
|
|
|
// past the end of the next thing we want to return
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
while (mCurEnd != mEncodingHeader) {
|
|
|
|
--mCurEnd;
|
|
|
|
if (*mCurEnd != ',' && !nsCRT::IsAsciiSpace(*mCurEnd))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (mCurEnd == mEncodingHeader)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE; // no more encodings
|
|
|
|
++mCurEnd;
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
// At this point mCurEnd points to the first char _after_ the
|
|
|
|
// header we want. Furthermore, mCurEnd - 1 != mEncodingHeader
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
mCurStart = mCurEnd - 1;
|
|
|
|
while (mCurStart != mEncodingHeader &&
|
|
|
|
*mCurStart != ',' && !nsCRT::IsAsciiSpace(*mCurStart))
|
|
|
|
--mCurStart;
|
|
|
|
if (*mCurStart == ',' || nsCRT::IsAsciiSpace(*mCurStart))
|
|
|
|
++mCurStart; // we stopped because of a weird char, so move up one
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-09-16 02:55:08 +04:00
|
|
|
// At this point mCurStart and mCurEnd bracket the encoding string
|
|
|
|
// we want. Check that it's not "identity"
|
|
|
|
if (Substring(mCurStart, mCurEnd).Equals("identity",
|
|
|
|
nsCaseInsensitiveCStringComparator())) {
|
|
|
|
mCurEnd = mCurStart;
|
|
|
|
return PrepareForNext();
|
|
|
|
}
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mReady = true;
|
2010-09-16 02:55:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsIHttpChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-07-24 18:49:25 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetTransferSize(uint64_t *aTransferSize)
|
|
|
|
{
|
|
|
|
*aTransferSize = mTransferSize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetDecodedBodySize(uint64_t *aDecodedBodySize)
|
|
|
|
{
|
|
|
|
*aDecodedBodySize = mDecodedBodySize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetEncodedBodySize(uint64_t *aEncodedBodySize)
|
|
|
|
{
|
|
|
|
*aEncodedBodySize = mEncodedBodySize;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetRequestMethod(nsACString& aMethod)
|
|
|
|
{
|
2016-05-03 01:06:00 +03:00
|
|
|
mRequestHead.Method(aMethod);
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetRequestMethod(const nsACString& aMethod)
|
|
|
|
{
|
2012-12-04 10:24:36 +04:00
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2011-09-22 18:43:11 +04:00
|
|
|
const nsCString& flatMethod = PromiseFlatCString(aMethod);
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
// Method names are restricted to valid HTTP tokens.
|
2011-09-22 18:43:11 +04:00
|
|
|
if (!nsHttp::IsValidToken(flatMethod))
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2014-03-18 20:36:18 +04:00
|
|
|
mRequestHead.SetMethod(flatMethod);
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-07 18:45:57 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetNetworkInterfaceId(nsACString& aNetworkInterfaceId)
|
|
|
|
{
|
|
|
|
aNetworkInterfaceId = mNetworkInterfaceId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetNetworkInterfaceId(const nsACString& aNetworkInterfaceId)
|
|
|
|
{
|
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
|
|
|
mNetworkInterfaceId = aNetworkInterfaceId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetReferrer(nsIURI **referrer)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(referrer);
|
|
|
|
*referrer = mReferrer;
|
|
|
|
NS_IF_ADDREF(*referrer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetReferrer(nsIURI *referrer)
|
2014-11-18 16:46:29 +03:00
|
|
|
{
|
|
|
|
return SetReferrerWithPolicy(referrer, REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetReferrerPolicy(uint32_t *referrerPolicy)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(referrerPolicy);
|
|
|
|
*referrerPolicy = mReferrerPolicy;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetReferrerWithPolicy(nsIURI *referrer,
|
|
|
|
uint32_t referrerPolicy)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
2012-12-04 10:24:36 +04:00
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
// clear existing referrer, if any
|
2012-07-30 18:20:58 +04:00
|
|
|
mReferrer = nullptr;
|
2010-04-07 12:43:09 +04:00
|
|
|
mRequestHead.ClearHeader(nsHttp::Referer);
|
2014-11-18 16:46:29 +03:00
|
|
|
mReferrerPolicy = REFERRER_POLICY_NO_REFERRER_WHEN_DOWNGRADE;
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2014-11-18 16:46:29 +03:00
|
|
|
if (!referrer) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't send referrer at all when the meta referrer setting is "no-referrer"
|
|
|
|
if (referrerPolicy == REFERRER_POLICY_NO_REFERRER) {
|
|
|
|
mReferrerPolicy = REFERRER_POLICY_NO_REFERRER;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2013-11-16 06:46:37 +04:00
|
|
|
// 0: never send referer
|
|
|
|
// 1: send referer for direct user action
|
|
|
|
// 2: always send referer
|
|
|
|
uint32_t userReferrerLevel = gHttpHandler->ReferrerLevel();
|
|
|
|
|
|
|
|
// false: use real referrer
|
|
|
|
// true: spoof with URI of the current request
|
|
|
|
bool userSpoofReferrerSource = gHttpHandler->SpoofReferrerSource();
|
|
|
|
|
|
|
|
// 0: full URI
|
|
|
|
// 1: scheme+host+port+path
|
|
|
|
// 2: scheme+host+port
|
|
|
|
int userReferrerTrimmingPolicy = gHttpHandler->ReferrerTrimmingPolicy();
|
|
|
|
|
|
|
|
// 0: send referer no matter what
|
|
|
|
// 1: send referer ONLY when base domains match
|
|
|
|
// 2: send referer ONLY when hosts match
|
|
|
|
int userReferrerXOriginPolicy = gHttpHandler->ReferrerXOriginPolicy();
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
// check referrer blocking pref
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t referrerLevel;
|
2014-11-18 16:46:29 +03:00
|
|
|
if (mLoadFlags & LOAD_INITIAL_DOCUMENT_URI) {
|
2010-04-07 12:43:09 +04:00
|
|
|
referrerLevel = 1; // user action
|
2014-11-18 16:46:29 +03:00
|
|
|
} else {
|
2010-04-07 12:43:09 +04:00
|
|
|
referrerLevel = 2; // inline content
|
2014-11-18 16:46:29 +03:00
|
|
|
}
|
|
|
|
if (userReferrerLevel < referrerLevel) {
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
2014-11-18 16:46:29 +03:00
|
|
|
}
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> referrerGrip;
|
|
|
|
nsresult rv;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool match;
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Strip off "wyciwyg://123/" from wyciwyg referrers.
|
|
|
|
//
|
|
|
|
// XXX this really belongs elsewhere since wyciwyg URLs aren't part of necko.
|
2013-11-16 06:46:37 +04:00
|
|
|
// perhaps some sort of generic nsINestedURI could be used. then, if an URI
|
|
|
|
// fails the whitelist test, then we could check for an inner URI and try
|
|
|
|
// that instead. though, that might be too automatic.
|
2013-05-16 17:30:42 +04:00
|
|
|
//
|
2010-04-07 12:43:09 +04:00
|
|
|
rv = referrer->SchemeIs("wyciwyg", &match);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (match) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2010-04-07 12:43:09 +04:00
|
|
|
rv = referrer->GetPath(path);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t pathLength = path.Length();
|
2010-04-07 12:43:09 +04:00
|
|
|
if (pathLength <= 2) return NS_ERROR_FAILURE;
|
|
|
|
|
2013-11-16 06:46:37 +04:00
|
|
|
// Path is of the form "//123/http://foo/bar", with a variable number of
|
|
|
|
// digits. To figure out where the "real" URL starts, search path for a
|
|
|
|
// '/', starting at the third character.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t slashIndex = path.FindChar('/', 2);
|
2010-04-07 12:43:09 +04:00
|
|
|
if (slashIndex == kNotFound) return NS_ERROR_FAILURE;
|
|
|
|
|
2013-11-16 06:46:37 +04:00
|
|
|
// Get charset of the original URI so we can pass it to our fixed up URI.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString charset;
|
2010-04-07 12:43:09 +04:00
|
|
|
referrer->GetOriginCharset(charset);
|
|
|
|
|
|
|
|
// Replace |referrer| with a URI without wyciwyg://123/.
|
|
|
|
rv = NS_NewURI(getter_AddRefs(referrerGrip),
|
|
|
|
Substring(path, slashIndex + 1, pathLength - slashIndex - 1),
|
|
|
|
charset.get());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
referrer = referrerGrip.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// block referrer if not on our white list...
|
|
|
|
//
|
|
|
|
static const char *const referrerWhiteList[] = {
|
|
|
|
"http",
|
|
|
|
"https",
|
|
|
|
"ftp",
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2010-04-07 12:43:09 +04:00
|
|
|
};
|
2011-10-17 18:59:28 +04:00
|
|
|
match = false;
|
2010-04-07 12:43:09 +04:00
|
|
|
const char *const *scheme = referrerWhiteList;
|
|
|
|
for (; *scheme && !match; ++scheme) {
|
|
|
|
rv = referrer->SchemeIs(*scheme, &match);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2014-11-18 16:46:29 +03:00
|
|
|
if (!match) return NS_OK; // kick out....
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// Handle secure referrals.
|
|
|
|
//
|
|
|
|
// Support referrals from a secure server if this is a secure site
|
|
|
|
// and (optionally) if the host names are the same.
|
|
|
|
//
|
|
|
|
rv = referrer->SchemeIs("https", &match);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2014-11-18 16:46:29 +03:00
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
if (match) {
|
|
|
|
rv = mURI->SchemeIs("https", &match);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2014-11-18 16:46:29 +03:00
|
|
|
// It's ok to send referrer for https-to-http scenarios if the referrer
|
2015-05-12 02:18:05 +03:00
|
|
|
// policy is "unsafe-url", "origin", or "origin-when-cross-origin".
|
2014-11-18 16:46:29 +03:00
|
|
|
if (referrerPolicy != REFERRER_POLICY_UNSAFE_URL &&
|
2015-01-08 03:46:00 +03:00
|
|
|
referrerPolicy != REFERRER_POLICY_ORIGIN_WHEN_XORIGIN &&
|
2014-11-18 16:46:29 +03:00
|
|
|
referrerPolicy != REFERRER_POLICY_ORIGIN) {
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2014-11-18 16:46:29 +03:00
|
|
|
// in other referrer policies, https->http is not allowed...
|
|
|
|
if (!match) return NS_OK;
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2014-11-18 16:46:29 +03:00
|
|
|
// ...and https->https is possibly only allowed if the hosts match.
|
|
|
|
if (!gHttpHandler->SendSecureXSiteReferrer()) {
|
|
|
|
nsAutoCString referrerHost;
|
|
|
|
nsAutoCString host;
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2014-11-18 16:46:29 +03:00
|
|
|
rv = referrer->GetAsciiHost(referrerHost);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mURI->GetAsciiHost(host);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// GetAsciiHost returns lowercase hostname.
|
|
|
|
if (!referrerHost.Equals(host))
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-04-07 12:43:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-18 16:46:29 +03:00
|
|
|
// for cross-origin-based referrer changes (not just host-based), figure out
|
|
|
|
// if the referrer is being sent cross-origin.
|
2015-01-08 03:46:00 +03:00
|
|
|
nsCOMPtr<nsIURI> triggeringURI;
|
2014-11-18 16:46:29 +03:00
|
|
|
bool isCrossOrigin = true;
|
|
|
|
if (mLoadInfo) {
|
2015-01-08 03:46:00 +03:00
|
|
|
mLoadInfo->TriggeringPrincipal()->GetURI(getter_AddRefs(triggeringURI));
|
2014-11-18 16:46:29 +03:00
|
|
|
}
|
2015-01-08 03:46:00 +03:00
|
|
|
if (triggeringURI) {
|
|
|
|
if (LOG_ENABLED()) {
|
|
|
|
nsAutoCString triggeringURISpec;
|
|
|
|
rv = triggeringURI->GetAsciiSpec(triggeringURISpec);
|
|
|
|
if (!NS_FAILED(rv)) {
|
|
|
|
LOG(("triggeringURI=%s\n", triggeringURISpec.get()));
|
|
|
|
}
|
|
|
|
}
|
2014-11-18 16:46:29 +03:00
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
2015-01-08 03:46:00 +03:00
|
|
|
rv = ssm->CheckSameOriginURI(triggeringURI, mURI, false);
|
2014-11-18 16:46:29 +03:00
|
|
|
isCrossOrigin = NS_FAILED(rv);
|
|
|
|
} else {
|
2015-01-08 03:46:00 +03:00
|
|
|
NS_WARNING("no triggering principal available via loadInfo, assuming load is cross-origin");
|
2014-11-18 16:46:29 +03:00
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
nsCOMPtr<nsIURI> clone;
|
|
|
|
//
|
|
|
|
// we need to clone the referrer, so we can:
|
|
|
|
// (1) modify it
|
|
|
|
// (2) keep a reference to it after returning from this function
|
|
|
|
//
|
2011-05-22 05:12:46 +04:00
|
|
|
// Use CloneIgnoringRef to strip away any fragment per RFC 2616 section 14.36
|
2014-11-18 16:46:29 +03:00
|
|
|
// and Referrer Policy section 6.3.5.
|
2011-05-22 05:12:46 +04:00
|
|
|
rv = referrer->CloneIgnoringRef(getter_AddRefs(clone));
|
2010-04-07 12:43:09 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2013-11-16 06:46:37 +04:00
|
|
|
nsAutoCString currentHost;
|
|
|
|
nsAutoCString referrerHost;
|
|
|
|
|
|
|
|
rv = mURI->GetAsciiHost(currentHost);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = clone->GetAsciiHost(referrerHost);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// check policy for sending ref only when hosts match
|
|
|
|
if (userReferrerXOriginPolicy == 2 && !currentHost.Equals(referrerHost))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (userReferrerXOriginPolicy == 1) {
|
|
|
|
nsAutoCString currentDomain = currentHost;
|
|
|
|
nsAutoCString referrerDomain = referrerHost;
|
|
|
|
uint32_t extraDomains = 0;
|
|
|
|
nsCOMPtr<nsIEffectiveTLDService> eTLDService = do_GetService(
|
|
|
|
NS_EFFECTIVETLDSERVICE_CONTRACTID);
|
|
|
|
if (eTLDService) {
|
|
|
|
rv = eTLDService->GetBaseDomain(mURI, extraDomains, currentDomain);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2015-12-08 11:27:00 +03:00
|
|
|
rv = eTLDService->GetBaseDomain(clone, extraDomains, referrerDomain);
|
2013-11-16 06:46:37 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check policy for sending only when effective top level domain matches.
|
|
|
|
// this falls back on using host if eTLDService does not work
|
|
|
|
if (!currentDomain.Equals(referrerDomain))
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// send spoofed referrer if desired
|
|
|
|
if (userSpoofReferrerSource) {
|
|
|
|
nsCOMPtr<nsIURI> mURIclone;
|
|
|
|
rv = mURI->CloneIgnoringRef(getter_AddRefs(mURIclone));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
clone = mURIclone;
|
|
|
|
currentHost = referrerHost;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
// strip away any userpass; we don't want to be giving out passwords ;-)
|
2014-11-18 16:46:29 +03:00
|
|
|
// This is required by Referrer Policy stripping algorithm.
|
2011-05-22 05:12:46 +04:00
|
|
|
rv = clone->SetUserPass(EmptyCString());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2013-11-16 06:46:37 +04:00
|
|
|
|
2014-11-18 16:46:29 +03:00
|
|
|
// site-specified referrer trimming may affect the trim level
|
|
|
|
// "unsafe-url" behaves like "origin" (send referrer in the same situations) but
|
|
|
|
// "unsafe-url" sends the whole referrer and origin removes the path.
|
|
|
|
// "origin-when-cross-origin" trims the referrer only when the request is
|
|
|
|
// cross-origin.
|
|
|
|
if (referrerPolicy == REFERRER_POLICY_ORIGIN ||
|
|
|
|
(isCrossOrigin && referrerPolicy == REFERRER_POLICY_ORIGIN_WHEN_XORIGIN)) {
|
|
|
|
userReferrerTrimmingPolicy = 2;
|
|
|
|
}
|
|
|
|
|
2013-11-16 06:46:37 +04:00
|
|
|
// check how much referer to send
|
|
|
|
switch (userReferrerTrimmingPolicy) {
|
|
|
|
|
|
|
|
case 1: {
|
|
|
|
// scheme+host+port+path
|
|
|
|
nsAutoCString prepath, path;
|
|
|
|
rv = clone->GetPrePath(prepath);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURL> url(do_QueryInterface(clone));
|
|
|
|
if (!url) {
|
|
|
|
// if this isn't a url, play it safe
|
|
|
|
// and just send the prepath
|
|
|
|
spec = prepath;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rv = url->GetFilePath(path);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
spec = prepath + path;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
2016-02-24 12:51:54 +03:00
|
|
|
// scheme+host+port+/
|
2013-11-16 06:46:37 +04:00
|
|
|
rv = clone->GetPrePath(spec);
|
2016-02-24 12:51:54 +03:00
|
|
|
spec.AppendLiteral("/");
|
2013-11-16 06:46:37 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// full URI
|
|
|
|
rv = clone->GetAsciiSpec(spec);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
break;
|
|
|
|
}
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2016-02-29 22:50:20 +03:00
|
|
|
// If any user trimming policy is in effect, use the trimmed URI.
|
|
|
|
if (userReferrerTrimmingPolicy) {
|
|
|
|
rv = NS_NewURI(getter_AddRefs(clone), spec);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
// finally, remember the referrer URI and set the Referer header.
|
2014-11-18 16:46:29 +03:00
|
|
|
rv = SetRequestHeader(NS_LITERAL_CSTRING("Referer"), spec, false);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
mReferrer = clone;
|
2014-11-18 16:46:29 +03:00
|
|
|
mReferrerPolicy = referrerPolicy;
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-21 23:13:00 +03:00
|
|
|
// Return the channel's proxy URI, or if it doesn't exist, the
|
|
|
|
// channel's main URI.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetProxyURI(nsIURI **aOut)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOut);
|
|
|
|
nsCOMPtr<nsIURI> result(mProxyURI);
|
|
|
|
result.forget(aOut);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetRequestHeader(const nsACString& aHeader,
|
|
|
|
nsACString& aValue)
|
|
|
|
{
|
2015-09-03 03:59:43 +03:00
|
|
|
aValue.Truncate();
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
// XXX might be better to search the header list directly instead of
|
|
|
|
// hitting the http atom hash table.
|
|
|
|
nsHttpAtom atom = nsHttp::ResolveAtom(aHeader);
|
|
|
|
if (!atom)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
return mRequestHead.GetHeader(atom, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetRequestHeader(const nsACString& aHeader,
|
|
|
|
const nsACString& aValue,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aMerge)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
const nsCString &flatHeader = PromiseFlatCString(aHeader);
|
|
|
|
const nsCString &flatValue = PromiseFlatCString(aValue);
|
|
|
|
|
|
|
|
LOG(("HttpBaseChannel::SetRequestHeader [this=%p header=\"%s\" value=\"%s\" merge=%u]\n",
|
|
|
|
this, flatHeader.get(), flatValue.get(), aMerge));
|
|
|
|
|
2014-07-24 20:38:55 +04:00
|
|
|
// Verify header names are valid HTTP tokens and header values are reasonably
|
|
|
|
// close to whats allowed in RFC 2616.
|
|
|
|
if (!nsHttp::IsValidToken(flatHeader) ||
|
|
|
|
!nsHttp::IsReasonableHeaderValue(flatValue)) {
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2014-07-24 20:38:55 +04:00
|
|
|
}
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
nsHttpAtom atom = nsHttp::ResolveAtom(flatHeader.get());
|
|
|
|
if (!atom) {
|
|
|
|
NS_WARNING("failed to resolve atom");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mRequestHead.SetHeader(atom, flatValue, aMerge);
|
|
|
|
}
|
|
|
|
|
2015-08-27 16:38:44 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetEmptyRequestHeader(const nsACString& aHeader)
|
|
|
|
{
|
|
|
|
const nsCString &flatHeader = PromiseFlatCString(aHeader);
|
|
|
|
|
|
|
|
LOG(("HttpBaseChannel::SetEmptyRequestHeader [this=%p header=\"%s\"]\n",
|
|
|
|
this, flatHeader.get()));
|
|
|
|
|
|
|
|
// Verify header names are valid HTTP tokens and header values are reasonably
|
|
|
|
// close to whats allowed in RFC 2616.
|
|
|
|
if (!nsHttp::IsValidToken(flatHeader)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpAtom atom = nsHttp::ResolveAtom(flatHeader.get());
|
|
|
|
if (!atom) {
|
|
|
|
NS_WARNING("failed to resolve atom");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mRequestHead.SetEmptyHeader(atom);
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::VisitRequestHeaders(nsIHttpHeaderVisitor *visitor)
|
|
|
|
{
|
2016-05-03 01:06:00 +03:00
|
|
|
return mRequestHead.VisitHeaders(visitor);
|
2010-04-07 12:43:09 +04:00
|
|
|
}
|
|
|
|
|
2015-09-04 01:17:23 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::VisitNonDefaultRequestHeaders(nsIHttpHeaderVisitor *visitor)
|
|
|
|
{
|
2016-05-03 01:06:00 +03:00
|
|
|
return mRequestHead.VisitHeaders(visitor,
|
|
|
|
nsHttpHeaderArray::eFilterSkipDefault);
|
2015-09-04 01:17:23 +03:00
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetResponseHeader(const nsACString &header, nsACString &value)
|
|
|
|
{
|
2015-09-03 03:59:43 +03:00
|
|
|
value.Truncate();
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
nsHttpAtom atom = nsHttp::ResolveAtom(header);
|
|
|
|
if (!atom)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
return mResponseHead->GetHeader(atom, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-05-16 17:30:42 +04:00
|
|
|
HttpBaseChannel::SetResponseHeader(const nsACString& header,
|
|
|
|
const nsACString& value,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool merge)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
LOG(("HttpBaseChannel::SetResponseHeader [this=%p header=\"%s\" value=\"%s\" merge=%u]\n",
|
|
|
|
this, PromiseFlatCString(header).get(), PromiseFlatCString(value).get(), merge));
|
|
|
|
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
nsHttpAtom atom = nsHttp::ResolveAtom(header);
|
|
|
|
if (!atom)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2013-05-16 17:30:42 +04:00
|
|
|
// these response headers must not be changed
|
2010-04-07 12:43:09 +04:00
|
|
|
if (atom == nsHttp::Content_Type ||
|
|
|
|
atom == nsHttp::Content_Length ||
|
|
|
|
atom == nsHttp::Content_Encoding ||
|
|
|
|
atom == nsHttp::Trailer ||
|
|
|
|
atom == nsHttp::Transfer_Encoding)
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mResponseHeadersModified = true;
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
return mResponseHead->SetHeader(atom, value, merge);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::VisitResponseHeaders(nsIHttpHeaderVisitor *visitor)
|
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
return mResponseHead->Headers().VisitHeaders(visitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::GetAllowPipelining(bool *value)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(value);
|
|
|
|
*value = mAllowPipelining;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::SetAllowPipelining(bool value)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
2012-12-04 10:24:36 +04:00
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
mAllowPipelining = value;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-06-04 20:57:15 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetAllowSTS(bool *value)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(value);
|
|
|
|
*value = mAllowSTS;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetAllowSTS(bool value)
|
|
|
|
{
|
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
|
|
|
|
|
|
|
mAllowSTS = value;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::GetRedirectionLimit(uint32_t *value)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(value);
|
|
|
|
*value = mRedirectionLimit;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::SetRedirectionLimit(uint32_t value)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
2012-12-04 10:24:36 +04:00
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2013-01-15 16:22:03 +04:00
|
|
|
mRedirectionLimit = std::min<uint32_t>(value, 0xff);
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-05 02:27:33 +03:00
|
|
|
nsresult
|
|
|
|
HttpBaseChannel::OverrideSecurityInfo(nsISupports* aSecurityInfo)
|
|
|
|
{
|
2015-06-17 14:16:33 +03:00
|
|
|
MOZ_ASSERT(!mSecurityInfo,
|
|
|
|
"This can only be called when we don't have a security info object already");
|
2015-03-05 02:27:33 +03:00
|
|
|
MOZ_RELEASE_ASSERT(aSecurityInfo,
|
|
|
|
"This can only be called with a valid security info object");
|
2015-10-06 16:37:06 +03:00
|
|
|
MOZ_ASSERT(!BypassServiceWorker(),
|
|
|
|
"This can only be called on channels that are not bypassing interception");
|
2015-08-17 23:18:41 +03:00
|
|
|
MOZ_ASSERT(mResponseCouldBeSynthesized,
|
2015-06-17 14:16:33 +03:00
|
|
|
"This can only be called on channels that can be intercepted");
|
|
|
|
if (mSecurityInfo) {
|
|
|
|
LOG(("HttpBaseChannel::OverrideSecurityInfo mSecurityInfo is null! "
|
|
|
|
"[this=%p]\n", this));
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2015-08-17 23:18:41 +03:00
|
|
|
if (!mResponseCouldBeSynthesized) {
|
2015-06-17 14:16:33 +03:00
|
|
|
LOG(("HttpBaseChannel::OverrideSecurityInfo channel cannot be intercepted! "
|
|
|
|
"[this=%p]\n", this));
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2015-03-05 02:27:33 +03:00
|
|
|
mSecurityInfo = aSecurityInfo;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::IsNoStoreResponse(bool *value)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
*value = mResponseHead->NoStore();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::IsNoCacheResponse(bool *value)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
*value = mResponseHead->NoCache();
|
|
|
|
if (!*value)
|
|
|
|
*value = mResponseHead->ExpiresInPast();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-01-09 00:38:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::IsPrivateResponse(bool *value)
|
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
*value = mResponseHead->Private();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::GetResponseStatus(uint32_t *aValue)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
*aValue = mResponseHead->Status();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetResponseStatusText(nsACString& aValue)
|
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
aValue = mResponseHead->StatusText();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::GetRequestSucceeded(bool *aValue)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t status = mResponseHead->Status();
|
2010-04-07 12:43:09 +04:00
|
|
|
*aValue = (status / 100 == 2);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-12 03:46:00 +04:00
|
|
|
NS_IMETHODIMP
|
2016-02-05 09:45:00 +03:00
|
|
|
HttpBaseChannel::RedirectTo(nsIURI *targetURI)
|
2013-01-12 03:46:00 +04:00
|
|
|
{
|
2016-02-05 09:45:00 +03:00
|
|
|
// We cannot redirect after OnStartRequest of the listener
|
|
|
|
// has been called, since to redirect we have to switch channels
|
|
|
|
// and the dance with OnStartRequest et al has to start over.
|
|
|
|
// This would break the nsIStreamListener contract.
|
|
|
|
NS_ENSURE_FALSE(mOnStartRequestCalled, NS_ERROR_NOT_AVAILABLE);
|
2013-01-12 03:46:00 +04:00
|
|
|
|
2016-02-05 09:45:00 +03:00
|
|
|
mAPIRedirectToURI = targetURI;
|
2013-01-12 03:46:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-31 23:50:08 +03:00
|
|
|
NS_IMETHODIMP
|
2016-04-21 17:59:17 +03:00
|
|
|
HttpBaseChannel::GetRequestContextID(nsID *aRCID)
|
2015-07-31 23:50:08 +03:00
|
|
|
{
|
2016-04-21 17:59:17 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aRCID);
|
|
|
|
*aRCID = mRequestContextID;
|
2015-07-31 23:50:08 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-04-21 17:59:17 +03:00
|
|
|
HttpBaseChannel::SetRequestContextID(const nsID aRCID)
|
2015-07-31 23:50:08 +03:00
|
|
|
{
|
2016-04-21 17:59:17 +03:00
|
|
|
mRequestContextID = aRCID;
|
2015-07-31 23:50:08 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-05 16:46:24 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetIsMainDocumentChannel(bool* aValue)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aValue);
|
|
|
|
*aValue = mForceMainDocumentChannel || (mLoadFlags & LOAD_DOCUMENT_URI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetIsMainDocumentChannel(bool aValue)
|
|
|
|
{
|
|
|
|
mForceMainDocumentChannel = aValue;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-24 18:49:25 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetProtocolVersion(nsACString& aProtocolVersion)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISSLSocketControl> ssl = do_QueryInterface(mSecurityInfo, &rv);
|
|
|
|
nsAutoCString protocol;
|
|
|
|
if (NS_SUCCEEDED(rv) && ssl &&
|
|
|
|
NS_SUCCEEDED(ssl->GetNegotiatedNPN(protocol)) &&
|
|
|
|
!protocol.IsEmpty()) {
|
|
|
|
// The negotiated protocol was not empty so we can use it.
|
|
|
|
aProtocolVersion = protocol;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mResponseHead) {
|
|
|
|
uint32_t version = mResponseHead->Version();
|
|
|
|
aProtocolVersion.Assign(nsHttp::GetProtocolVersion(version));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsIHttpChannelInternal
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-10-30 03:22:22 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetTopWindowURI(nsIURI **aTopWindowURI)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<mozIThirdPartyUtil> util;
|
|
|
|
// Only compute the top window URI once. In e10s, this must be computed in the
|
|
|
|
// child. The parent gets the top window URI through HttpChannelOpenArgs.
|
|
|
|
if (!mTopWindowURI) {
|
|
|
|
util = do_GetService(THIRDPARTYUTIL_CONTRACTID);
|
|
|
|
if (!util) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> win;
|
2014-10-30 03:22:22 +03:00
|
|
|
nsresult rv = util->GetTopWindowForChannel(this, getter_AddRefs(win));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = util->GetURIFromWindow(win, getter_AddRefs(mTopWindowURI));
|
|
|
|
#if DEBUG
|
|
|
|
if (mTopWindowURI) {
|
|
|
|
nsCString spec;
|
|
|
|
rv = mTopWindowURI->GetSpec(spec);
|
|
|
|
LOG(("HttpChannelBase::Setting topwindow URI spec %s [this=%p]\n",
|
|
|
|
spec.get(), this));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_IF_ADDREF(*aTopWindowURI = mTopWindowURI);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetDocumentURI(nsIURI **aDocumentURI)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aDocumentURI);
|
|
|
|
*aDocumentURI = mDocumentURI;
|
|
|
|
NS_IF_ADDREF(*aDocumentURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetDocumentURI(nsIURI *aDocumentURI)
|
|
|
|
{
|
2012-12-04 10:24:36 +04:00
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
2010-04-07 12:43:09 +04:00
|
|
|
|
|
|
|
mDocumentURI = aDocumentURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::GetRequestVersion(uint32_t *major, uint32_t *minor)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
nsHttpVersion version = mRequestHead.Version();
|
|
|
|
|
|
|
|
if (major) { *major = version / 10; }
|
|
|
|
if (minor) { *minor = version % 10; }
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::GetResponseVersion(uint32_t *major, uint32_t *minor)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
{
|
|
|
|
*major = *minor = 0; // we should at least be kind about it
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpVersion version = mResponseHead->Version();
|
|
|
|
|
|
|
|
if (major) { *major = version / 10; }
|
|
|
|
if (minor) { *minor = version % 10; }
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-26 22:44:42 +04:00
|
|
|
namespace {
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class CookieNotifierRunnable : public Runnable
|
2014-02-26 22:44:42 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CookieNotifierRunnable(HttpBaseChannel* aChannel, char const * aCookie)
|
2015-11-19 12:30:23 +03:00
|
|
|
: mChannel(aChannel)
|
|
|
|
{
|
|
|
|
CopyASCIItoUTF16(aCookie, mCookie);
|
|
|
|
}
|
2014-02-26 22:44:42 +04:00
|
|
|
|
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(static_cast<nsIChannel*>(mChannel.get()),
|
|
|
|
"http-on-response-set-cookie",
|
|
|
|
mCookie.get());
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<HttpBaseChannel> mChannel;
|
2015-11-19 12:30:23 +03:00
|
|
|
nsString mCookie;
|
2014-02-26 22:44:42 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2014-02-26 22:44:42 +04:00
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetCookie(const char *aCookieHeader)
|
|
|
|
{
|
|
|
|
if (mLoadFlags & LOAD_ANONYMOUS)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// empty header isn't an error
|
|
|
|
if (!(aCookieHeader && *aCookieHeader))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsICookieService *cs = gHttpHandler->GetCookieService();
|
|
|
|
NS_ENSURE_TRUE(cs, NS_ERROR_FAILURE);
|
|
|
|
|
2014-02-26 22:44:42 +04:00
|
|
|
nsresult rv =
|
|
|
|
cs->SetCookieStringFromHttp(mURI, nullptr, nullptr, aCookieHeader,
|
|
|
|
mResponseHead->PeekHeader(nsHttp::Date), this);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<CookieNotifierRunnable> r =
|
2014-02-26 22:44:42 +04:00
|
|
|
new CookieNotifierRunnable(this, aCookieHeader);
|
|
|
|
NS_DispatchToMainThread(r);
|
|
|
|
}
|
|
|
|
return rv;
|
2010-04-07 12:43:09 +04:00
|
|
|
}
|
|
|
|
|
2014-10-28 16:23:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetThirdPartyFlags(uint32_t *aFlags)
|
|
|
|
{
|
|
|
|
*aFlags = mThirdPartyFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetThirdPartyFlags(uint32_t aFlags)
|
|
|
|
{
|
|
|
|
ENSURE_CALLED_BEFORE_ASYNC_OPEN();
|
|
|
|
|
|
|
|
mThirdPartyFlags = aFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::GetForceAllowThirdPartyCookie(bool *aForce)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
2014-10-28 16:23:00 +03:00
|
|
|
*aForce = !!(mThirdPartyFlags & nsIHttpChannelInternal::THIRD_PARTY_FORCE_ALLOW);
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::SetForceAllowThirdPartyCookie(bool aForce)
|
2010-04-07 12:43:09 +04:00
|
|
|
{
|
|
|
|
ENSURE_CALLED_BEFORE_ASYNC_OPEN();
|
|
|
|
|
2014-10-28 16:23:00 +03:00
|
|
|
if (aForce)
|
|
|
|
mThirdPartyFlags |= nsIHttpChannelInternal::THIRD_PARTY_FORCE_ALLOW;
|
|
|
|
else
|
|
|
|
mThirdPartyFlags &= ~nsIHttpChannelInternal::THIRD_PARTY_FORCE_ALLOW;
|
|
|
|
|
2010-04-07 12:43:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-28 22:33:06 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::GetCanceled(bool *aCanceled)
|
2010-07-28 22:33:06 +04:00
|
|
|
{
|
|
|
|
*aCanceled = mCanceled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-10 09:22:24 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::GetChannelIsForDownload(bool *aChannelIsForDownload)
|
2010-09-10 09:22:24 +04:00
|
|
|
{
|
|
|
|
*aChannelIsForDownload = mChannelIsForDownload;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
HttpBaseChannel::SetChannelIsForDownload(bool aChannelIsForDownload)
|
2010-09-10 09:22:24 +04:00
|
|
|
{
|
|
|
|
mChannelIsForDownload = aChannelIsForDownload;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-24 06:36:53 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetCacheKeysRedirectChain(nsTArray<nsCString> *cacheKeys)
|
|
|
|
{
|
|
|
|
mRedirectedCachekeys = cacheKeys;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-05 19:45:59 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetLocalAddress(nsACString& addr)
|
|
|
|
{
|
|
|
|
if (mSelfAddr.raw.family == PR_AF_UNSPEC)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2012-12-24 01:08:43 +04:00
|
|
|
addr.SetCapacity(kIPv6CStrBufSize);
|
|
|
|
NetAddrToString(&mSelfAddr, addr.BeginWriting(), kIPv6CStrBufSize);
|
2011-05-05 19:45:59 +04:00
|
|
|
addr.SetLength(strlen(addr.BeginReading()));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-07-26 19:37:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::TakeAllSecurityMessages(
|
|
|
|
nsCOMArray<nsISecurityConsoleMessage> &aMessages)
|
|
|
|
{
|
|
|
|
aMessages.Clear();
|
|
|
|
aMessages.SwapElements(mSecurityConsoleMessages);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Please use this method with care. This can cause the message
|
|
|
|
* queue to grow large and cause the channel to take up a lot
|
|
|
|
* of memory. Use only static string messages and do not add
|
|
|
|
* server side data to the queue, as that can be large.
|
|
|
|
* Add only a limited number of messages to the queue to keep
|
|
|
|
* the channel size down and do so only in rare erroneous situations.
|
|
|
|
* More information can be found here:
|
|
|
|
* https://bugzilla.mozilla.org/show_bug.cgi?id=846918
|
|
|
|
*/
|
2015-01-02 17:28:37 +03:00
|
|
|
nsresult
|
2013-07-26 19:37:03 +04:00
|
|
|
HttpBaseChannel::AddSecurityMessage(const nsAString &aMessageTag,
|
|
|
|
const nsAString &aMessageCategory)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsISecurityConsoleMessage> message =
|
|
|
|
do_CreateInstance(NS_SECURITY_CONSOLE_MESSAGE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
message->SetTag(aMessageTag);
|
|
|
|
message->SetCategory(aMessageCategory);
|
|
|
|
mSecurityConsoleMessages.AppendElement(message);
|
2015-02-09 15:04:00 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (!console) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
GetLoadInfo(getter_AddRefs(loadInfo));
|
|
|
|
if (!loadInfo) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t innerWindowID = loadInfo->GetInnerWindowID();
|
|
|
|
|
|
|
|
nsXPIDLString errorText;
|
|
|
|
rv = nsContentUtils::GetLocalizedString(
|
|
|
|
nsContentUtils::eSECURITY_PROPERTIES,
|
|
|
|
NS_ConvertUTF16toUTF8(aMessageTag).get(),
|
|
|
|
errorText);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoCString spec;
|
|
|
|
if (mURI) {
|
|
|
|
mURI->GetSpec(spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
|
|
|
error->InitWithWindowID(errorText, NS_ConvertUTF8toUTF16(spec),
|
|
|
|
EmptyString(), 0, 0, nsIScriptError::warningFlag,
|
|
|
|
NS_ConvertUTF16toUTF8(aMessageCategory),
|
|
|
|
innerWindowID);
|
|
|
|
console->LogMessage(error);
|
|
|
|
|
2013-07-26 19:37:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-05 19:45:59 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::GetLocalPort(int32_t* port)
|
2011-05-05 19:45:59 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(port);
|
|
|
|
|
|
|
|
if (mSelfAddr.raw.family == PR_AF_INET) {
|
2012-12-24 01:08:43 +04:00
|
|
|
*port = (int32_t)ntohs(mSelfAddr.inet.port);
|
2011-05-05 19:45:59 +04:00
|
|
|
}
|
|
|
|
else if (mSelfAddr.raw.family == PR_AF_INET6) {
|
2012-12-24 01:08:43 +04:00
|
|
|
*port = (int32_t)ntohs(mSelfAddr.inet6.port);
|
2011-05-05 19:45:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetRemoteAddress(nsACString& addr)
|
|
|
|
{
|
|
|
|
if (mPeerAddr.raw.family == PR_AF_UNSPEC)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2012-12-24 01:08:43 +04:00
|
|
|
addr.SetCapacity(kIPv6CStrBufSize);
|
|
|
|
NetAddrToString(&mPeerAddr, addr.BeginWriting(), kIPv6CStrBufSize);
|
2011-05-05 19:45:59 +04:00
|
|
|
addr.SetLength(strlen(addr.BeginReading()));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::GetRemotePort(int32_t* port)
|
2011-05-05 19:45:59 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(port);
|
|
|
|
|
|
|
|
if (mPeerAddr.raw.family == PR_AF_INET) {
|
2012-12-24 01:08:43 +04:00
|
|
|
*port = (int32_t)ntohs(mPeerAddr.inet.port);
|
2011-05-05 19:45:59 +04:00
|
|
|
}
|
|
|
|
else if (mPeerAddr.raw.family == PR_AF_INET6) {
|
2012-12-24 01:08:43 +04:00
|
|
|
*port = (int32_t)ntohs(mPeerAddr.inet6.port);
|
2011-05-05 19:45:59 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-20 03:43:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::HTTPUpgrade(const nsACString &aProtocolName,
|
|
|
|
nsIHttpUpgradeListener *aListener)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(!aProtocolName.IsEmpty());
|
|
|
|
NS_ENSURE_ARG_POINTER(aListener);
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2011-05-20 03:43:37 +04:00
|
|
|
mUpgradeProtocol = aProtocolName;
|
|
|
|
mUpgradeProtocolCallback = aListener;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-13 19:55:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetAllowSpdy(bool *aAllowSpdy)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAllowSpdy);
|
|
|
|
|
|
|
|
*aAllowSpdy = mAllowSpdy;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetAllowSpdy(bool aAllowSpdy)
|
|
|
|
{
|
|
|
|
mAllowSpdy = aAllowSpdy;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-04-13 19:59:34 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetAllowAltSvc(bool *aAllowAltSvc)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aAllowAltSvc);
|
|
|
|
|
|
|
|
*aAllowAltSvc = mAllowAltSvc;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetAllowAltSvc(bool aAllowAltSvc)
|
|
|
|
{
|
|
|
|
mAllowAltSvc = aAllowAltSvc;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-12-05 16:09:11 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetApiRedirectToURI(nsIURI ** aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_IF_ADDREF(*aResult = mAPIRedirectToURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-12-19 03:03:48 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetResponseTimeoutEnabled(bool *aEnable)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!aEnable)) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aEnable = mResponseTimeoutEnabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetResponseTimeoutEnabled(bool aEnable)
|
|
|
|
{
|
|
|
|
mResponseTimeoutEnabled = aEnable;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-11 22:53:27 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetInitialRwin(uint32_t *aRwin)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!aRwin)) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aRwin = mInitialRwin;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetInitialRwin(uint32_t aRwin)
|
|
|
|
{
|
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
|
|
|
mInitialRwin = aRwin;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-06-27 05:51:49 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::ForcePending(bool aForcePending)
|
|
|
|
{
|
|
|
|
mForcePending = aForcePending;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-10 18:13:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetLastModifiedTime(PRTime* lastModifiedTime)
|
|
|
|
{
|
|
|
|
if (!mResponseHead)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
uint32_t lastMod;
|
|
|
|
mResponseHead->GetLastModifiedValue(&lastMod);
|
|
|
|
*lastModifiedTime = lastMod;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-03-17 18:47:02 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetCorsIncludeCredentials(bool* aInclude)
|
|
|
|
{
|
|
|
|
*aInclude = mCorsIncludeCredentials;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetCorsIncludeCredentials(bool aInclude)
|
|
|
|
{
|
|
|
|
mCorsIncludeCredentials = aInclude;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetCorsMode(uint32_t* aMode)
|
|
|
|
{
|
|
|
|
*aMode = mCorsMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetCorsMode(uint32_t aMode)
|
|
|
|
{
|
|
|
|
mCorsMode = aMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-01 00:26:29 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetRedirectMode(uint32_t* aMode)
|
|
|
|
{
|
|
|
|
*aMode = mRedirectMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetRedirectMode(uint32_t aMode)
|
|
|
|
{
|
|
|
|
mRedirectMode = aMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-02-29 00:34:01 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetFetchCacheMode(uint32_t* aFetchCacheMode)
|
|
|
|
{
|
2016-04-15 21:15:58 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(aFetchCacheMode);
|
|
|
|
|
|
|
|
// If the fetch cache mode is overriden, then use it directly.
|
|
|
|
if (mFetchCacheMode != nsIHttpChannelInternal::FETCH_CACHE_MODE_DEFAULT) {
|
|
|
|
*aFetchCacheMode = mFetchCacheMode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise try to guess an appropriate cache mode from the load flags.
|
|
|
|
if (mLoadFlags & (INHIBIT_CACHING | LOAD_BYPASS_CACHE)) {
|
|
|
|
*aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_NO_STORE;
|
|
|
|
} else if (mLoadFlags & LOAD_BYPASS_CACHE) {
|
|
|
|
*aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_RELOAD;
|
|
|
|
} else if (mLoadFlags & VALIDATE_ALWAYS) {
|
|
|
|
*aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_NO_CACHE;
|
|
|
|
} else if (mLoadFlags & LOAD_FROM_CACHE) {
|
|
|
|
*aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_FORCE_CACHE;
|
|
|
|
} else {
|
|
|
|
*aFetchCacheMode = nsIHttpChannelInternal::FETCH_CACHE_MODE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2016-02-29 00:34:01 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetFetchCacheMode(uint32_t aFetchCacheMode)
|
|
|
|
{
|
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
|
|
|
MOZ_ASSERT(mFetchCacheMode == nsIHttpChannelInternal::FETCH_CACHE_MODE_DEFAULT,
|
|
|
|
"SetFetchCacheMode() should only be called once per channel");
|
|
|
|
|
|
|
|
mFetchCacheMode = aFetchCacheMode;
|
|
|
|
|
|
|
|
// Now, set the load flags that implement each cache mode.
|
|
|
|
switch (mFetchCacheMode) {
|
|
|
|
case nsIHttpChannelInternal::FETCH_CACHE_MODE_NO_STORE:
|
|
|
|
// no-store means don't consult the cache on the way to the network, and
|
|
|
|
// don't store the response in the cache even if it's cacheable.
|
|
|
|
mLoadFlags |= INHIBIT_CACHING | LOAD_BYPASS_CACHE;
|
|
|
|
break;
|
|
|
|
case nsIHttpChannelInternal::FETCH_CACHE_MODE_RELOAD:
|
|
|
|
// reload means don't consult the cache on the way to the network, but
|
|
|
|
// do store the response in the cache if possible.
|
|
|
|
mLoadFlags |= LOAD_BYPASS_CACHE;
|
|
|
|
break;
|
|
|
|
case nsIHttpChannelInternal::FETCH_CACHE_MODE_NO_CACHE:
|
|
|
|
// no-cache means always validate what's in the cache.
|
|
|
|
mLoadFlags |= VALIDATE_ALWAYS;
|
|
|
|
break;
|
|
|
|
case nsIHttpChannelInternal::FETCH_CACHE_MODE_FORCE_CACHE:
|
|
|
|
// force-cache means don't validate unless if the response would vary.
|
|
|
|
mLoadFlags |= LOAD_FROM_CACHE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-11 08:53:35 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsISupportsPriority
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::GetPriority(int32_t *value)
|
2010-04-11 08:53:35 +04:00
|
|
|
{
|
|
|
|
*value = mPriority;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
HttpBaseChannel::AdjustPriority(int32_t delta)
|
2010-04-11 08:53:35 +04:00
|
|
|
{
|
|
|
|
return SetPriority(mPriority + delta);
|
|
|
|
}
|
|
|
|
|
2010-08-11 07:07:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsIResumableChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetEntityID(nsACString& aEntityID)
|
|
|
|
{
|
|
|
|
// Don't return an entity ID for Non-GET requests which require
|
|
|
|
// additional data
|
2014-03-18 20:36:18 +04:00
|
|
|
if (!mRequestHead.IsGet()) {
|
2010-08-11 07:07:09 +04:00
|
|
|
return NS_ERROR_NOT_RESUMABLE;
|
|
|
|
}
|
|
|
|
|
2012-09-28 23:55:23 +04:00
|
|
|
uint64_t size = UINT64_MAX;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString etag, lastmod;
|
2010-08-11 07:07:09 +04:00
|
|
|
if (mResponseHead) {
|
2011-07-22 06:29:00 +04:00
|
|
|
// Don't return an entity if the server sent the following header:
|
|
|
|
// Accept-Ranges: none
|
|
|
|
// Not sending the Accept-Ranges header means we can still try
|
|
|
|
// sending range requests.
|
|
|
|
const char* acceptRanges =
|
|
|
|
mResponseHead->PeekHeader(nsHttp::Accept_Ranges);
|
|
|
|
if (acceptRanges &&
|
|
|
|
!nsHttp::FindToken(acceptRanges, "bytes", HTTP_HEADER_VALUE_SEPS)) {
|
|
|
|
return NS_ERROR_NOT_RESUMABLE;
|
|
|
|
}
|
|
|
|
|
2010-08-11 07:07:09 +04:00
|
|
|
size = mResponseHead->TotalEntitySize();
|
|
|
|
const char* cLastMod = mResponseHead->PeekHeader(nsHttp::Last_Modified);
|
|
|
|
if (cLastMod)
|
|
|
|
lastmod = cLastMod;
|
|
|
|
const char* cEtag = mResponseHead->PeekHeader(nsHttp::ETag);
|
|
|
|
if (cEtag)
|
|
|
|
etag = cEtag;
|
|
|
|
}
|
|
|
|
nsCString entityID;
|
|
|
|
NS_EscapeURL(etag.BeginReading(), etag.Length(), esc_AlwaysCopy |
|
|
|
|
esc_FileBaseName | esc_Forced, entityID);
|
|
|
|
entityID.Append('/');
|
2012-08-22 19:56:38 +04:00
|
|
|
entityID.AppendInt(int64_t(size));
|
2010-08-11 07:07:09 +04:00
|
|
|
entityID.Append('/');
|
|
|
|
entityID.Append(lastmod);
|
|
|
|
// NOTE: Appending lastmod as the last part avoids having to escape it
|
|
|
|
|
|
|
|
aEntityID = entityID;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-30 05:53:25 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsIConsoleReportCollector
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
HttpBaseChannel::AddConsoleReport(uint32_t aErrorFlags,
|
|
|
|
const nsACString& aCategory,
|
|
|
|
nsContentUtils::PropertiesFile aPropertiesFile,
|
|
|
|
const nsACString& aSourceFileURI,
|
|
|
|
uint32_t aLineNumber, uint32_t aColumnNumber,
|
|
|
|
const nsACString& aMessageName,
|
|
|
|
const nsTArray<nsString>& aStringParams)
|
|
|
|
{
|
|
|
|
mReportCollector->AddConsoleReport(aErrorFlags, aCategory, aPropertiesFile,
|
|
|
|
aSourceFileURI, aLineNumber,
|
|
|
|
aColumnNumber, aMessageName,
|
|
|
|
aStringParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
HttpBaseChannel::FlushConsoleReports(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
mReportCollector->FlushConsoleReports(aDocument);
|
|
|
|
}
|
|
|
|
|
2015-11-03 22:20:56 +03:00
|
|
|
void
|
|
|
|
HttpBaseChannel::FlushConsoleReports(nsIConsoleReportCollector* aCollector)
|
|
|
|
{
|
|
|
|
mReportCollector->FlushConsoleReports(aCollector);
|
|
|
|
}
|
|
|
|
|
2014-05-22 23:58:23 +04:00
|
|
|
nsIPrincipal *
|
2015-02-13 23:54:04 +03:00
|
|
|
HttpBaseChannel::GetURIPrincipal()
|
2014-05-22 23:58:23 +04:00
|
|
|
{
|
|
|
|
if (mPrincipal) {
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIScriptSecurityManager *securityManager =
|
|
|
|
nsContentUtils::GetSecurityManager();
|
|
|
|
|
|
|
|
if (!securityManager) {
|
2015-02-13 23:54:04 +03:00
|
|
|
LOG(("HttpBaseChannel::GetURIPrincipal: No security manager [this=%p]",
|
2014-05-22 23:58:23 +04:00
|
|
|
this));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-02-13 23:54:04 +03:00
|
|
|
securityManager->GetChannelURIPrincipal(this, getter_AddRefs(mPrincipal));
|
2014-05-22 23:58:23 +04:00
|
|
|
if (!mPrincipal) {
|
2015-02-13 23:54:04 +03:00
|
|
|
LOG(("HttpBaseChannel::GetURIPrincipal: No channel principal [this=%p]",
|
2014-05-22 23:58:23 +04:00
|
|
|
this));
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
2015-02-19 04:34:29 +03:00
|
|
|
bool
|
|
|
|
HttpBaseChannel::IsNavigation()
|
|
|
|
{
|
2015-10-05 16:46:24 +03:00
|
|
|
return mForceMainDocumentChannel;
|
2015-02-19 04:34:29 +03:00
|
|
|
}
|
|
|
|
|
2015-10-06 16:37:06 +03:00
|
|
|
bool
|
|
|
|
HttpBaseChannel::BypassServiceWorker() const
|
|
|
|
{
|
|
|
|
return mLoadFlags & LOAD_BYPASS_SERVICE_WORKER;
|
|
|
|
}
|
|
|
|
|
2014-07-10 00:35:02 +04:00
|
|
|
bool
|
2015-11-02 19:27:00 +03:00
|
|
|
HttpBaseChannel::ShouldIntercept(nsIURI* aURI)
|
2014-07-10 00:35:02 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsINetworkInterceptController> controller;
|
|
|
|
GetCallback(controller);
|
|
|
|
bool shouldIntercept = false;
|
2015-10-06 16:37:06 +03:00
|
|
|
if (controller && !BypassServiceWorker() && mLoadInfo) {
|
2015-11-02 19:27:00 +03:00
|
|
|
nsresult rv = controller->ShouldPrepareForIntercept(aURI ? aURI : mURI.get(),
|
2015-10-07 05:40:36 +03:00
|
|
|
nsContentUtils::IsNonSubresourceRequest(this),
|
2015-02-19 04:34:29 +03:00
|
|
|
&shouldIntercept);
|
2015-07-23 21:03:25 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-10 00:35:02 +04:00
|
|
|
}
|
|
|
|
return shouldIntercept;
|
|
|
|
}
|
|
|
|
|
2011-05-24 13:32:26 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpChannel::nsITraceableChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetNewListener(nsIStreamListener *aListener, nsIStreamListener **_retval)
|
|
|
|
{
|
|
|
|
if (!mTracingEnabled)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
NS_ENSURE_ARG_POINTER(aListener);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStreamListener> wrapper = new nsStreamListenerWrapper(mListener);
|
|
|
|
|
|
|
|
wrapper.forget(_retval);
|
|
|
|
mListener = aListener;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-04-07 12:43:09 +04:00
|
|
|
|
2010-06-16 03:07:10 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel helpers
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-10-03 04:18:34 +04:00
|
|
|
void
|
|
|
|
HttpBaseChannel::ReleaseListeners()
|
|
|
|
{
|
2013-07-09 05:45:25 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "Should only be called on the main thread.");
|
2015-12-08 11:27:00 +03:00
|
|
|
|
2012-10-03 04:18:34 +04:00
|
|
|
mListener = nullptr;
|
|
|
|
mListenerContext = nullptr;
|
|
|
|
mCallbacks = nullptr;
|
|
|
|
mProgressSink = nullptr;
|
2015-07-24 18:49:25 +03:00
|
|
|
mCompressListener = nullptr;
|
2012-10-03 04:18:34 +04:00
|
|
|
}
|
|
|
|
|
2011-06-12 05:37:03 +04:00
|
|
|
void
|
|
|
|
HttpBaseChannel::DoNotifyListener()
|
|
|
|
{
|
2015-02-13 15:56:00 +03:00
|
|
|
if (mListener) {
|
2015-04-02 13:12:00 +03:00
|
|
|
MOZ_ASSERT(!mOnStartRequestCalled,
|
|
|
|
"We should not call OnStartRequest twice");
|
|
|
|
|
2015-03-18 01:26:33 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> listener = mListener;
|
|
|
|
listener->OnStartRequest(this, mListenerContext);
|
2015-04-02 13:12:00 +03:00
|
|
|
|
|
|
|
mOnStartRequestCalled = true;
|
2015-02-13 15:56:00 +03:00
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
// Make sure mIsPending is set to false. At this moment we are done from
|
2011-06-12 05:37:03 +04:00
|
|
|
// the point of view of our consumer and we have to report our self
|
|
|
|
// as not-pending.
|
2015-02-13 15:56:00 +03:00
|
|
|
mIsPending = false;
|
|
|
|
|
2011-06-12 05:37:03 +04:00
|
|
|
if (mListener) {
|
2016-04-06 11:47:00 +03:00
|
|
|
MOZ_ASSERT(!mOnStopRequestCalled,
|
|
|
|
"We should not call OnStopRequest twice");
|
|
|
|
|
2015-03-18 01:26:33 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> listener = mListener;
|
|
|
|
listener->OnStopRequest(this, mListenerContext, mStatus);
|
2016-04-06 11:47:00 +03:00
|
|
|
|
|
|
|
mOnStopRequestCalled = true;
|
2011-06-12 05:37:03 +04:00
|
|
|
}
|
2015-02-13 15:56:00 +03:00
|
|
|
|
2012-10-03 04:18:34 +04:00
|
|
|
// We have to make sure to drop the references to listeners and callbacks
|
|
|
|
// no longer needed
|
|
|
|
ReleaseListeners();
|
2011-06-12 05:37:03 +04:00
|
|
|
|
|
|
|
DoNotifyListenerCleanup();
|
2015-10-30 05:53:25 +03:00
|
|
|
|
|
|
|
// If this is a navigation, then we must let the docshell flush the reports
|
|
|
|
// to the console later. The LoadDocument() is pointing at the detached
|
|
|
|
// document that started the navigation. We want to show the reports on the
|
|
|
|
// new document. Otherwise the console is wiped and the user never sees
|
|
|
|
// the information.
|
|
|
|
if (!IsNavigation() && mLoadInfo) {
|
|
|
|
nsCOMPtr<nsIDOMDocument> dommyDoc;
|
|
|
|
mLoadInfo->GetLoadingDocument(getter_AddRefs(dommyDoc));
|
|
|
|
nsCOMPtr<nsIDocument> doc = do_QueryInterface(dommyDoc);
|
|
|
|
FlushConsoleReports(doc);
|
|
|
|
}
|
2011-06-12 05:37:03 +04:00
|
|
|
}
|
|
|
|
|
2010-06-16 03:07:10 +04:00
|
|
|
void
|
|
|
|
HttpBaseChannel::AddCookiesToRequest()
|
|
|
|
{
|
|
|
|
if (mLoadFlags & LOAD_ANONYMOUS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-16 17:30:42 +04:00
|
|
|
bool useCookieService =
|
2015-07-04 04:29:00 +03:00
|
|
|
(XRE_IsParentProcess());
|
2010-06-16 03:07:10 +04:00
|
|
|
nsXPIDLCString cookie;
|
2010-10-02 08:17:26 +04:00
|
|
|
if (useCookieService) {
|
|
|
|
nsICookieService *cs = gHttpHandler->GetCookieService();
|
|
|
|
if (cs) {
|
|
|
|
cs->GetCookieStringFromHttp(mURI,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2010-10-02 08:17:26 +04:00
|
|
|
this, getter_Copies(cookie));
|
|
|
|
}
|
2010-06-16 03:07:10 +04:00
|
|
|
|
2010-10-02 08:17:26 +04:00
|
|
|
if (cookie.IsEmpty()) {
|
|
|
|
cookie = mUserSetCookieHeader;
|
|
|
|
}
|
|
|
|
else if (!mUserSetCookieHeader.IsEmpty()) {
|
2014-05-22 07:48:50 +04:00
|
|
|
cookie.AppendLiteral("; ");
|
|
|
|
cookie.Append(mUserSetCookieHeader);
|
2010-10-02 08:17:26 +04:00
|
|
|
}
|
2010-06-16 03:07:10 +04:00
|
|
|
}
|
2010-10-02 08:17:26 +04:00
|
|
|
else {
|
2010-06-16 03:07:10 +04:00
|
|
|
cookie = mUserSetCookieHeader;
|
|
|
|
}
|
|
|
|
|
2010-10-02 08:17:26 +04:00
|
|
|
// If we are in the child process, we want the parent seeing any
|
|
|
|
// cookie headers that might have been set by SetRequestHeader()
|
2011-10-17 18:59:28 +04:00
|
|
|
SetRequestHeader(nsDependentCString(nsHttp::Cookie), cookie, false);
|
2010-04-07 12:43:09 +04:00
|
|
|
}
|
2010-06-16 03:07:10 +04:00
|
|
|
|
2014-03-18 20:36:18 +04:00
|
|
|
bool
|
|
|
|
HttpBaseChannel::ShouldRewriteRedirectToGET(uint32_t httpStatus,
|
|
|
|
nsHttpRequestHead::ParsedMethodType method)
|
|
|
|
{
|
|
|
|
// for 301 and 302, only rewrite POST
|
|
|
|
if (httpStatus == 301 || httpStatus == 302)
|
|
|
|
return method == nsHttpRequestHead::kMethod_Post;
|
|
|
|
|
|
|
|
// rewrite for 303 unless it was HEAD
|
|
|
|
if (httpStatus == 303)
|
|
|
|
return method != nsHttpRequestHead::kMethod_Head;
|
|
|
|
|
|
|
|
// otherwise, such as for 307, do not rewrite
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-06 10:28:00 +03:00
|
|
|
static
|
|
|
|
bool IsHeaderBlacklistedForRedirectCopy(nsHttpAtom const& aHeader)
|
|
|
|
{
|
|
|
|
// IMPORTANT: keep this list ASCII-code sorted
|
|
|
|
static nsHttpAtom const* blackList[] = {
|
|
|
|
&nsHttp::Accept,
|
|
|
|
&nsHttp::Accept_Encoding,
|
|
|
|
&nsHttp::Accept_Language,
|
|
|
|
&nsHttp::Authentication,
|
|
|
|
&nsHttp::Authorization,
|
|
|
|
&nsHttp::Connection,
|
|
|
|
&nsHttp::Content_Length,
|
|
|
|
&nsHttp::Cookie,
|
|
|
|
&nsHttp::Host,
|
|
|
|
&nsHttp::If,
|
|
|
|
&nsHttp::If_Match,
|
|
|
|
&nsHttp::If_Modified_Since,
|
|
|
|
&nsHttp::If_None_Match,
|
|
|
|
&nsHttp::If_None_Match_Any,
|
|
|
|
&nsHttp::If_Range,
|
|
|
|
&nsHttp::If_Unmodified_Since,
|
|
|
|
&nsHttp::Proxy_Authenticate,
|
|
|
|
&nsHttp::Proxy_Authorization,
|
|
|
|
&nsHttp::Range,
|
|
|
|
&nsHttp::TE,
|
|
|
|
&nsHttp::Transfer_Encoding,
|
|
|
|
&nsHttp::Upgrade,
|
|
|
|
&nsHttp::User_Agent,
|
|
|
|
&nsHttp::WWW_Authenticate
|
|
|
|
};
|
|
|
|
|
|
|
|
class HttpAtomComparator
|
|
|
|
{
|
|
|
|
nsHttpAtom const& mTarget;
|
|
|
|
public:
|
|
|
|
explicit HttpAtomComparator(nsHttpAtom const& aTarget)
|
|
|
|
: mTarget(aTarget) {}
|
|
|
|
int operator()(nsHttpAtom const* aVal) const {
|
|
|
|
if (mTarget == *aVal) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return strcmp(mTarget._val, aVal->_val);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t unused;
|
|
|
|
return BinarySearchIf(blackList, 0, ArrayLength(blackList),
|
|
|
|
HttpAtomComparator(aHeader), &unused);
|
|
|
|
}
|
|
|
|
|
2016-05-03 01:06:00 +03:00
|
|
|
class SetupReplacementChannelHeaderVisitor final : public nsIHttpHeaderVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
explicit SetupReplacementChannelHeaderVisitor(nsIHttpChannel *aChannel)
|
|
|
|
: mChannel(aChannel)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD VisitHeader(const nsACString& aHeader,
|
|
|
|
const nsACString& aValue) override
|
|
|
|
{
|
|
|
|
nsHttpAtom atom = nsHttp::ResolveAtom(aHeader);
|
|
|
|
if (!IsHeaderBlacklistedForRedirectCopy(atom)) {
|
|
|
|
mChannel->SetRequestHeader(aHeader, aValue, false);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
~SetupReplacementChannelHeaderVisitor()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> mChannel;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(SetupReplacementChannelHeaderVisitor, nsIHttpHeaderVisitor)
|
|
|
|
|
2010-08-11 07:11:57 +04:00
|
|
|
nsresult
|
2013-05-16 17:30:42 +04:00
|
|
|
HttpBaseChannel::SetupReplacementChannel(nsIURI *newURI,
|
2010-08-11 07:11:57 +04:00
|
|
|
nsIChannel *newChannel,
|
2015-11-01 01:22:01 +03:00
|
|
|
bool preserveMethod,
|
|
|
|
uint32_t redirectFlags)
|
2010-08-11 07:11:57 +04:00
|
|
|
{
|
|
|
|
LOG(("HttpBaseChannel::SetupReplacementChannel "
|
2012-07-25 06:40:34 +04:00
|
|
|
"[this=%p newChannel=%p preserveMethod=%d]",
|
|
|
|
this, newChannel, preserveMethod));
|
2015-11-01 01:22:01 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t newLoadFlags = mLoadFlags | LOAD_REPLACE;
|
2010-08-11 07:11:57 +04:00
|
|
|
// if the original channel was using SSL and this channel is not using
|
|
|
|
// SSL, then no need to inhibit persistent caching. however, if the
|
|
|
|
// original channel was not using SSL and has INHIBIT_PERSISTENT_CACHING
|
|
|
|
// set, then allow the flag to apply to the redirected channel as well.
|
|
|
|
// since we force set INHIBIT_PERSISTENT_CACHING on all HTTPS channels,
|
|
|
|
// we only need to check if the original channel was using SSL.
|
2012-09-15 00:27:46 +04:00
|
|
|
bool usingSSL = false;
|
|
|
|
nsresult rv = mURI->SchemeIs("https", &usingSSL);
|
|
|
|
if (NS_SUCCEEDED(rv) && usingSSL)
|
2010-08-11 07:11:57 +04:00
|
|
|
newLoadFlags &= ~INHIBIT_PERSISTENT_CACHING;
|
|
|
|
|
|
|
|
// Do not pass along LOAD_CHECK_OFFLINE_CACHE
|
|
|
|
newLoadFlags &= ~nsICachingChannel::LOAD_CHECK_OFFLINE_CACHE;
|
|
|
|
|
2013-05-16 17:30:42 +04:00
|
|
|
newChannel->SetLoadGroup(mLoadGroup);
|
2010-08-11 07:11:57 +04:00
|
|
|
newChannel->SetNotificationCallbacks(mCallbacks);
|
|
|
|
newChannel->SetLoadFlags(newLoadFlags);
|
|
|
|
|
2012-10-12 22:59:39 +04:00
|
|
|
// Try to preserve the privacy bit if it has been overridden
|
|
|
|
if (mPrivateBrowsingOverriden) {
|
|
|
|
nsCOMPtr<nsIPrivateBrowsingChannel> newPBChannel =
|
|
|
|
do_QueryInterface(newChannel);
|
|
|
|
if (newPBChannel) {
|
|
|
|
newPBChannel->SetPrivate(mPrivateBrowsing);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-01 01:22:01 +03:00
|
|
|
// make a copy of the loadinfo, append to the redirectchain
|
|
|
|
// and set it on the new channel
|
|
|
|
if (mLoadInfo) {
|
|
|
|
nsCOMPtr<nsILoadInfo> newLoadInfo =
|
|
|
|
static_cast<mozilla::LoadInfo*>(mLoadInfo.get())->Clone();
|
|
|
|
bool isInternalRedirect =
|
|
|
|
(redirectFlags & (nsIChannelEventSink::REDIRECT_INTERNAL |
|
|
|
|
nsIChannelEventSink::REDIRECT_STS_UPGRADE));
|
|
|
|
newLoadInfo->AppendRedirectedPrincipal(GetURIPrincipal(), isInternalRedirect);
|
|
|
|
newChannel->SetLoadInfo(newLoadInfo);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// the newChannel was created with a dummy loadInfo, we should clear
|
|
|
|
// it in case the original channel does not have a loadInfo
|
|
|
|
newChannel->SetLoadInfo(nullptr);
|
|
|
|
}
|
2014-07-10 10:56:37 +04:00
|
|
|
|
2010-08-11 07:11:57 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(newChannel);
|
|
|
|
if (!httpChannel)
|
|
|
|
return NS_OK; // no other options to set
|
|
|
|
|
2015-08-28 17:23:46 +03:00
|
|
|
// Preserve the CORS preflight information.
|
|
|
|
nsCOMPtr<nsIHttpChannelInternal> httpInternal = do_QueryInterface(newChannel);
|
|
|
|
if (mRequireCORSPreflight && httpInternal) {
|
2015-12-07 02:33:14 +03:00
|
|
|
httpInternal->SetCorsPreflightParameters(mUnsafeHeaders);
|
2015-08-28 17:23:46 +03:00
|
|
|
}
|
|
|
|
|
2010-08-11 07:11:57 +04:00
|
|
|
if (preserveMethod) {
|
|
|
|
nsCOMPtr<nsIUploadChannel> uploadChannel =
|
|
|
|
do_QueryInterface(httpChannel);
|
|
|
|
nsCOMPtr<nsIUploadChannel2> uploadChannel2 =
|
|
|
|
do_QueryInterface(httpChannel);
|
|
|
|
if (mUploadStream && (uploadChannel2 || uploadChannel)) {
|
|
|
|
// rewind upload stream
|
|
|
|
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(mUploadStream);
|
|
|
|
if (seekable)
|
|
|
|
seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
|
|
|
|
|
|
|
// replicate original call to SetUploadStream...
|
|
|
|
if (uploadChannel2) {
|
2016-05-03 01:06:00 +03:00
|
|
|
nsAutoCString ctype;
|
|
|
|
// If header is not present mRequestHead.HasHeaderValue will truncated
|
|
|
|
// it.
|
|
|
|
mRequestHead.GetHeader(nsHttp::Content_Type, ctype);
|
|
|
|
nsAutoCString clen;
|
|
|
|
mRequestHead.GetHeader(nsHttp::Content_Length, clen);
|
|
|
|
nsAutoCString method;
|
|
|
|
mRequestHead.Method(method);
|
|
|
|
int64_t len = clen.IsEmpty() ? -1 : nsCRT::atoll(clen.get());
|
2010-08-11 07:11:57 +04:00
|
|
|
uploadChannel2->ExplicitSetUploadStream(
|
2016-05-03 01:06:00 +03:00
|
|
|
mUploadStream, ctype, len,
|
|
|
|
method,
|
2010-08-11 11:09:50 +04:00
|
|
|
mUploadStreamHasHeaders);
|
2010-08-11 07:11:57 +04:00
|
|
|
} else {
|
|
|
|
if (mUploadStreamHasHeaders) {
|
|
|
|
uploadChannel->SetUploadStream(mUploadStream, EmptyCString(),
|
|
|
|
-1);
|
|
|
|
} else {
|
2016-05-03 01:06:00 +03:00
|
|
|
nsAutoCString ctype;
|
|
|
|
if (NS_FAILED(mRequestHead.GetHeader(nsHttp::Content_Type, ctype))) {
|
|
|
|
ctype = NS_LITERAL_CSTRING("application/octet-stream");
|
2010-08-11 07:11:57 +04:00
|
|
|
}
|
2016-05-03 01:06:00 +03:00
|
|
|
nsAutoCString clen;
|
|
|
|
if (NS_SUCCEEDED(mRequestHead.GetHeader(nsHttp::Content_Length, clen))
|
|
|
|
&&
|
|
|
|
!clen.IsEmpty()) {
|
2010-08-11 07:11:57 +04:00
|
|
|
uploadChannel->SetUploadStream(mUploadStream,
|
2016-05-03 01:06:00 +03:00
|
|
|
ctype,
|
|
|
|
nsCRT::atoll(clen.get()));
|
2010-08-11 07:11:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-16 17:30:42 +04:00
|
|
|
// since preserveMethod is true, we need to ensure that the appropriate
|
|
|
|
// request method gets set on the channel, regardless of whether or not
|
2010-08-11 07:11:57 +04:00
|
|
|
// we set the upload stream above. This means SetRequestMethod() will
|
|
|
|
// be called twice if ExplicitSetUploadStream() gets called above.
|
|
|
|
|
2016-05-03 01:06:00 +03:00
|
|
|
nsAutoCString method;
|
|
|
|
mRequestHead.Method(method);
|
|
|
|
httpChannel->SetRequestMethod(method);
|
2010-08-11 07:11:57 +04:00
|
|
|
}
|
|
|
|
// convey the referrer if one was used for this channel to the next one
|
|
|
|
if (mReferrer)
|
2014-11-18 16:46:29 +03:00
|
|
|
httpChannel->SetReferrerWithPolicy(mReferrer, mReferrerPolicy);
|
2014-06-04 20:57:15 +04:00
|
|
|
// convey the mAllowPipelining and mAllowSTS flags
|
2010-08-11 07:11:57 +04:00
|
|
|
httpChannel->SetAllowPipelining(mAllowPipelining);
|
2014-06-04 20:57:15 +04:00
|
|
|
httpChannel->SetAllowSTS(mAllowSTS);
|
2010-08-11 07:11:57 +04:00
|
|
|
// convey the new redirection limit
|
|
|
|
httpChannel->SetRedirectionLimit(mRedirectionLimit - 1);
|
|
|
|
|
2014-02-26 18:03:14 +04:00
|
|
|
// convey the Accept header value
|
|
|
|
{
|
|
|
|
nsAutoCString oldAcceptValue;
|
|
|
|
nsresult hasHeader = mRequestHead.GetHeader(nsHttp::Accept, oldAcceptValue);
|
|
|
|
if (NS_SUCCEEDED(hasHeader)) {
|
|
|
|
httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"),
|
|
|
|
oldAcceptValue,
|
|
|
|
false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-21 17:59:17 +03:00
|
|
|
// share the request context - see bug 1236650
|
|
|
|
httpChannel->SetRequestContextID(mRequestContextID);
|
2016-04-12 21:43:39 +03:00
|
|
|
|
2010-08-11 07:11:57 +04:00
|
|
|
if (httpInternal) {
|
2014-10-28 16:23:00 +03:00
|
|
|
// Convey third party cookie and spdy flags.
|
|
|
|
httpInternal->SetThirdPartyFlags(mThirdPartyFlags);
|
2011-12-13 19:55:50 +04:00
|
|
|
httpInternal->SetAllowSpdy(mAllowSpdy);
|
2015-04-13 19:59:34 +03:00
|
|
|
httpInternal->SetAllowAltSvc(mAllowAltSvc);
|
2010-08-11 07:11:57 +04:00
|
|
|
|
2016-02-03 00:44:11 +03:00
|
|
|
RefPtr<nsHttpChannel> realChannel;
|
|
|
|
CallQueryInterface(newChannel, realChannel.StartAssignment());
|
|
|
|
if (realChannel) {
|
|
|
|
realChannel->SetTopWindowURI(mTopWindowURI);
|
|
|
|
}
|
|
|
|
|
2010-08-11 07:11:57 +04:00
|
|
|
// update the DocumentURI indicator since we are being redirected.
|
|
|
|
// if this was a top-level document channel, then the new channel
|
|
|
|
// should have its mDocumentURI point to newURI; otherwise, we
|
|
|
|
// just need to pass along our mDocumentURI to the new channel.
|
|
|
|
if (newURI && (mURI == mDocumentURI))
|
|
|
|
httpInternal->SetDocumentURI(newURI);
|
|
|
|
else
|
|
|
|
httpInternal->SetDocumentURI(mDocumentURI);
|
2011-03-24 06:36:53 +03:00
|
|
|
|
|
|
|
// if there is a chain of keys for redirect-responses we transfer it to
|
|
|
|
// the new channel (see bug #561276)
|
|
|
|
if (mRedirectedCachekeys) {
|
|
|
|
LOG(("HttpBaseChannel::SetupReplacementChannel "
|
|
|
|
"[this=%p] transferring chain of redirect cache-keys", this));
|
2012-06-01 02:20:05 +04:00
|
|
|
httpInternal->SetCacheKeysRedirectChain(mRedirectedCachekeys.forget());
|
2011-03-24 06:36:53 +03:00
|
|
|
}
|
2015-09-01 00:26:29 +03:00
|
|
|
|
|
|
|
// Preserve CORS mode flag.
|
|
|
|
httpInternal->SetCorsMode(mCorsMode);
|
|
|
|
|
|
|
|
// Preserve Redirect mode flag.
|
|
|
|
httpInternal->SetRedirectMode(mRedirectMode);
|
2016-02-29 00:34:01 +03:00
|
|
|
|
|
|
|
// Preserve Cache mode flag.
|
|
|
|
httpInternal->SetFetchCacheMode(mFetchCacheMode);
|
2011-03-24 06:36:53 +03:00
|
|
|
}
|
2013-05-16 17:30:42 +04:00
|
|
|
|
2010-08-11 07:11:57 +04:00
|
|
|
// transfer application cache information
|
|
|
|
nsCOMPtr<nsIApplicationCacheChannel> appCacheChannel =
|
|
|
|
do_QueryInterface(newChannel);
|
|
|
|
if (appCacheChannel) {
|
|
|
|
appCacheChannel->SetApplicationCache(mApplicationCache);
|
|
|
|
appCacheChannel->SetInheritApplicationCache(mInheritApplicationCache);
|
|
|
|
// We purposely avoid transfering mChooseApplicationCache.
|
|
|
|
}
|
|
|
|
|
|
|
|
// transfer any properties
|
|
|
|
nsCOMPtr<nsIWritablePropertyBag> bag(do_QueryInterface(newChannel));
|
2015-11-20 03:46:24 +03:00
|
|
|
if (bag) {
|
|
|
|
for (auto iter = mPropertyHash.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
bag->SetProperty(iter.Key(), iter.UserData());
|
|
|
|
}
|
|
|
|
}
|
2010-08-11 07:11:57 +04:00
|
|
|
|
2013-10-16 05:35:44 +04:00
|
|
|
// Transfer the timing data (if we are dealing with an nsITimedChannel).
|
|
|
|
nsCOMPtr<nsITimedChannel> newTimedChannel(do_QueryInterface(newChannel));
|
|
|
|
nsCOMPtr<nsITimedChannel> oldTimedChannel(
|
|
|
|
do_QueryInterface(static_cast<nsIHttpChannel*>(this)));
|
|
|
|
if (oldTimedChannel && newTimedChannel) {
|
|
|
|
newTimedChannel->SetTimingEnabled(mTimingEnabled);
|
|
|
|
newTimedChannel->SetRedirectCount(mRedirectCount + 1);
|
|
|
|
|
|
|
|
// If the RedirectStart is null, we will use the AsyncOpen value of the
|
|
|
|
// previous channel (this is the first redirect in the redirects chain).
|
|
|
|
if (mRedirectStartTimeStamp.IsNull()) {
|
|
|
|
TimeStamp asyncOpen;
|
|
|
|
oldTimedChannel->GetAsyncOpen(&asyncOpen);
|
|
|
|
newTimedChannel->SetRedirectStart(asyncOpen);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newTimedChannel->SetRedirectStart(mRedirectStartTimeStamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The RedirectEnd timestamp is equal to the previous channel response end.
|
|
|
|
TimeStamp prevResponseEnd;
|
|
|
|
oldTimedChannel->GetResponseEnd(&prevResponseEnd);
|
|
|
|
newTimedChannel->SetRedirectEnd(prevResponseEnd);
|
|
|
|
|
2014-06-05 23:24:47 +04:00
|
|
|
nsAutoString initiatorType;
|
|
|
|
oldTimedChannel->GetInitiatorType(initiatorType);
|
|
|
|
newTimedChannel->SetInitiatorType(initiatorType);
|
|
|
|
|
2013-10-16 05:35:44 +04:00
|
|
|
// Check whether or not this was a cross-domain redirect.
|
|
|
|
newTimedChannel->SetAllRedirectsSameOrigin(
|
|
|
|
mAllRedirectsSameOrigin && SameOriginWithOriginalUri(newURI));
|
2014-05-15 09:26:07 +04:00
|
|
|
|
|
|
|
// Execute the timing allow check to determine whether
|
|
|
|
// to report the redirect timing info
|
|
|
|
nsCOMPtr<nsILoadInfo> loadInfo;
|
|
|
|
GetLoadInfo(getter_AddRefs(loadInfo));
|
2016-04-14 02:30:31 +03:00
|
|
|
// TYPE_DOCUMENT loads don't have a loadingPrincipal, so we can't set
|
|
|
|
// AllRedirectsPassTimingAllowCheck on them.
|
|
|
|
if (loadInfo && loadInfo->GetExternalContentPolicyType() != nsIContentPolicy::TYPE_DOCUMENT) {
|
2014-05-15 09:26:07 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> principal = loadInfo->LoadingPrincipal();
|
|
|
|
newTimedChannel->SetAllRedirectsPassTimingAllowCheck(
|
|
|
|
mAllRedirectsPassTimingAllowCheck &&
|
|
|
|
oldTimedChannel->TimingAllowCheck(principal));
|
|
|
|
}
|
2013-10-16 05:35:44 +04:00
|
|
|
}
|
2011-05-21 14:03:36 +04:00
|
|
|
|
2016-04-06 10:28:00 +03:00
|
|
|
if (redirectFlags & (nsIChannelEventSink::REDIRECT_INTERNAL |
|
|
|
|
nsIChannelEventSink::REDIRECT_STS_UPGRADE)) {
|
|
|
|
// Copy non-origin related headers to the new channel.
|
2016-05-03 01:06:00 +03:00
|
|
|
nsCOMPtr<nsIHttpHeaderVisitor> visitor =
|
|
|
|
new SetupReplacementChannelHeaderVisitor(httpChannel);
|
|
|
|
mRequestHead.VisitHeaders(visitor);
|
2016-04-06 10:28:00 +03:00
|
|
|
}
|
|
|
|
|
2014-06-05 23:24:47 +04:00
|
|
|
// This channel has been redirected. Don't report timing info.
|
|
|
|
mTimingEnabled = false;
|
2010-08-11 07:11:57 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-16 05:35:44 +04:00
|
|
|
// Redirect Tracking
|
|
|
|
bool
|
|
|
|
HttpBaseChannel::SameOriginWithOriginalUri(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
|
|
|
nsresult rv = ssm->CheckSameOriginURI(aURI, mOriginalURI, false);
|
|
|
|
return (NS_SUCCEEDED(rv));
|
|
|
|
}
|
|
|
|
|
2014-04-21 17:34:33 +04:00
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HttpBaseChannel::nsITimedChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetTimingEnabled(bool enabled) {
|
|
|
|
mTimingEnabled = enabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetTimingEnabled(bool* _retval) {
|
|
|
|
*_retval = mTimingEnabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetChannelCreation(TimeStamp* _retval) {
|
|
|
|
*_retval = mChannelCreationTimestamp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetAsyncOpen(TimeStamp* _retval) {
|
|
|
|
*_retval = mAsyncOpenTime;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the number of redirects. There is no check for cross-domain
|
|
|
|
* redirects. This check must be done by the consumers.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetRedirectCount(uint16_t *aRedirectCount)
|
|
|
|
{
|
|
|
|
*aRedirectCount = mRedirectCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetRedirectCount(uint16_t aRedirectCount)
|
|
|
|
{
|
|
|
|
mRedirectCount = aRedirectCount;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetRedirectStart(TimeStamp* _retval)
|
|
|
|
{
|
|
|
|
*_retval = mRedirectStartTimeStamp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetRedirectStart(TimeStamp aRedirectStart)
|
|
|
|
{
|
|
|
|
mRedirectStartTimeStamp = aRedirectStart;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetRedirectEnd(TimeStamp* _retval)
|
|
|
|
{
|
|
|
|
*_retval = mRedirectEndTimeStamp;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetRedirectEnd(TimeStamp aRedirectEnd)
|
|
|
|
{
|
|
|
|
mRedirectEndTimeStamp = aRedirectEnd;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetAllRedirectsSameOrigin(bool *aAllRedirectsSameOrigin)
|
|
|
|
{
|
|
|
|
*aAllRedirectsSameOrigin = mAllRedirectsSameOrigin;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetAllRedirectsSameOrigin(bool aAllRedirectsSameOrigin)
|
|
|
|
{
|
|
|
|
mAllRedirectsSameOrigin = aAllRedirectsSameOrigin;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-15 09:26:07 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetAllRedirectsPassTimingAllowCheck(bool *aPassesCheck)
|
|
|
|
{
|
|
|
|
*aPassesCheck = mAllRedirectsPassTimingAllowCheck;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetAllRedirectsPassTimingAllowCheck(bool aPassesCheck)
|
|
|
|
{
|
|
|
|
mAllRedirectsPassTimingAllowCheck = aPassesCheck;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// http://www.w3.org/TR/resource-timing/#timing-allow-check
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::TimingAllowCheck(nsIPrincipal *aOrigin, bool *_retval)
|
|
|
|
{
|
|
|
|
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
|
|
|
nsCOMPtr<nsIPrincipal> resourcePrincipal;
|
|
|
|
nsresult rv = ssm->GetChannelURIPrincipal(this, getter_AddRefs(resourcePrincipal));
|
|
|
|
if (NS_FAILED(rv) || !resourcePrincipal || !aOrigin) {
|
|
|
|
*_retval = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool sameOrigin = false;
|
|
|
|
rv = resourcePrincipal->Equals(aOrigin, &sameOrigin);
|
|
|
|
if (NS_SUCCEEDED(rv) && sameOrigin) {
|
|
|
|
*_retval = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString headerValue;
|
|
|
|
rv = GetResponseHeader(NS_LITERAL_CSTRING("Timing-Allow-Origin"), headerValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
*_retval = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (headerValue == "*") {
|
|
|
|
*_retval = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString origin;
|
|
|
|
nsContentUtils::GetASCIIOrigin(aOrigin, origin);
|
|
|
|
|
|
|
|
if (headerValue == origin) {
|
|
|
|
*_retval = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*_retval = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-21 17:34:33 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetDomainLookupStart(TimeStamp* _retval) {
|
|
|
|
*_retval = mTransactionTimings.domainLookupStart;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetDomainLookupEnd(TimeStamp* _retval) {
|
|
|
|
*_retval = mTransactionTimings.domainLookupEnd;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetConnectStart(TimeStamp* _retval) {
|
|
|
|
*_retval = mTransactionTimings.connectStart;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetConnectEnd(TimeStamp* _retval) {
|
|
|
|
*_retval = mTransactionTimings.connectEnd;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetRequestStart(TimeStamp* _retval) {
|
|
|
|
*_retval = mTransactionTimings.requestStart;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetResponseStart(TimeStamp* _retval) {
|
|
|
|
*_retval = mTransactionTimings.responseStart;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetResponseEnd(TimeStamp* _retval) {
|
|
|
|
*_retval = mTransactionTimings.responseEnd;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetCacheReadStart(TimeStamp* _retval) {
|
|
|
|
*_retval = mCacheReadStart;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetCacheReadEnd(TimeStamp* _retval) {
|
|
|
|
*_retval = mCacheReadEnd;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetInitiatorType(nsAString & aInitiatorType)
|
|
|
|
{
|
|
|
|
aInitiatorType = mInitiatorType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetInitiatorType(const nsAString & aInitiatorType)
|
|
|
|
{
|
|
|
|
mInitiatorType = aInitiatorType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define IMPL_TIMING_ATTR(name) \
|
|
|
|
NS_IMETHODIMP \
|
|
|
|
HttpBaseChannel::Get##name##Time(PRTime* _retval) { \
|
|
|
|
TimeStamp stamp; \
|
|
|
|
Get##name(&stamp); \
|
|
|
|
if (stamp.IsNull()) { \
|
|
|
|
*_retval = 0; \
|
|
|
|
return NS_OK; \
|
|
|
|
} \
|
|
|
|
*_retval = mChannelCreationTime + \
|
|
|
|
(PRTime) ((stamp - mChannelCreationTimestamp).ToSeconds() * 1e6); \
|
|
|
|
return NS_OK; \
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_TIMING_ATTR(ChannelCreation)
|
|
|
|
IMPL_TIMING_ATTR(AsyncOpen)
|
|
|
|
IMPL_TIMING_ATTR(DomainLookupStart)
|
|
|
|
IMPL_TIMING_ATTR(DomainLookupEnd)
|
|
|
|
IMPL_TIMING_ATTR(ConnectStart)
|
|
|
|
IMPL_TIMING_ATTR(ConnectEnd)
|
|
|
|
IMPL_TIMING_ATTR(RequestStart)
|
|
|
|
IMPL_TIMING_ATTR(ResponseStart)
|
|
|
|
IMPL_TIMING_ATTR(ResponseEnd)
|
|
|
|
IMPL_TIMING_ATTR(CacheReadStart)
|
|
|
|
IMPL_TIMING_ATTR(CacheReadEnd)
|
|
|
|
IMPL_TIMING_ATTR(RedirectStart)
|
|
|
|
IMPL_TIMING_ATTR(RedirectEnd)
|
|
|
|
|
|
|
|
#undef IMPL_TIMING_ATTR
|
|
|
|
|
2014-10-06 15:33:13 +04:00
|
|
|
nsPerformance*
|
|
|
|
HttpBaseChannel::GetPerformance()
|
|
|
|
{
|
|
|
|
// If performance timing is disabled, there is no need for the nsPerformance
|
|
|
|
// object anymore.
|
|
|
|
if (!mTimingEnabled) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-04-15 05:26:58 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> pDomWindow = GetInnerDOMWindow();
|
|
|
|
if (!pDomWindow) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPerformance* docPerformance = pDomWindow->GetPerformance();
|
|
|
|
if (!docPerformance) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
// iframes should be added to the parent's entries list.
|
|
|
|
if (mLoadFlags & LOAD_DOCUMENT_URI) {
|
|
|
|
return docPerformance->GetParentPerformance();
|
|
|
|
}
|
|
|
|
return docPerformance;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIURI*
|
|
|
|
HttpBaseChannel::GetReferringPage()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> pDomWindow = GetInnerDOMWindow();
|
|
|
|
if (!pDomWindow) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return pDomWindow->GetDocumentURI();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPIDOMWindowInner*
|
|
|
|
HttpBaseChannel::GetInnerDOMWindow()
|
|
|
|
{
|
2014-10-06 15:33:13 +04:00
|
|
|
nsCOMPtr<nsILoadContext> loadContext;
|
|
|
|
NS_QueryNotificationCallbacks(this, loadContext);
|
|
|
|
if (!loadContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> domWindow;
|
2014-10-06 15:33:13 +04:00
|
|
|
loadContext->GetAssociatedWindow(getter_AddRefs(domWindow));
|
|
|
|
if (!domWindow) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-30 20:05:36 +03:00
|
|
|
auto* pDomWindow = nsPIDOMWindowOuter::From(domWindow);
|
2014-10-06 15:33:13 +04:00
|
|
|
if (!pDomWindow) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> innerWindow = pDomWindow->GetCurrentInnerWindow();
|
|
|
|
if (!innerWindow) {
|
|
|
|
return nullptr;
|
2014-10-06 15:33:13 +04:00
|
|
|
}
|
|
|
|
|
2016-04-15 05:26:58 +03:00
|
|
|
return innerWindow;
|
2014-10-06 15:33:13 +04:00
|
|
|
}
|
2014-04-21 17:34:33 +04:00
|
|
|
|
2010-06-16 03:07:10 +04:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
2015-07-31 23:50:08 +03:00
|
|
|
bool
|
2016-04-21 17:59:17 +03:00
|
|
|
HttpBaseChannel::EnsureRequestContextID()
|
2015-07-31 23:50:08 +03:00
|
|
|
{
|
|
|
|
nsID nullID;
|
|
|
|
nullID.Clear();
|
2016-04-21 17:59:17 +03:00
|
|
|
if (!mRequestContextID.Equals(nullID)) {
|
|
|
|
// Already have a request context ID, no need to do the rest of this work
|
2015-07-31 23:50:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the loadgroup at the end of the chain in order
|
|
|
|
// to make sure all channels derived from the load group
|
|
|
|
// use the same connection scope.
|
|
|
|
nsCOMPtr<nsILoadGroupChild> childLoadGroup = do_QueryInterface(mLoadGroup);
|
|
|
|
if (!childLoadGroup) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> rootLoadGroup;
|
|
|
|
childLoadGroup->GetRootLoadGroup(getter_AddRefs(rootLoadGroup));
|
|
|
|
if (!rootLoadGroup) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the load group connection scope on the transaction
|
2016-04-21 17:59:17 +03:00
|
|
|
rootLoadGroup->GetRequestContextID(&mRequestContextID);
|
2015-07-31 23:50:08 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-07 02:33:14 +03:00
|
|
|
void
|
2015-12-07 02:33:14 +03:00
|
|
|
HttpBaseChannel::SetCorsPreflightParameters(const nsTArray<nsCString>& aUnsafeHeaders)
|
2015-08-22 00:31:56 +03:00
|
|
|
{
|
2015-12-07 02:33:14 +03:00
|
|
|
MOZ_RELEASE_ASSERT(!mRequestObserversCalled);
|
2015-08-22 00:31:56 +03:00
|
|
|
|
|
|
|
mRequireCORSPreflight = true;
|
|
|
|
mUnsafeHeaders = aUnsafeHeaders;
|
|
|
|
}
|
|
|
|
|
2015-12-30 21:47:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::GetBlockAuthPrompt(bool* aValue)
|
|
|
|
{
|
|
|
|
if (!aValue) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aValue = mBlockAuthPrompt;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HttpBaseChannel::SetBlockAuthPrompt(bool aValue)
|
|
|
|
{
|
|
|
|
ENSURE_CALLED_BEFORE_CONNECT();
|
|
|
|
|
|
|
|
mBlockAuthPrompt = aValue;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|