Bug 1169613 - Use content type of synthesized response for JAR channel requests if available. Part 1: Set Content-Type of synthesized reponses for JAR channel requests. r=jdm
authorFernando Jimenez <ferjmoreno@gmail.com>
Fri, 05 Jun 2015 12:53:58 +0200
changeset 247345 bf8a4b45e3da9b89188529b57b2d93b4b0294748
parent 247344 f0b790cb82196b2ac78edb133b171036453a5331
child 247346 99fc1ca23701c27fe0e85764f9c9947cd59530a6
push id60681
push userferjmoreno@gmail.com
push dateFri, 05 Jun 2015 10:54:12 +0000
treeherdermozilla-inbound@52256ba02d2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1169613
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1169613 - Use content type of synthesized response for JAR channel requests if available. Part 1: Set Content-Type of synthesized reponses for JAR channel requests. r=jdm
modules/libjar/InterceptedJARChannel.cpp
modules/libjar/InterceptedJARChannel.h
modules/libjar/nsJARChannel.cpp
modules/libjar/nsJARChannel.h
--- a/modules/libjar/InterceptedJARChannel.cpp
+++ b/modules/libjar/InterceptedJARChannel.cpp
@@ -63,27 +63,30 @@ InterceptedJARChannel::SynthesizeStatus(
 {
   return NS_OK;
 }
 
 NS_IMETHODIMP
 InterceptedJARChannel::SynthesizeHeader(const nsACString& aName,
                                         const nsACString& aValue)
 {
+  if (aName.LowerCaseEqualsLiteral("content-type")) {
+    mContentType = aValue;
+  }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 InterceptedJARChannel::FinishSynthesizedResponse()
 {
   if (NS_WARN_IF(!mChannel)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
-  mChannel->OverrideWithSynthesizedResponse(mSynthesizedInput);
+  mChannel->OverrideWithSynthesizedResponse(mSynthesizedInput, mContentType);
 
   mResponseBody = nullptr;
   mChannel = nullptr;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 InterceptedJARChannel::Cancel()
--- a/modules/libjar/InterceptedJARChannel.h
+++ b/modules/libjar/InterceptedJARChannel.h
@@ -36,16 +36,19 @@ class InterceptedJARChannel : public nsI
   nsRefPtr<nsJARChannel> mChannel;
 
   // Reader-side of the synthesized response body.
   nsCOMPtr<nsIInputStream> mSynthesizedInput;
 
   // The stream to write the body of the synthesized response.
   nsCOMPtr<nsIOutputStream> mResponseBody;
 
+  // The content type of the synthesized response.
+  nsCString mContentType;
+
   // Wether this intercepted channel was performing a navigation.
   bool mIsNavigation;
 
   virtual ~InterceptedJARChannel() {};
 public:
   InterceptedJARChannel(nsJARChannel* aChannel,
                         nsINetworkInterceptController* aController,
                         bool aIsNavigation);
--- a/modules/libjar/nsJARChannel.cpp
+++ b/modules/libjar/nsJARChannel.cpp
@@ -891,17 +891,18 @@ void nsJARChannel::ResetInterception()
     LOG(("nsJARChannel::ResetInterception [this=%x]\n", this));
 
     // Continue with the original request.
     nsresult rv = ContinueAsyncOpen();
     NS_ENSURE_SUCCESS_VOID(rv);
 }
 
 void
-nsJARChannel::OverrideWithSynthesizedResponse(nsIInputStream* aSynthesizedInput)
+nsJARChannel::OverrideWithSynthesizedResponse(nsIInputStream* aSynthesizedInput,
+                                              const nsACString& aContentType)
 {
     // In our current implementation, the FetchEvent handler will copy the
     // response stream completely into the pipe backing the input stream so we
     // can treat the available as the length of the stream.
     uint64_t available;
     nsresult rv = aSynthesizedInput->Available(&available);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       mSynthesizedStreamLength = -1;
@@ -912,16 +913,18 @@ nsJARChannel::OverrideWithSynthesizedRes
     rv = nsInputStreamPump::Create(getter_AddRefs(mSynthesizedResponsePump),
                                    aSynthesizedInput,
                                    int64_t(-1), int64_t(-1), 0, 0, true);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       aSynthesizedInput->Close();
       return;
     }
 
+    SetContentType(aContentType);
+
     FinishAsyncOpen();
 
     rv = mSynthesizedResponsePump->AsyncRead(this, nullptr);
     NS_ENSURE_SUCCESS_VOID(rv);
 }
 
 NS_IMETHODIMP
 nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
--- a/modules/libjar/nsJARChannel.h
+++ b/modules/libjar/nsJARChannel.h
@@ -86,17 +86,18 @@ private:
     nsresult ContinueAsyncOpen();
     void FinishAsyncOpen();
 
     // Discard the prior interception and continue with the original network
     // request.
     void ResetInterception();
     // Override this channel's pending response with a synthesized one. The
     // content will be asynchronously read from the pump.
-    void OverrideWithSynthesizedResponse(nsIInputStream* aSynthesizedInput);
+    void OverrideWithSynthesizedResponse(nsIInputStream* aSynthesizedInput,
+                                         const nsACString& aContentType);
 
     nsCString                       mSpec;
 
     bool                            mOpened;
 
     nsCOMPtr<nsIJARURI>             mJarURI;
     nsCOMPtr<nsIURI>                mOriginalURI;
     nsCOMPtr<nsIURI>                mAppURI;