Attachment #8926220: Propagate the URLs from respondWith() if the response's URL is different from the request's and the response has been redirected for bug #1222008

View | Details | Raw Unified | Return to bug 1222008
Collapse All | Expand All

(-)a/dom/workers/ServiceWorkerEvents.cpp (-12 / +8 lines)
Line     Link Here 
 Lines 266-297   public: Link Here 
266
NS_IMPL_ISUPPORTS(BodyCopyHandle, nsIInterceptedBodyCallback)
266
NS_IMPL_ISUPPORTS(BodyCopyHandle, nsIInterceptedBodyCallback)
267
267
268
class StartResponse final : public Runnable
268
class StartResponse final : public Runnable
269
{
269
{
270
  nsMainThreadPtrHandle<nsIInterceptedChannel> mChannel;
270
  nsMainThreadPtrHandle<nsIInterceptedChannel> mChannel;
271
  RefPtr<InternalResponse> mInternalResponse;
271
  RefPtr<InternalResponse> mInternalResponse;
272
  ChannelInfo mWorkerChannelInfo;
272
  ChannelInfo mWorkerChannelInfo;
273
  const nsCString mScriptSpec;
273
  const nsCString mScriptSpec;
274
  const nsCString mResponseURLSpec;
275
  UniquePtr<RespondWithClosure> mClosure;
274
  UniquePtr<RespondWithClosure> mClosure;
276
275
277
public:
276
public:
278
  StartResponse(nsMainThreadPtrHandle<nsIInterceptedChannel>& aChannel,
277
  StartResponse(nsMainThreadPtrHandle<nsIInterceptedChannel>& aChannel,
279
                InternalResponse* aInternalResponse,
278
                InternalResponse* aInternalResponse,
280
                const ChannelInfo& aWorkerChannelInfo,
279
                const ChannelInfo& aWorkerChannelInfo,
281
                const nsACString& aScriptSpec,
280
                const nsACString& aScriptSpec,
282
                const nsACString& aResponseURLSpec,
283
                UniquePtr<RespondWithClosure>&& aClosure)
281
                UniquePtr<RespondWithClosure>&& aClosure)
284
    : Runnable("dom::workers::StartResponse")
282
    : Runnable("dom::workers::StartResponse")
285
    , mChannel(aChannel)
283
    , mChannel(aChannel)
286
    , mInternalResponse(aInternalResponse)
284
    , mInternalResponse(aInternalResponse)
287
    , mWorkerChannelInfo(aWorkerChannelInfo)
285
    , mWorkerChannelInfo(aWorkerChannelInfo)
288
    , mScriptSpec(aScriptSpec)
286
    , mScriptSpec(aScriptSpec)
289
    , mResponseURLSpec(aResponseURLSpec)
290
    , mClosure(Move(aClosure))
287
    , mClosure(Move(aClosure))
291
  {
288
  {
292
  }
289
  }
293
290
294
  NS_IMETHOD
291
  NS_IMETHOD
295
  Run() override
292
  Run() override
296
  {
293
  {
297
    AssertIsOnMainThread();
294
    AssertIsOnMainThread();
 Lines 337-354   public: Link Here 
337
    auto castLoadInfo = static_cast<LoadInfo*>(loadInfo.get());
334
    auto castLoadInfo = static_cast<LoadInfo*>(loadInfo.get());
338
    castLoadInfo->SynthesizeServiceWorkerTainting(mInternalResponse->GetTainting());
335
    castLoadInfo->SynthesizeServiceWorkerTainting(mInternalResponse->GetTainting());
339
336
340
    nsCOMPtr<nsIInputStream> body;
337
    nsCOMPtr<nsIInputStream> body;
341
    mInternalResponse->GetUnfilteredBody(getter_AddRefs(body));
338
    mInternalResponse->GetUnfilteredBody(getter_AddRefs(body));
342
    RefPtr<BodyCopyHandle> copyHandle;
339
    RefPtr<BodyCopyHandle> copyHandle;
343
    copyHandle = new BodyCopyHandle(Move(mClosure));
340
    copyHandle = new BodyCopyHandle(Move(mClosure));
344
341
345
    rv = mChannel->StartSynthesizedResponse(body, copyHandle,
342
    rv =
346
                                            mResponseURLSpec);
343
      mChannel->StartSynthesizedResponse(body, copyHandle,
344
                                         mInternalResponse->GetUnfilteredURL(),
345
                                         mInternalResponse->IsRedirected());
347
    if (NS_WARN_IF(NS_FAILED(rv))) {
346
    if (NS_WARN_IF(NS_FAILED(rv))) {
348
      mChannel->CancelInterception(NS_ERROR_INTERCEPTION_FAILED);
347
      mChannel->CancelInterception(NS_ERROR_INTERCEPTION_FAILED);
349
      return NS_OK;
348
      return NS_OK;
350
    }
349
    }
351
350
352
    nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
351
    nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
353
    if (obsService) {
352
    if (obsService) {
354
      obsService->NotifyObservers(underlyingChannel, "service-worker-synthesized-response", nullptr);
353
      obsService->NotifyObservers(underlyingChannel, "service-worker-synthesized-response", nullptr);
 Lines 653-691   RespondWithHandler::ResolvedCallback(JSC Link Here 
653
      NS_LITERAL_CSTRING("InterceptedUsedResponseWithURL"), mRequestURL);
652
      NS_LITERAL_CSTRING("InterceptedUsedResponseWithURL"), mRequestURL);
654
    return;
653
    return;
655
  }
654
  }
656
655
657
  RefPtr<InternalResponse> ir = response->GetInternalResponse();
656
  RefPtr<InternalResponse> ir = response->GetInternalResponse();
658
  if (NS_WARN_IF(!ir)) {
657
  if (NS_WARN_IF(!ir)) {
659
    return;
658
    return;
660
  }
659
  }
660
661
  // When an opaque response is encountered, we need the original channel's principal
661
  // When an opaque response is encountered, we need the original channel's principal
662
  // to reflect the final URL. Non-opaque responses are either same-origin or CORS-enabled
662
  // to reflect the final URL. Non-opaque responses are either same-origin or CORS-enabled
663
  // cross-origin responses, which are treated as same-origin by consumers.
663
  // cross-origin responses, which are treated as same-origin by consumers.
664
  nsCString responseURL;
664
  if (response->Type() == ResponseType::Opaque &&
665
  if (response->Type() == ResponseType::Opaque) {
665
      NS_WARN_IF(ir->GetUnfilteredURL().IsEmpty())) {
666
    responseURL = ir->GetUnfilteredURL();
666
    return;
667
    if (NS_WARN_IF(responseURL.IsEmpty())) {
668
      return;
669
    }
670
  }
667
  }
671
668
672
  UniquePtr<RespondWithClosure> closure(new RespondWithClosure(mInterceptedChannel,
669
  UniquePtr<RespondWithClosure> closure(new RespondWithClosure(mInterceptedChannel,
673
                                                               mRegistration,
670
                                                               mRegistration,
674
                                                               mRequestURL,
671
                                                               mRequestURL,
675
                                                               mRespondWithScriptSpec,
672
                                                               mRespondWithScriptSpec,
676
                                                               mRespondWithLineNumber,
673
                                                               mRespondWithLineNumber,
677
                                                               mRespondWithColumnNumber));
674
                                                               mRespondWithColumnNumber));
678
675
679
  nsCOMPtr<nsIRunnable> startRunnable = new StartResponse(mInterceptedChannel,
676
  nsCOMPtr<nsIRunnable> startRunnable = new StartResponse(mInterceptedChannel,
680
                                                          ir,
677
                                                          ir,
681
                                                          worker->GetChannelInfo(),
678
                                                          worker->GetChannelInfo(),
682
                                                          mScriptSpec,
679
                                                          mScriptSpec,
683
                                                          responseURL,
684
                                                          Move(closure));
680
                                                          Move(closure));
685
681
686
  nsCOMPtr<nsIInputStream> body;
682
  nsCOMPtr<nsIInputStream> body;
687
  ir->GetUnfilteredBody(getter_AddRefs(body));
683
  ir->GetUnfilteredBody(getter_AddRefs(body));
688
  // Errors and redirects may not have a body.
684
  // Errors and redirects may not have a body.
689
  if (body) {
685
  if (body) {
690
    IgnoredErrorResult error;
686
    IgnoredErrorResult error;
691
    response->SetBodyUsed(aCx, error);
687
    response->SetBodyUsed(aCx, error);
(-)a/netwerk/base/nsINetworkInterceptController.idl (-1 / +6 lines)
Line     Link Here 
 Lines 73-92   interface nsIInterceptedChannel : nsISup Link Here 
73
     *   empty body is assumed.
73
     *   empty body is assumed.
74
     * - A callback may be optionally passed.  It will be invoked
74
     * - A callback may be optionally passed.  It will be invoked
75
     *   when the body is complete.  For a nullptr body this may be
75
     *   when the body is complete.  For a nullptr body this may be
76
     *   synchronously on the current thread.  Otherwise it will be invoked
76
     *   synchronously on the current thread.  Otherwise it will be invoked
77
     *   asynchronously on the current thread.
77
     *   asynchronously on the current thread.
78
     * - The caller may optionally pass a spec for a URL that this response
78
     * - The caller may optionally pass a spec for a URL that this response
79
     *   originates from; an empty string will cause the original
79
     *   originates from; an empty string will cause the original
80
     *   intercepted request's URL to be used instead.
80
     *   intercepted request's URL to be used instead.
81
     * - The redirected flag is false will cause the channel do an internal
82
     *   redirect when the original intercepted reauest's URL is different from
83
     *   the response's URL. The flag is true will cause the chaanel do a real
84
     *   redirect when the URLs are different.
81
     */
85
     */
82
    void startSynthesizedResponse(in nsIInputStream body,
86
    void startSynthesizedResponse(in nsIInputStream body,
83
                                  in nsIInterceptedBodyCallback callback,
87
                                  in nsIInterceptedBodyCallback callback,
84
                                  in ACString finalURLSpec);
88
                                  in ACString finalURLSpec,
89
                                  in bool redirected);
85
90
86
    /**
91
    /**
87
     * Instruct a channel that has been intercepted that response synthesis
92
     * Instruct a channel that has been intercepted that response synthesis
88
     * has completed and all outstanding resources can be closed.
93
     * has completed and all outstanding resources can be closed.
89
     */
94
     */
90
    void finishSynthesizedResponse();
95
    void finishSynthesizedResponse();
91
96
92
    /**
97
    /**
(-)a/netwerk/protocol/http/HttpChannelChild.cpp (-3 / +9 lines)
Line     Link Here 
 Lines 1723-1746   HttpChannelChild::Redirect1Begin(const u Link Here 
1723
  }
1723
  }
1724
1724
1725
  if (NS_FAILED(rv))
1725
  if (NS_FAILED(rv))
1726
    OnRedirectVerifyCallback(rv);
1726
    OnRedirectVerifyCallback(rv);
1727
}
1727
}
1728
1728
1729
void
1729
void
1730
HttpChannelChild::BeginNonIPCRedirect(nsIURI* responseURI,
1730
HttpChannelChild::BeginNonIPCRedirect(nsIURI* responseURI,
1731
                                      const nsHttpResponseHead* responseHead)
1731
                                      const nsHttpResponseHead* responseHead,
1732
                                      const bool aRealRedirect)
1732
{
1733
{
1733
  LOG(("HttpChannelChild::BeginNonIPCRedirect [this=%p]\n", this));
1734
  LOG(("HttpChannelChild::BeginNonIPCRedirect [this=%p]\n", this));
1734
1735
1736
  const uint32_t redirectFlag =
1737
    aRealRedirect ? nsIChannelEventSink::REDIRECT_TEMPORARY
1738
                  : nsIChannelEventSink::REDIRECT_INTERNAL;
1739
1740
1735
  nsCOMPtr<nsIChannel> newChannel;
1741
  nsCOMPtr<nsIChannel> newChannel;
1736
  nsresult rv = SetupRedirect(responseURI,
1742
  nsresult rv = SetupRedirect(responseURI,
1737
                              responseHead,
1743
                              responseHead,
1738
                              nsIChannelEventSink::REDIRECT_INTERNAL,
1744
                              redirectFlag,
1739
                              getter_AddRefs(newChannel));
1745
                              getter_AddRefs(newChannel));
1740
1746
1741
  if (NS_SUCCEEDED(rv)) {
1747
  if (NS_SUCCEEDED(rv)) {
1742
    // Ensure that the new channel shares the original channel's security information,
1748
    // Ensure that the new channel shares the original channel's security information,
1743
    // since it won't be provided via IPC. In particular, if the target of this redirect
1749
    // since it won't be provided via IPC. In particular, if the target of this redirect
1744
    // is a synthesized response that has its own security info, the pre-redirect channel
1750
    // is a synthesized response that has its own security info, the pre-redirect channel
1745
    // has already received it and it must be propagated to the post-redirect channel.
1751
    // has already received it and it must be propagated to the post-redirect channel.
1746
    nsCOMPtr<nsIHttpChannelChild> channelChild = do_QueryInterface(newChannel);
1752
    nsCOMPtr<nsIHttpChannelChild> channelChild = do_QueryInterface(newChannel);
 Lines 1749-1765   HttpChannelChild::BeginNonIPCRedirect(ns Link Here 
1749
      httpChannelChild->OverrideSecurityInfoForNonIPCRedirect(mSecurityInfo);
1755
      httpChannelChild->OverrideSecurityInfoForNonIPCRedirect(mSecurityInfo);
1750
    }
1756
    }
1751
1757
1752
    nsCOMPtr<nsIEventTarget> target = GetNeckoTarget();
1758
    nsCOMPtr<nsIEventTarget> target = GetNeckoTarget();
1753
    MOZ_ASSERT(target);
1759
    MOZ_ASSERT(target);
1754
1760
1755
    rv = gHttpHandler->AsyncOnChannelRedirect(this,
1761
    rv = gHttpHandler->AsyncOnChannelRedirect(this,
1756
                                              newChannel,
1762
                                              newChannel,
1757
                                              nsIChannelEventSink::REDIRECT_INTERNAL,
1763
                                              redirectFlag,
1758
                                              target);
1764
                                              target);
1759
  }
1765
  }
1760
1766
1761
  if (NS_FAILED(rv))
1767
  if (NS_FAILED(rv))
1762
    OnRedirectVerifyCallback(rv);
1768
    OnRedirectVerifyCallback(rv);
1763
}
1769
}
1764
1770
1765
void
1771
void
(-)a/netwerk/protocol/http/HttpChannelChild.h (-1 / +2 lines)
Line     Link Here 
 Lines 427-443   private: Link Here 
427
  // response headers.
427
  // response headers.
428
  MOZ_MUST_USE nsresult SetupRedirect(nsIURI* uri,
428
  MOZ_MUST_USE nsresult SetupRedirect(nsIURI* uri,
429
                                      const nsHttpResponseHead* responseHead,
429
                                      const nsHttpResponseHead* responseHead,
430
                                      const uint32_t& redirectFlags,
430
                                      const uint32_t& redirectFlags,
431
                                      nsIChannel** outChannel);
431
                                      nsIChannel** outChannel);
432
432
433
  // Perform a redirection without communicating with the parent process at all.
433
  // Perform a redirection without communicating with the parent process at all.
434
  void BeginNonIPCRedirect(nsIURI* responseURI,
434
  void BeginNonIPCRedirect(nsIURI* responseURI,
435
                           const nsHttpResponseHead* responseHead);
435
                           const nsHttpResponseHead* responseHead,
436
                           const bool realRedirect);
436
437
437
  // Override the default security info pointer during a non-IPC redirection.
438
  // Override the default security info pointer during a non-IPC redirection.
438
  void OverrideSecurityInfoForNonIPCRedirect(nsISupports* securityInfo);
439
  void OverrideSecurityInfoForNonIPCRedirect(nsISupports* securityInfo);
439
440
440
  // Collect telemetry for the successful rate of OMT.
441
  // Collect telemetry for the successful rate of OMT.
441
  void CollectOMTTelemetry();
442
  void CollectOMTTelemetry();
442
443
443
  // The result of RetargetDeliveryTo for this channel.
444
  // The result of RetargetDeliveryTo for this channel.
(-)a/netwerk/protocol/http/HttpChannelParentListener.cpp (-1 / +1 lines)
Line     Link Here 
 Lines 313-329   public: Link Here 
313
    , mChannel(aChannel)
313
    , mChannel(aChannel)
314
  {
314
  {
315
  }
315
  }
316
316
317
  NS_IMETHOD Run() override
317
  NS_IMETHOD Run() override
318
  {
318
  {
319
    // The URL passed as an argument here doesn't matter, since the child will
319
    // The URL passed as an argument here doesn't matter, since the child will
320
    // receive a redirection notification as a result of this synthesized response.
320
    // receive a redirection notification as a result of this synthesized response.
321
    mChannel->StartSynthesizedResponse(nullptr, nullptr, EmptyCString());
321
    mChannel->StartSynthesizedResponse(nullptr, nullptr, EmptyCString(), false);
322
    mChannel->FinishSynthesizedResponse();
322
    mChannel->FinishSynthesizedResponse();
323
    return NS_OK;
323
    return NS_OK;
324
  }
324
  }
325
};
325
};
326
326
327
NS_IMETHODIMP
327
NS_IMETHODIMP
328
HttpChannelParentListener::ChannelIntercepted(nsIInterceptedChannel* aChannel)
328
HttpChannelParentListener::ChannelIntercepted(nsIInterceptedChannel* aChannel)
329
{
329
{
(-)a/netwerk/protocol/http/InterceptedChannel.cpp (-2 / +6 lines)
Line     Link Here 
 Lines 270-286   InterceptedChannelContent::SynthesizeHea Link Here 
270
  }
270
  }
271
271
272
  return DoSynthesizeHeader(aName, aValue);
272
  return DoSynthesizeHeader(aName, aValue);
273
}
273
}
274
274
275
NS_IMETHODIMP
275
NS_IMETHODIMP
276
InterceptedChannelContent::StartSynthesizedResponse(nsIInputStream* aBody,
276
InterceptedChannelContent::StartSynthesizedResponse(nsIInputStream* aBody,
277
                                                    nsIInterceptedBodyCallback* aBodyCallback,
277
                                                    nsIInterceptedBodyCallback* aBodyCallback,
278
                                                    const nsACString& aFinalURLSpec)
278
                                                    const nsACString& aFinalURLSpec,
279
                                                    bool aRedirected)
279
{
280
{
280
  if (NS_WARN_IF(mClosed)) {
281
  if (NS_WARN_IF(mClosed)) {
281
    return NS_ERROR_NOT_AVAILABLE;
282
    return NS_ERROR_NOT_AVAILABLE;
282
  }
283
  }
283
284
284
  EnsureSynthesizedResponse();
285
  EnsureSynthesizedResponse();
285
286
286
  nsCOMPtr<nsIURI> originalURI;
287
  nsCOMPtr<nsIURI> originalURI;
 Lines 297-313   InterceptedChannelContent::StartSynthesi Link Here 
297
  } else {
298
  } else {
298
    responseURI = originalURI;
299
    responseURI = originalURI;
299
  }
300
  }
300
301
301
  bool equal = false;
302
  bool equal = false;
302
  originalURI->Equals(responseURI, &equal);
303
  originalURI->Equals(responseURI, &equal);
303
  if (!equal) {
304
  if (!equal) {
304
    mChannel->ForceIntercepted(aBody, aBodyCallback);
305
    mChannel->ForceIntercepted(aBody, aBodyCallback);
305
    mChannel->BeginNonIPCRedirect(responseURI, *mSynthesizedResponseHead.ptr());
306
    // If the response has been redirected, do the real redirect. Otherwise, do
307
    // an internal redirect.
308
    mChannel->BeginNonIPCRedirect(responseURI, *mSynthesizedResponseHead.ptr(),
309
                                  aRedirected);
306
  } else {
310
  } else {
307
    mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(),
311
    mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(),
308
                                              aBody, aBodyCallback,
312
                                              aBody, aBodyCallback,
309
                                              mStreamListener);
313
                                              mStreamListener);
310
  }
314
  }
311
315
312
  return NS_OK;
316
  return NS_OK;
313
}
317
}
(-)a/netwerk/protocol/http/InterceptedChannel.h (-1 / +2 lines)
Line     Link Here 
 Lines 177-193   public: Link Here 
177
  InterceptedChannelContent(HttpChannelChild* aChannel,
177
  InterceptedChannelContent(HttpChannelChild* aChannel,
178
                            nsINetworkInterceptController* aController,
178
                            nsINetworkInterceptController* aController,
179
                            InterceptStreamListener* aListener,
179
                            InterceptStreamListener* aListener,
180
                            bool aSecureUpgrade);
180
                            bool aSecureUpgrade);
181
181
182
  NS_IMETHOD ResetInterception() override;
182
  NS_IMETHOD ResetInterception() override;
183
  NS_IMETHOD StartSynthesizedResponse(nsIInputStream* aBody,
183
  NS_IMETHOD StartSynthesizedResponse(nsIInputStream* aBody,
184
                                      nsIInterceptedBodyCallback* aBodyCallback,
184
                                      nsIInterceptedBodyCallback* aBodyCallback,
185
                                      const nsACString& aFinalURLSpec) override;
185
                                      const nsACString& aFinalURLSpec,
186
                                      bool aRedirected) override;
186
  NS_IMETHOD FinishSynthesizedResponse() override;
187
  NS_IMETHOD FinishSynthesizedResponse() override;
187
  NS_IMETHOD GetChannel(nsIChannel** aChannel) override;
188
  NS_IMETHOD GetChannel(nsIChannel** aChannel) override;
188
  NS_IMETHOD GetSecureUpgradedChannelURI(nsIURI** aURI) override;
189
  NS_IMETHOD GetSecureUpgradedChannelURI(nsIURI** aURI) override;
189
  NS_IMETHOD SynthesizeStatus(uint16_t aStatus, const nsACString& aReason) override;
190
  NS_IMETHOD SynthesizeStatus(uint16_t aStatus, const nsACString& aReason) override;
190
  NS_IMETHOD SynthesizeHeader(const nsACString& aName, const nsACString& aValue) override;
191
  NS_IMETHOD SynthesizeHeader(const nsACString& aName, const nsACString& aValue) override;
191
  NS_IMETHOD CancelInterception(nsresult aStatus) override;
192
  NS_IMETHOD CancelInterception(nsresult aStatus) override;
192
  NS_IMETHOD SetChannelInfo(mozilla::dom::ChannelInfo* aChannelInfo) override;
193
  NS_IMETHOD SetChannelInfo(mozilla::dom::ChannelInfo* aChannelInfo) override;
193
  NS_IMETHOD GetInternalContentPolicyType(nsContentPolicyType *aInternalContentPolicyType) override;
194
  NS_IMETHOD GetInternalContentPolicyType(nsContentPolicyType *aInternalContentPolicyType) override;
(-)a/netwerk/protocol/http/InterceptedHttpChannel.cpp (-5 / +8 lines)
Line     Link Here 
 Lines 224-242   InterceptedHttpChannel::FollowSyntheticR Link Here 
224
  if (NS_WARN_IF(NS_FAILED(rv))) {
224
  if (NS_WARN_IF(NS_FAILED(rv))) {
225
    OnRedirectVerifyCallback(rv);
225
    OnRedirectVerifyCallback(rv);
226
  }
226
  }
227
227
228
  return rv;
228
  return rv;
229
}
229
}
230
230
231
nsresult
231
nsresult
232
InterceptedHttpChannel::RedirectForOpaqueResponse(nsIURI* aResponseURI)
232
InterceptedHttpChannel::RedirectForResponse(nsIURI* aResponseURI,
233
                                            const bool aRealRedirect)
233
{
234
{
234
  // Perform an internal redirect to another InterceptedHttpChannel using
235
  // Perform a real/internal redirect to another InterceptedHttpChannel using
235
  // the given cross-origin response URL.  The resulting channel will then
236
  // the given cross-origin response URL.  The resulting channel will then
236
  // process the synthetic response as normal.  This extra redirect is
237
  // process the synthetic response as normal.  This extra redirect is
237
  // performed so that listeners treat the result as unsafe cross-origin
238
  // performed so that listeners treat the result as unsafe cross-origin
238
  // data.
239
  // data.
239
240
240
  nsresult rv = NS_OK;
241
  nsresult rv = NS_OK;
241
242
242
  // We want to pass ownership of the body callback to the new synthesized
243
  // We want to pass ownership of the body callback to the new synthesized
 Lines 248-264   InterceptedHttpChannel::RedirectForOpaqu Link Here 
248
    CreateForSynthesis(mResponseHead, mBodyReader, bodyCallback,
249
    CreateForSynthesis(mResponseHead, mBodyReader, bodyCallback,
249
                       mChannelCreationTime, mChannelCreationTimestamp,
250
                       mChannelCreationTime, mChannelCreationTimestamp,
250
                       mAsyncOpenTime);
251
                       mAsyncOpenTime);
251
252
252
  rv = newChannel->Init(aResponseURI, mCaps,
253
  rv = newChannel->Init(aResponseURI, mCaps,
253
                        static_cast<nsProxyInfo*>(mProxyInfo.get()),
254
                        static_cast<nsProxyInfo*>(mProxyInfo.get()),
254
                        mProxyResolveFlags, mProxyURI, mChannelId);
255
                        mProxyResolveFlags, mProxyURI, mChannelId);
255
256
256
  uint32_t flags = nsIChannelEventSink::REDIRECT_INTERNAL;
257
  uint32_t flags = aRealRedirect ? nsIChannelEventSink::REDIRECT_TEMPORARY
258
                                 : nsIChannelEventSink::REDIRECT_INTERNAL;
257
259
258
  nsCOMPtr<nsILoadInfo> redirectLoadInfo =
260
  nsCOMPtr<nsILoadInfo> redirectLoadInfo =
259
    CloneLoadInfoForRedirect(aResponseURI, flags);
261
    CloneLoadInfoForRedirect(aResponseURI, flags);
260
  newChannel->SetLoadInfo(redirectLoadInfo);
262
  newChannel->SetLoadInfo(redirectLoadInfo);
261
  NS_ENSURE_SUCCESS(rv, rv);
263
  NS_ENSURE_SUCCESS(rv, rv);
262
264
263
  rv = SetupReplacementChannel(aResponseURI, newChannel, true, flags);
265
  rv = SetupReplacementChannel(aResponseURI, newChannel, true, flags);
264
  NS_ENSURE_SUCCESS(rv, rv);
266
  NS_ENSURE_SUCCESS(rv, rv);
 Lines 712-728   InterceptedHttpChannel::SynthesizeHeader Link Here 
712
  nsresult rv = mSynthesizedResponseHead->ParseHeaderLine(header);
714
  nsresult rv = mSynthesizedResponseHead->ParseHeaderLine(header);
713
  NS_ENSURE_SUCCESS(rv, rv);
715
  NS_ENSURE_SUCCESS(rv, rv);
714
  return NS_OK;
716
  return NS_OK;
715
}
717
}
716
718
717
NS_IMETHODIMP
719
NS_IMETHODIMP
718
InterceptedHttpChannel::StartSynthesizedResponse(nsIInputStream* aBody,
720
InterceptedHttpChannel::StartSynthesizedResponse(nsIInputStream* aBody,
719
                                                 nsIInterceptedBodyCallback* aBodyCallback,
721
                                                 nsIInterceptedBodyCallback* aBodyCallback,
720
                                                 const nsACString& aFinalURLSpec)
722
                                                 const nsACString& aFinalURLSpec,
723
                                                 bool aRedirected)
721
{
724
{
722
  nsresult rv = NS_OK;
725
  nsresult rv = NS_OK;
723
726
724
  auto autoCleanup = MakeScopeExit([&] {
727
  auto autoCleanup = MakeScopeExit([&] {
725
    // Auto-cancel on failure.  Do this first to get mStatus set, if necessary.
728
    // Auto-cancel on failure.  Do this first to get mStatus set, if necessary.
726
    if (NS_FAILED(rv)) {
729
    if (NS_FAILED(rv)) {
727
      Cancel(rv);
730
      Cancel(rv);
728
    }
731
    }
 Lines 778-794   InterceptedHttpChannel::StartSynthesized Link Here 
778
    NS_ENSURE_SUCCESS(rv, rv);
781
    NS_ENSURE_SUCCESS(rv, rv);
779
  } else {
782
  } else {
780
    responseURI = mURI;
783
    responseURI = mURI;
781
  }
784
  }
782
785
783
  bool equal = false;
786
  bool equal = false;
784
  Unused << mURI->Equals(responseURI, &equal);
787
  Unused << mURI->Equals(responseURI, &equal);
785
  if (!equal) {
788
  if (!equal) {
786
    rv = RedirectForOpaqueResponse(responseURI);
789
    rv = RedirectForResponse(responseURI, aRedirected);
787
    NS_ENSURE_SUCCESS(rv, rv);
790
    NS_ENSURE_SUCCESS(rv, rv);
788
791
789
    return NS_OK;
792
    return NS_OK;
790
  }
793
  }
791
794
792
  rv = StartPump();
795
  rv = StartPump();
793
  NS_ENSURE_SUCCESS(rv, rv);
796
  NS_ENSURE_SUCCESS(rv, rv);
794
797
(-)a/netwerk/protocol/http/InterceptedHttpChannel.h (-1 / +4 lines)
Line     Link Here 
 Lines 108-125   private: Link Here 
108
  AsyncOpenInternal();
108
  AsyncOpenInternal();
109
109
110
  bool
110
  bool
111
  ShouldRedirect() const;
111
  ShouldRedirect() const;
112
112
113
  nsresult
113
  nsresult
114
  FollowSyntheticRedirect();
114
  FollowSyntheticRedirect();
115
115
116
  // If the response's URL is different from the request's, do a real redirect
117
  // while the response has not been redirected yet. Otherwise, do an internal
118
  // redirect.
116
  nsresult
119
  nsresult
117
  RedirectForOpaqueResponse(nsIURI* aResponseURI);
120
  RedirectForResponse(nsIURI* aResponseURI, const bool aRealRedirect);
118
121
119
  nsresult
122
  nsresult
120
  StartPump();
123
  StartPump();
121
124
122
  nsresult
125
  nsresult
123
  OpenRedirectChannel();
126
  OpenRedirectChannel();
124
127
125
  void
128
  void

Return to bug 1222008