From 6ffaec381efa909fe9c3fa12b76dcc2c49345259 Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Wed, 13 Jun 2001 05:48:44 +0000 Subject: [PATCH] Fixes bug 35956 "file extension not changed but gzipped files expanded when saving" r=gagan, sr=dougt, a=asa git-svn-id: svn://10.0.0.236/trunk@97041 18797224-902f-48f8-a5cc-f745e15eee43 --- .../protocol/http/src/nsHttpChannel.cpp | 40 ++++++++++++++----- .../netwerk/protocol/http/src/nsHttpChannel.h | 2 +- .../netwerk/protocol/http/src/nsHttpHandler.h | 5 ++- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp index 945e0690507..2c55b846e84 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHttpChannel.cpp @@ -324,18 +324,21 @@ nsHttpChannel::SetupTransaction() return mTransaction->SetupRequest(&mRequestHead, mUploadStream); } -nsresult +void nsHttpChannel::ApplyContentConversions() { + if (!mResponseHead) + return; + LOG(("nsHttpChannel::ApplyContentConversions [this=%x]\n", this)); if (!mApplyConversion) { LOG(("not applying conversion per mApplyConversion\n")); - return NS_OK; + return; } const char *val = mResponseHead->PeekHeader(nsHttp::Content_Encoding); - if (val) { + if (val && PL_strcasestr(nsHttpHandler::get()->AcceptEncodings(), val)) { nsCOMPtr serv; nsresult rv = nsHttpHandler::get()-> GetStreamConverterService(getter_AddRefs(serv)); @@ -355,7 +358,6 @@ nsHttpChannel::ApplyContentConversions() } } } - return NS_OK; } nsresult @@ -427,8 +429,17 @@ nsHttpChannel::ProcessNormal() LOG(("nsHttpChannel::ProcessNormal [this=%x]\n", this)); - // install stream converter if required - ApplyContentConversions(); + // For .gz files, apache sends both a Content-Type: application/x-gzip + // as well as Content-Encoding: gzip, which is completely wrong. In + // this case, we choose to ignore the rogue Content-Encoding header. We + // must do this early on so as to prevent it from being seen up stream. + const char *encoding = mResponseHead->PeekHeader(nsHttp::Content_Encoding); + if (encoding && PL_strcasestr(encoding, "gzip") && ( + !PL_strcmp(mResponseHead->ContentType(), APPLICATION_GZIP) || + !PL_strcmp(mResponseHead->ContentType(), APPLICATION_GZIP2))) { + // clear the Content-Encoding header + mResponseHead->SetHeader(nsHttp::Content_Encoding, nsnull); + } // install cache listener if we still have a cache entry open if (mCacheEntry) { @@ -440,7 +451,12 @@ nsHttpChannel::ProcessNormal() rv = nsHttpHandler::get()->OnExamineResponse(this); NS_ASSERTION(NS_SUCCEEDED(rv), "OnExamineResponse failed"); - return mListener->OnStartRequest(this, mListenerContext); + rv = mListener->OnStartRequest(this, mListenerContext); + if (NS_FAILED(rv)) return rv; + + // install stream converter if required + ApplyContentConversions(); + return NS_OK; } //----------------------------------------------------------------------------- @@ -866,9 +882,6 @@ nsHttpChannel::ReadFromCache() mCachedResponseHead = 0; } - // install stream converter if required - ApplyContentConversions(); - // if we don't already have security info, try to get it from the cache // entry. there are two cases to consider here: 1) we are just reading // from the cache, or 2) this may be due to a 304 not modified response, @@ -2045,7 +2058,12 @@ nsHttpChannel::OnStartRequest(nsIRequest *request, nsISupports *ctxt) } // there won't be a response head if we've been cancelled - return mListener->OnStartRequest(this, mListenerContext); + nsresult rv = mListener->OnStartRequest(this, mListenerContext); + if (NS_FAILED(rv)) return rv; + + // install stream converter if required + ApplyContentConversions(); + return NS_OK; } NS_IMETHODIMP diff --git a/mozilla/netwerk/protocol/http/src/nsHttpChannel.h b/mozilla/netwerk/protocol/http/src/nsHttpChannel.h index e2d31b60f76..2de71a0e8a9 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpChannel.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpChannel.h @@ -82,7 +82,7 @@ private: nsresult Connect(PRBool firstTime = PR_TRUE); nsresult AsyncAbort(nsresult status); nsresult SetupTransaction(); - nsresult ApplyContentConversions(); + void ApplyContentConversions(); nsresult ProcessResponse(); nsresult ProcessNormal(); nsresult ProcessNotModified(); diff --git a/mozilla/netwerk/protocol/http/src/nsHttpHandler.h b/mozilla/netwerk/protocol/http/src/nsHttpHandler.h index c1eb7def801..09d229be603 100644 --- a/mozilla/netwerk/protocol/http/src/nsHttpHandler.h +++ b/mozilla/netwerk/protocol/http/src/nsHttpHandler.h @@ -84,8 +84,9 @@ public: PRUint32 capabilities); const char *UserAgent(); - nsHttpVersion DefaultVersion() { return (nsHttpVersion) mHttpVersion; } - PRUint32 ReferrerLevel() { return mReferrerLevel; } + nsHttpVersion DefaultVersion() { return (nsHttpVersion) mHttpVersion; } + PRUint32 ReferrerLevel() { return mReferrerLevel; } + const char *AcceptEncodings() { return mAcceptEncodings; } nsHttpAuthCache *AuthCache() { return mAuthCache; }