NS_IMETHODIMP InterceptedChannelChrome::FinishSynthesizedResponse() { if (!mChannel) { return NS_ERROR_NOT_AVAILABLE; } EnsureSynthesizedResponse(); // If the synthesized response is a redirect, then we want to respect // the encoding of whatever is loaded as a result. if (WillRedirect(mSynthesizedResponseHead.ref())) { nsresult rv = mChannel->SetApplyConversion(mOldApplyConversion); NS_ENSURE_SUCCESS(rv, rv); } mChannel->MarkIntercepted(); // First we ensure the appropriate metadata is set on the synthesized cache entry // (i.e. the flattened response head) nsCOMPtr<nsISupports> securityInfo; nsresult rv = mChannel->GetSecurityInfo(getter_AddRefs(securityInfo)); NS_ENSURE_SUCCESS(rv, rv); rv = DoAddCacheEntryHeaders(mChannel, mSynthesizedCacheEntry, mChannel->GetRequestHead(), mSynthesizedResponseHead.ref(), securityInfo); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIURI> uri; mChannel->GetURI(getter_AddRefs(uri)); bool usingSSL = false; uri->SchemeIs("https", &usingSSL); // Then we open a real cache entry to read the synthesized response from. rv = mChannel->OpenCacheEntry(usingSSL); NS_ENSURE_SUCCESS(rv, rv); mSynthesizedCacheEntry = nullptr; if (!mChannel->AwaitingCacheCallbacks()) { rv = mChannel->ContinueConnect(); NS_ENSURE_SUCCESS(rv, rv); } mChannel = nullptr; return NS_OK; }
NS_IMETHODIMP InterceptedChannelChrome::FinishSynthesizedResponse(const nsACString& aFinalURLSpec) { if (!mChannel) { return NS_ERROR_NOT_AVAILABLE; } // Make sure the cache entry's output stream is always closed. If the // channel was intercepted with a null-body response then its possible // the synthesis completed without a stream copy operation. mResponseBody->Close(); mReportCollector->FlushConsoleReports(mChannel); EnsureSynthesizedResponse(); // If the synthesized response is a redirect, then we want to respect // the encoding of whatever is loaded as a result. if (WillRedirect(mSynthesizedResponseHead.ref())) { nsresult rv = mChannel->SetApplyConversion(mOldApplyConversion); NS_ENSURE_SUCCESS(rv, rv); } mChannel->MarkIntercepted(); // First we ensure the appropriate metadata is set on the synthesized cache entry // (i.e. the flattened response head) nsCOMPtr<nsISupports> securityInfo; nsresult rv = mChannel->GetSecurityInfo(getter_AddRefs(securityInfo)); NS_ENSURE_SUCCESS(rv, rv); uint32_t expirationTime = 0; rv = DoUpdateExpirationTime(mChannel, mSynthesizedCacheEntry, mSynthesizedResponseHead.ref(), expirationTime); rv = DoAddCacheEntryHeaders(mChannel, mSynthesizedCacheEntry, mChannel->GetRequestHead(), mSynthesizedResponseHead.ref(), securityInfo); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIURI> originalURI; mChannel->GetURI(getter_AddRefs(originalURI)); nsCOMPtr<nsIURI> responseURI; if (!aFinalURLSpec.IsEmpty()) { rv = NS_NewURI(getter_AddRefs(responseURI), aFinalURLSpec); NS_ENSURE_SUCCESS(rv, rv); } else { responseURI = originalURI; } bool equal = false; originalURI->Equals(responseURI, &equal); if (!equal) { rv = mChannel->StartRedirectChannelToURI(responseURI, nsIChannelEventSink::REDIRECT_INTERNAL); NS_ENSURE_SUCCESS(rv, rv); } else { bool usingSSL = false; responseURI->SchemeIs("https", &usingSSL); // Then we open a real cache entry to read the synthesized response from. rv = mChannel->OpenCacheEntry(usingSSL); NS_ENSURE_SUCCESS(rv, rv); mSynthesizedCacheEntry = nullptr; if (!mChannel->AwaitingCacheCallbacks()) { rv = mChannel->ContinueConnect(); NS_ENSURE_SUCCESS(rv, rv); } } mReleaseHandle = nullptr; mChannel = nullptr; return NS_OK; }
NS_IMETHODIMP InterceptedChannelChrome::FinishSynthesizedResponse(const nsACString& aFinalURLSpec) { if (!mChannel) { return NS_ERROR_NOT_AVAILABLE; } EnsureSynthesizedResponse(); // If the synthesized response is a redirect, then we want to respect // the encoding of whatever is loaded as a result. if (WillRedirect(mSynthesizedResponseHead.ref())) { nsresult rv = mChannel->SetApplyConversion(mOldApplyConversion); NS_ENSURE_SUCCESS(rv, rv); } mChannel->MarkIntercepted(); // First we ensure the appropriate metadata is set on the synthesized cache entry // (i.e. the flattened response head) nsCOMPtr<nsISupports> securityInfo; nsresult rv = mChannel->GetSecurityInfo(getter_AddRefs(securityInfo)); NS_ENSURE_SUCCESS(rv, rv); rv = DoAddCacheEntryHeaders(mChannel, mSynthesizedCacheEntry, mChannel->GetRequestHead(), mSynthesizedResponseHead.ref(), securityInfo); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIURI> originalURI; mChannel->GetURI(getter_AddRefs(originalURI)); nsCOMPtr<nsIURI> responseURI; if (!aFinalURLSpec.IsEmpty()) { nsresult rv = NS_NewURI(getter_AddRefs(responseURI), aFinalURLSpec); NS_ENSURE_SUCCESS(rv, rv); } else { responseURI = originalURI; } bool equal = false; originalURI->Equals(responseURI, &equal); if (!equal) { nsresult rv = mChannel->StartRedirectChannelToURI(responseURI, nsIChannelEventSink::REDIRECT_INTERNAL); NS_ENSURE_SUCCESS(rv, rv); } else { bool usingSSL = false; responseURI->SchemeIs("https", &usingSSL); // Then we open a real cache entry to read the synthesized response from. rv = mChannel->OpenCacheEntry(usingSSL); NS_ENSURE_SUCCESS(rv, rv); mSynthesizedCacheEntry = nullptr; if (!mChannel->AwaitingCacheCallbacks()) { rv = mChannel->ContinueConnect(); NS_ENSURE_SUCCESS(rv, rv); } } mChannel = nullptr; return NS_OK; }