2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim:set et cin ts=4 sw=4 sts=4: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Darin Fisher <darin@netscape.com> (original author)
|
|
|
|
* Christian Biesinger <cbiesinger@web.de>
|
2010-04-07 01:43:09 -07:00
|
|
|
* Daniel Witte <dwitte@mozilla.com>
|
2010-06-22 17:33:57 -07:00
|
|
|
* Jason Duell <jduell.mcbugs@gmail.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef nsHttpChannel_h__
|
|
|
|
#define nsHttpChannel_h__
|
|
|
|
|
2010-04-07 01:43:09 -07:00
|
|
|
#include "HttpBaseChannel.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsHttpTransaction.h"
|
|
|
|
#include "nsInputStreamPump.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2010-04-07 01:43:09 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIHttpEventSink.h"
|
|
|
|
#include "nsICachingChannel.h"
|
|
|
|
#include "nsICacheEntryDescriptor.h"
|
|
|
|
#include "nsICacheListener.h"
|
2008-08-26 16:09:02 -07:00
|
|
|
#include "nsIApplicationCache.h"
|
2008-11-04 02:20:27 -08:00
|
|
|
#include "nsIApplicationCacheChannel.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIEncodedChannel.h"
|
|
|
|
#include "nsIStringEnumerator.h"
|
|
|
|
#include "nsIPrompt.h"
|
|
|
|
#include "nsIResumableChannel.h"
|
|
|
|
#include "nsIProtocolProxyCallback.h"
|
|
|
|
#include "nsICancelable.h"
|
2010-06-17 11:33:42 -07:00
|
|
|
#include "nsIHttpAuthenticableChannel.h"
|
2008-08-25 10:21:28 -07:00
|
|
|
#include "nsITraceableChannel.h"
|
2010-06-17 11:33:42 -07:00
|
|
|
#include "nsIHttpChannelAuthProvider.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsAHttpConnection;
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
using namespace mozilla::net;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2010-04-07 01:43:09 -07:00
|
|
|
class nsHttpChannel : public HttpBaseChannel
|
2007-03-22 10:30:00 -07:00
|
|
|
, public nsIStreamListener
|
|
|
|
, public nsICachingChannel
|
|
|
|
, public nsICacheListener
|
|
|
|
, public nsIEncodedChannel
|
|
|
|
, public nsITransportEventSink
|
|
|
|
, public nsIResumableChannel
|
|
|
|
, public nsIProtocolProxyCallback
|
2010-06-17 11:33:42 -07:00
|
|
|
, public nsIHttpAuthenticableChannel
|
2008-08-25 10:21:28 -07:00
|
|
|
, public nsITraceableChannel
|
2008-11-04 02:20:27 -08:00
|
|
|
, public nsIApplicationCacheChannel
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2010-06-23 23:55:19 -07:00
|
|
|
NS_DECL_NSICACHEINFOCHANNEL
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSICACHINGCHANNEL
|
|
|
|
NS_DECL_NSICACHELISTENER
|
|
|
|
NS_DECL_NSIENCODEDCHANNEL
|
|
|
|
NS_DECL_NSITRANSPORTEVENTSINK
|
|
|
|
NS_DECL_NSIRESUMABLECHANNEL
|
|
|
|
NS_DECL_NSIPROTOCOLPROXYCALLBACK
|
|
|
|
NS_DECL_NSIPROXIEDCHANNEL
|
2008-08-25 10:21:28 -07:00
|
|
|
NS_DECL_NSITRACEABLECHANNEL
|
2008-08-26 16:09:02 -07:00
|
|
|
NS_DECL_NSIAPPLICATIONCACHECONTAINER
|
2008-11-04 02:20:27 -08:00
|
|
|
NS_DECL_NSIAPPLICATIONCACHECHANNEL
|
2010-06-17 11:33:42 -07:00
|
|
|
|
|
|
|
// nsIHttpAuthenticableChannel. We can't use
|
|
|
|
// NS_DECL_NSIHTTPAUTHENTICABLECHANNEL because it duplicates cancel() and
|
|
|
|
// others.
|
|
|
|
NS_IMETHOD GetIsSSL(PRBool *aIsSSL);
|
|
|
|
NS_IMETHOD GetProxyMethodIsConnect(PRBool *aProxyMethodIsConnect);
|
|
|
|
NS_IMETHOD GetServerResponseHeader(nsACString & aServerResponseHeader);
|
|
|
|
NS_IMETHOD GetProxyChallenges(nsACString & aChallenges);
|
|
|
|
NS_IMETHOD GetWWWChallenges(nsACString & aChallenges);
|
|
|
|
NS_IMETHOD SetProxyCredentials(const nsACString & aCredentials);
|
|
|
|
NS_IMETHOD SetWWWCredentials(const nsACString & aCredentials);
|
|
|
|
NS_IMETHOD OnAuthAvailable();
|
|
|
|
NS_IMETHOD OnAuthCancelled(PRBool userCancel);
|
2010-06-22 17:33:57 -07:00
|
|
|
// Functions we implement from nsIHttpAuthenticableChannel but are
|
|
|
|
// declared in HttpBaseChannel must be implemented in this class. We
|
|
|
|
// just call the HttpBaseChannel:: impls.
|
|
|
|
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags);
|
|
|
|
NS_IMETHOD GetURI(nsIURI **aURI);
|
|
|
|
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks);
|
|
|
|
NS_IMETHOD GetLoadGroup(nsILoadGroup **aLoadGroup);
|
|
|
|
NS_IMETHOD GetRequestMethod(nsACString& aMethod);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsHttpChannel();
|
|
|
|
virtual ~nsHttpChannel();
|
|
|
|
|
2010-06-22 17:33:57 -07:00
|
|
|
virtual nsresult Init(nsIURI *aURI, PRUint8 aCaps, nsProxyInfo *aProxyInfo);
|
|
|
|
|
2010-04-07 01:43:09 -07:00
|
|
|
// Methods HttpBaseChannel didn't implement for us or that we override.
|
|
|
|
//
|
|
|
|
// nsIRequest
|
|
|
|
NS_IMETHOD Cancel(nsresult status);
|
|
|
|
NS_IMETHOD Suspend();
|
|
|
|
NS_IMETHOD Resume();
|
|
|
|
// nsIChannel
|
|
|
|
NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo);
|
|
|
|
NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *aContext);
|
|
|
|
// nsIHttpChannelInternal
|
|
|
|
NS_IMETHOD SetupFallbackChannel(const char *aFallbackKey);
|
2010-04-10 21:53:35 -07:00
|
|
|
// nsISupportsPriority
|
|
|
|
NS_IMETHOD SetPriority(PRInt32 value);
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
public: /* internal necko use only */
|
2007-03-22 10:30:00 -07:00
|
|
|
typedef void (nsHttpChannel:: *nsAsyncCallback)(void);
|
2010-03-23 08:14:36 -07:00
|
|
|
nsHttpResponseHead * GetResponseHead() const { return mResponseHead; }
|
2010-06-15 16:07:10 -07:00
|
|
|
void SetRemoteChannel(bool aRemote) { mRemoteChannel = aRemote; }
|
2010-05-30 15:30:28 -07:00
|
|
|
void InternalSetUploadStream(nsIInputStream *uploadStream)
|
|
|
|
{ mUploadStream = uploadStream; }
|
|
|
|
void SetUploadStreamHasHeaders(PRBool hasHeaders)
|
|
|
|
{ mUploadStreamHasHeaders = hasHeaders; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-04-07 01:43:44 -07:00
|
|
|
nsresult SetReferrerInternal(nsIURI *referrer) {
|
|
|
|
nsCAutoString spec;
|
|
|
|
nsresult rv = referrer->GetAsciiSpec(spec);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mReferrer = referrer;
|
|
|
|
mRequestHead.SetHeader(nsHttp::Referer, spec);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2007-03-22 10:30:00 -07:00
|
|
|
// AsyncCall may be used to call a member function asynchronously.
|
2009-02-11 20:16:00 -08:00
|
|
|
// retval isn't refcounted and is set only when event was successfully
|
|
|
|
// posted, the event is returned for the purpose of cancelling when needed
|
|
|
|
nsresult AsyncCall(nsAsyncCallback funcPtr,
|
|
|
|
nsRunnableMethod<nsHttpChannel> **retval = nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool RequestIsConditional();
|
|
|
|
nsresult Connect(PRBool firstTime = PR_TRUE);
|
|
|
|
nsresult AsyncAbort(nsresult status);
|
2007-08-23 11:56:12 -07:00
|
|
|
// Send OnStartRequest/OnStopRequest to our listener, if any.
|
|
|
|
void HandleAsyncNotifyListener();
|
|
|
|
void DoNotifyListener();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult SetupTransaction();
|
|
|
|
nsresult ApplyContentConversions();
|
|
|
|
nsresult CallOnStartRequest();
|
|
|
|
nsresult ProcessResponse();
|
|
|
|
nsresult ProcessNormal();
|
|
|
|
nsresult ProcessNotModified();
|
|
|
|
nsresult ProcessRedirection(PRUint32 httpStatus);
|
2009-05-17 07:22:55 -07:00
|
|
|
PRBool ShouldSSLProxyResponseContinue(PRUint32 httpStatus);
|
2009-04-23 12:49:32 -07:00
|
|
|
nsresult ProcessFailedSSLConnect(PRUint32 httpStatus);
|
2008-09-30 11:34:23 -07:00
|
|
|
nsresult ProcessFallback(PRBool *fallingBack);
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool ResponseWouldVary();
|
|
|
|
|
|
|
|
// redirection specific methods
|
|
|
|
void HandleAsyncRedirect();
|
|
|
|
void HandleAsyncNotModified();
|
2008-09-30 11:34:23 -07:00
|
|
|
void HandleAsyncFallback();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult PromptTempRedirect();
|
2008-11-04 20:35:39 -08:00
|
|
|
nsresult SetupReplacementChannel(nsIURI *, nsIChannel *, PRBool preserveMethod);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// proxy specific methods
|
|
|
|
nsresult ProxyFailover();
|
2007-08-23 11:56:12 -07:00
|
|
|
nsresult DoReplaceWithProxy(nsIProxyInfo *);
|
|
|
|
void HandleAsyncReplaceWithProxy();
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult ResolveProxy();
|
|
|
|
|
|
|
|
// cache specific methods
|
|
|
|
nsresult OpenCacheEntry(PRBool offline, PRBool *delayed);
|
|
|
|
nsresult OpenOfflineCacheEntryForWriting();
|
2008-10-10 09:14:51 -07:00
|
|
|
nsresult GenerateCacheKey(PRUint32 postID, nsACString &key);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult UpdateExpirationTime();
|
|
|
|
nsresult CheckCache();
|
|
|
|
nsresult ShouldUpdateOfflineCacheEntry(PRBool *shouldCacheForOfflineUse);
|
|
|
|
nsresult ReadFromCache();
|
2008-09-09 18:39:38 -07:00
|
|
|
void CloseCacheEntry(PRBool doomOnFailure);
|
2007-03-22 10:30:00 -07:00
|
|
|
void CloseOfflineCacheEntry();
|
|
|
|
nsresult InitCacheEntry();
|
|
|
|
nsresult InitOfflineCacheEntry();
|
|
|
|
nsresult AddCacheEntryHeaders(nsICacheEntryDescriptor *entry);
|
|
|
|
nsresult StoreAuthorizationMetaData(nsICacheEntryDescriptor *entry);
|
|
|
|
nsresult FinalizeCacheEntry();
|
|
|
|
nsresult InstallCacheListener(PRUint32 offset = 0);
|
|
|
|
nsresult InstallOfflineCacheListener();
|
2008-10-10 09:14:51 -07:00
|
|
|
void MaybeInvalidateCacheEntryForSubsequentGet();
|
|
|
|
nsCacheStoragePolicy DetermineStoragePolicy();
|
2009-02-11 20:16:00 -08:00
|
|
|
void AsyncOnExamineCachedResponse();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-31 17:55:14 -07:00
|
|
|
// Handle the bogus Content-Encoding Apache sometimes sends
|
|
|
|
void ClearBogusContentEncodingIfNeeded();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// byte range request specific methods
|
|
|
|
nsresult SetupByteRangeRequest(PRUint32 partialLen);
|
|
|
|
nsresult ProcessPartialContent();
|
|
|
|
nsresult OnDoneReadingPartialCacheEntry(PRBool *streamDone);
|
|
|
|
|
|
|
|
nsresult DoAuthRetry(nsAHttpConnection *);
|
2009-06-16 09:27:17 -07:00
|
|
|
PRBool MustValidateBasedOnQueryUrl();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsISupports> mSecurityInfo;
|
|
|
|
nsCOMPtr<nsICancelable> mProxyRequest;
|
|
|
|
|
|
|
|
nsRefPtr<nsInputStreamPump> mTransactionPump;
|
2010-04-07 01:43:09 -07:00
|
|
|
nsRefPtr<nsHttpTransaction> mTransaction;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-08-12 01:51:46 -07:00
|
|
|
PRUint64 mLogicalOffset;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// cache specific data
|
|
|
|
nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry;
|
|
|
|
nsRefPtr<nsInputStreamPump> mCachePump;
|
2010-04-07 01:43:09 -07:00
|
|
|
nsAutoPtr<nsHttpResponseHead> mCachedResponseHead;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCacheAccessMode mCacheAccess;
|
|
|
|
PRUint32 mPostID;
|
|
|
|
PRUint32 mRequestTime;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICacheEntryDescriptor> mOfflineCacheEntry;
|
|
|
|
nsCacheAccessMode mOfflineCacheAccess;
|
2007-07-24 23:31:27 -07:00
|
|
|
nsCString mOfflineCacheClientID;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-08-26 16:09:02 -07:00
|
|
|
nsCOMPtr<nsIApplicationCache> mApplicationCache;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// auth specific data
|
2010-06-17 11:33:42 -07:00
|
|
|
nsCOMPtr<nsIHttpChannelAuthProvider> mAuthProvider;
|
2009-07-20 11:29:41 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Resumable channel specific data
|
|
|
|
nsCString mEntityID;
|
|
|
|
PRUint64 mStartPos;
|
|
|
|
|
2007-08-23 11:56:12 -07:00
|
|
|
// Function pointer that can be set to indicate that we got suspended while
|
|
|
|
// waiting on an AsyncCall. When we get resumed we should AsyncCall this
|
|
|
|
// function.
|
|
|
|
nsAsyncCallback mPendingAsyncCallOnResume;
|
|
|
|
|
|
|
|
// Proxy info to replace with
|
|
|
|
nsCOMPtr<nsIProxyInfo> mTargetProxyInfo;
|
|
|
|
|
|
|
|
// Suspend counter. This is used if someone tries to suspend/resume us
|
|
|
|
// before we have either a cache pump or a transaction pump.
|
|
|
|
PRUint32 mSuspendCount;
|
|
|
|
|
2008-09-30 11:34:23 -07:00
|
|
|
// If the channel is associated with a cache, and the URI matched
|
|
|
|
// a fallback namespace, this will hold the key for the fallback
|
|
|
|
// cache entry.
|
|
|
|
nsCString mFallbackKey;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// state flags
|
|
|
|
PRUint32 mApplyConversion : 1;
|
|
|
|
PRUint32 mCachedContentIsValid : 1;
|
|
|
|
PRUint32 mCachedContentIsPartial : 1;
|
|
|
|
PRUint32 mCanceled : 1;
|
|
|
|
PRUint32 mTransactionReplaced : 1;
|
|
|
|
PRUint32 mAuthRetryPending : 1;
|
|
|
|
PRUint32 mResuming : 1;
|
|
|
|
PRUint32 mInitedCacheEntry : 1;
|
|
|
|
PRUint32 mCacheForOfflineUse : 1;
|
2008-09-30 11:34:23 -07:00
|
|
|
// True if mCacheForOfflineUse was set because we were caching
|
|
|
|
// opportunistically.
|
|
|
|
PRUint32 mCachingOpportunistically : 1;
|
|
|
|
// True if we are loading a fallback cache entry from the
|
|
|
|
// application cache.
|
|
|
|
PRUint32 mFallbackChannel : 1;
|
2008-11-04 02:20:27 -08:00
|
|
|
PRUint32 mInheritApplicationCache : 1;
|
|
|
|
PRUint32 mChooseApplicationCache : 1;
|
2008-11-05 16:01:08 -08:00
|
|
|
PRUint32 mLoadedFromApplicationCache : 1;
|
2008-08-25 10:21:28 -07:00
|
|
|
PRUint32 mTracingEnabled : 1;
|
2009-10-21 10:34:47 -07:00
|
|
|
// True if consumer added its own If-None-Match or If-Modified-Since
|
2009-10-21 03:18:08 -07:00
|
|
|
// headers. In such a case we must not override them in the cache code
|
|
|
|
// and also we want to pass possible 304 code response through.
|
|
|
|
PRUint32 mCustomConditionalRequest : 1;
|
2010-04-26 16:23:43 -07:00
|
|
|
// True iff this channel is servicing a remote HttpChannelChild
|
|
|
|
PRUint32 mRemoteChannel : 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsContentEncodings : public nsIUTF8StringEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIUTF8STRINGENUMERATOR
|
|
|
|
|
|
|
|
nsContentEncodings(nsIHttpChannel* aChannel, const char* aEncodingHeader);
|
|
|
|
virtual ~nsContentEncodings();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult PrepareForNext(void);
|
|
|
|
|
|
|
|
// We do not own the buffer. The channel owns it.
|
|
|
|
const char* mEncodingHeader;
|
|
|
|
const char* mCurStart; // points to start of current header
|
|
|
|
const char* mCurEnd; // points to end of current header
|
|
|
|
|
|
|
|
// Hold a ref to our channel so that it can't go away and take the
|
|
|
|
// header with it.
|
|
|
|
nsCOMPtr<nsIHttpChannel> mChannel;
|
|
|
|
|
|
|
|
PRPackedBool mReady;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsHttpChannel_h__
|