Bug 570867 - e10s http: add cookies to request in child, not parent [r=dwitte]

This commit is contained in:
Benjamin Stover 2010-06-15 16:07:10 -07:00
Родитель 01ec63785a
Коммит dfb55c48d4
6 изменённых файлов: 83 добавлений и 49 удалений

Просмотреть файл

@ -940,6 +940,42 @@ HttpBaseChannel::AdjustPriority(PRInt32 delta)
//------------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------
// HttpBaseChannel helpers
//-----------------------------------------------------------------------------
void
HttpBaseChannel::AddCookiesToRequest()
{
if (mLoadFlags & LOAD_ANONYMOUS) {
return;
}
nsXPIDLCString cookie;
nsICookieService *cs = gHttpHandler->GetCookieService();
if (cs) {
cs->GetCookieStringFromHttp(mURI,
mDocumentURI ? mDocumentURI : mOriginalURI,
this,
getter_Copies(cookie));
}
if (cookie.IsEmpty()) {
cookie = mUserSetCookieHeader;
}
else if (!mUserSetCookieHeader.IsEmpty()) {
cookie.Append(NS_LITERAL_CSTRING("; ") + mUserSetCookieHeader);
}
// overwrite any existing cookie headers. be sure to clear any
// existing cookies if we have no cookies to set or if the cookie
// service is unavailable.
SetRequestHeader(nsDependentCString(nsHttp::Cookie), cookie, PR_FALSE);
}
//------------------------------------------------------------------------------
} // namespace net
} // namespace mozilla

Просмотреть файл

@ -167,6 +167,8 @@ public:
NS_IMETHOD AdjustPriority(PRInt32 delta);
protected:
void AddCookiesToRequest();
// Helper function to simplify getting notification callbacks.
template <class T>
void GetCallback(nsCOMPtr<T> &aResult)
@ -195,6 +197,7 @@ protected:
nsCString mSpec; // ASCII encoded URL spec
nsCString mContentTypeHint;
nsCString mContentCharsetHint;
nsCString mUserSetCookieHeader;
nsresult mStatus;
PRUint32 mLoadFlags;

Просмотреть файл

@ -111,7 +111,7 @@ HttpChannelChild::RecvOnStartRequest(const nsHttpResponseHead& responseHead)
mResponseHead = new nsHttpResponseHead(responseHead);
nsresult rv = mListener->OnStartRequest(this, mListenerContext);
if (!NS_SUCCEEDED(rv)) {
if (NS_FAILED(rv)) {
// TODO: Cancel request: (bug 536317)
// - Send Cancel msg to parent
// - drop any in flight OnDataAvail msgs we receive
@ -119,6 +119,9 @@ HttpChannelChild::RecvOnStartRequest(const nsHttpResponseHead& responseHead)
// - return true here, not false
return false;
}
SetCookie(mResponseHead->PeekHeader(nsHttp::Set_Cookie));
return true;
}
@ -141,14 +144,14 @@ HttpChannelChild::RecvOnDataAvailable(const nsCString& data,
data.get(),
count,
NS_ASSIGNMENT_DEPEND);
if (!NS_SUCCEEDED(rv)) {
if (NS_FAILED(rv)) {
// TODO: what to do here? Cancel request? Very unlikely to fail.
return false;
}
rv = mListener->OnDataAvailable(this, mListenerContext,
stringStream, offset, count);
stringStream->Close();
if (!NS_SUCCEEDED(rv)) {
if (NS_FAILED(rv)) {
// TODO: Cancel request: see OnStartRequest. Bug 536317
return false;
}
@ -175,7 +178,7 @@ HttpChannelChild::RecvOnStopRequest(const nsresult& statusCode)
// Corresponding AddRef in AsyncOpen().
this->Release();
if (!NS_SUCCEEDED(rv)) {
if (NS_FAILED(rv)) {
// TODO: Cancel request: see OnStartRequest (bug 536317)
return false;
}
@ -292,7 +295,7 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
mUploadStream->Available(&bytes);
if (bytes > 0) {
rv = NS_ReadInputStreamToString(mUploadStream, uploadStreamData, bytes);
if (!NS_SUCCEEDED(rv))
if (NS_FAILED(rv))
return rv;
}
@ -302,7 +305,12 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext)
uploadStreamInfo = eUploadStream_null;
}
// FIXME bug 562587: need to dupe nsHttpChannel::AsyncOpen cookies logic
const char *cookieHeader = mRequestHead.PeekHeader(nsHttp::Cookie);
if (cookieHeader) {
mUserSetCookieHeader = cookieHeader;
}
AddCookiesToRequest();
//
// NOTE: From now on we must return NS_OK; all errors must be handled via
@ -389,7 +397,6 @@ HttpChannelChild::SetupFallbackChannel(const char *aFallbackKey)
DROP_DEAD();
}
//-----------------------------------------------------------------------------
// HttpChannelChild::nsICachingChannel
//-----------------------------------------------------------------------------

Просмотреть файл

@ -123,7 +123,7 @@ HttpChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
return false; // TODO: cancel request (bug 536317), return true
nsHttpChannel *httpChan = static_cast<nsHttpChannel *>(mChannel.get());
httpChan->SetRemoteChannel();
httpChan->SetRemoteChannel(true);
if (originalUri)
httpChan->SetOriginalURI(originalUri);
@ -134,10 +134,11 @@ HttpChannelParent::RecvAsyncOpen(const IPC::URI& aURI,
if (loadFlags != nsIRequest::LOAD_NORMAL)
httpChan->SetLoadFlags(loadFlags);
for (PRUint32 i = 0; i < requestHeaders.Length(); i++)
for (PRUint32 i = 0; i < requestHeaders.Length(); i++) {
httpChan->SetRequestHeader(requestHeaders[i].mHeader,
requestHeaders[i].mValue,
requestHeaders[i].mMerge);
}
httpChan->SetNotificationCallbacks(this);

Просмотреть файл

@ -115,6 +115,7 @@ nsHttpChannel::nsHttpChannel()
, mLoadedFromApplicationCache(PR_FALSE)
, mTracingEnabled(PR_TRUE)
, mCustomConditionalRequest(PR_FALSE)
, mRemoteChannel(PR_FALSE)
{
LOG(("Creating nsHttpChannel [this=%p]\n", this));
}
@ -559,32 +560,6 @@ nsHttpChannel::SetupTransaction()
return rv;
}
void
nsHttpChannel::AddCookiesToRequest()
{
if (mLoadFlags & LOAD_ANONYMOUS) {
return;
}
nsXPIDLCString cookie;
nsICookieService *cs = gHttpHandler->GetCookieService();
if (cs)
cs->GetCookieStringFromHttp(mURI,
mDocumentURI ? mDocumentURI : mOriginalURI,
this,
getter_Copies(cookie));
if (cookie.IsEmpty())
cookie = mUserSetCookieHeader;
else if (!mUserSetCookieHeader.IsEmpty())
cookie.Append(NS_LITERAL_CSTRING("; ") + mUserSetCookieHeader);
// overwrite any existing cookie headers. be sure to clear any
// existing cookies if we have no cookies to set or if the cookie
// service is unavailable.
mRequestHead.SetHeader(nsHttp::Cookie, cookie, PR_FALSE);
}
nsresult
nsHttpChannel::ApplyContentConversions()
{
@ -848,9 +823,12 @@ nsHttpChannel::ProcessResponse()
// notify "http-on-examine-response" observers
gHttpHandler->OnExamineResponse(this);
// set cookies, if any exist; done after OnExamineResponse to allow those
// observers to modify the cookie response headers
SetCookie(mResponseHead->PeekHeader(nsHttp::Set_Cookie));
if (!mRemoteChannel) {
// For non-remote channels, we are responsible for cookies.
// Set cookies, if any exist; done after OnExamineResponse to allow those
// observers to modify the cookie response headers.
SetCookie(mResponseHead->PeekHeader(nsHttp::Set_Cookie));
}
// handle unused username and password in url (see bug 232567)
if (httpStatus != 401 && httpStatus != 407) {
@ -2712,6 +2690,9 @@ nsHttpChannel::SetupReplacementChannel(nsIURI *newURI,
// convey the new redirection limit
httpChannel->SetRedirectionLimit(mRedirectionLimit - 1);
nsHttpChannel *httpChannelImpl = static_cast<nsHttpChannel*>(httpChannel.get());
httpChannelImpl->SetRemoteChannel(mRemoteChannel);
nsCOMPtr<nsIHttpChannelInternal> httpInternal = do_QueryInterface(newChannel);
if (httpInternal) {
// convey the mForceAllowThirdPartyCookie flag
@ -4124,13 +4105,17 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
}
}
// Remember the cookie header that was set, if any
const char *cookieHeader = mRequestHead.PeekHeader(nsHttp::Cookie);
if (cookieHeader)
mUserSetCookieHeader = cookieHeader;
if (!mRemoteChannel) {
// For non-remote channels, we are responsible for cookies.
// fetch cookies, and add them to the request header
AddCookiesToRequest();
// Remember the cookie header that was set, if any
const char *cookieHeader = mRequestHead.PeekHeader(nsHttp::Cookie);
if (cookieHeader) {
mUserSetCookieHeader = cookieHeader;
}
AddCookiesToRequest();
}
// notify "http-on-modify-request" observers
gHttpHandler->OnModifyRequest(this);
@ -4937,7 +4922,11 @@ nsHttpChannel::DoAuthRetry(nsAHttpConnection *conn)
// fetch cookies, and add them to the request header.
// the server response could have included cookies that must be sent with
// this authentication attempt (bug 84794).
AddCookiesToRequest();
// TODO: save cookies from auth response and send them here (bug 572151).
if (!mRemoteChannel) {
// For non-remote channels, we are responsible for cookies.
AddCookiesToRequest();
}
// notify "http-on-modify-request" observers
gHttpHandler->OnModifyRequest(this);

Просмотреть файл

@ -123,7 +123,7 @@ public:
public: /* internal necko use only */
typedef void (nsHttpChannel:: *nsAsyncCallback)(void);
nsHttpResponseHead * GetResponseHead() const { return mResponseHead; }
void SetRemoteChannel() { mRemoteChannel = 1; }
void SetRemoteChannel(bool aRemote) { mRemoteChannel = aRemote; }
void InternalSetUploadStream(nsIInputStream *uploadStream)
{ mUploadStream = uploadStream; }
void SetUploadStreamHasHeaders(PRBool hasHeaders)
@ -152,7 +152,6 @@ private:
void HandleAsyncNotifyListener();
void DoNotifyListener();
nsresult SetupTransaction();
void AddCookiesToRequest();
nsresult ApplyContentConversions();
nsresult CallOnStartRequest();
nsresult ProcessResponse();
@ -251,7 +250,6 @@ private:
nsRefPtr<nsHttpTransaction> mTransaction;
PRUint64 mLogicalOffset;
nsCString mUserSetCookieHeader;
// cache specific data
nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry;