nsresult InterceptedChannelBase::DoSynthesizeHeader(const nsACString& aName, const nsACString& aValue) { EnsureSynthesizedResponse(); nsAutoCString header = aName + NS_LITERAL_CSTRING(": ") + aValue; // Overwrite any existing header. nsresult rv = (*mSynthesizedResponseHead)->ParseHeaderLine(header); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
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; }
nsresult InterceptedChannelBase::DoSynthesizeStatus(uint16_t aStatus, const nsACString& aReason) { EnsureSynthesizedResponse(); // Always assume HTTP 1.1 for synthesized responses. nsAutoCString statusLine; statusLine.AppendLiteral("HTTP/1.1 "); statusLine.AppendInt(aStatus); statusLine.AppendLiteral(" "); statusLine.Append(aReason); (*mSynthesizedResponseHead)->ParseStatusLine(statusLine.get()); return NS_OK; }
NS_IMETHODIMP InterceptedChannelContent::FinishSynthesizedResponse(const nsACString& aFinalURLSpec) { if (NS_WARN_IF(!mChannel)) { return NS_ERROR_NOT_AVAILABLE; } // Make sure the body 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(); 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 if (mSecureUpgrade) { nsresult rv = NS_GetSecureUpgradedURI(originalURI, getter_AddRefs(responseURI)); NS_ENSURE_SUCCESS(rv, rv); } else { responseURI = originalURI; } bool equal = false; originalURI->Equals(responseURI, &equal); if (!equal) { mChannel->ForceIntercepted(mSynthesizedInput); mChannel->BeginNonIPCRedirect(responseURI, *mSynthesizedResponseHead.ptr()); } else { mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(), mSynthesizedInput, mStreamListener); } mResponseBody = nullptr; mReleaseHandle = nullptr; mChannel = nullptr; mStreamListener = nullptr; return NS_OK; }
NS_IMETHODIMP InterceptedChannelContent::FinishSynthesizedResponse() { if (NS_WARN_IF(!mChannel)) { return NS_ERROR_NOT_AVAILABLE; } EnsureSynthesizedResponse(); mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(), mSynthesizedInput, mStreamListener); mResponseBody = nullptr; mChannel = nullptr; mStreamListener = nullptr; return NS_OK; }
NS_IMETHODIMP InterceptedChannelContent::StartSynthesizedResponse(nsIInputStream* aBody, nsIInterceptedBodyCallback* aBodyCallback, nsICacheInfoChannel* aCacheInfoChannel, const nsACString& aFinalURLSpec, bool aResponseRedirected) { if (NS_WARN_IF(mClosed)) { return NS_ERROR_NOT_AVAILABLE; } EnsureSynthesizedResponse(); 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 if (mSecureUpgrade) { nsresult rv = NS_GetSecureUpgradedURI(originalURI, getter_AddRefs(responseURI)); NS_ENSURE_SUCCESS(rv, rv); } else { responseURI = originalURI; } bool equal = false; originalURI->Equals(responseURI, &equal); if (!equal) { mChannel->ForceIntercepted(aBody, aBodyCallback, aCacheInfoChannel); mChannel->BeginNonIPCRedirect(responseURI, *mSynthesizedResponseHead.ptr(), aResponseRedirected); } else { mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(), aBody, aBodyCallback, mStreamListener, aCacheInfoChannel); } return NS_OK; }
NS_IMETHODIMP InterceptedChannelContent::FinishSynthesizedResponse() { if (NS_WARN_IF(!mChannel)) { return NS_ERROR_NOT_AVAILABLE; } EnsureSynthesizedResponse(); nsresult rv = nsInputStreamPump::Create(getter_AddRefs(mStoragePump), mSynthesizedInput, int64_t(-1), int64_t(-1), 0, 0, true); if (NS_WARN_IF(NS_FAILED(rv))) { mSynthesizedInput->Close(); return rv; } mResponseBody = nullptr; rv = mStoragePump->AsyncRead(mStreamListener, nullptr); NS_ENSURE_SUCCESS(rv, rv); // Intercepted responses should already be decoded. mChannel->SetApplyConversion(false); // 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. int64_t streamLength; uint64_t available; rv = mSynthesizedInput->Available(&available); if (NS_WARN_IF(NS_FAILED(rv))) { streamLength = -1; } else { streamLength = int64_t(available); } mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(), mStoragePump, streamLength); mChannel = nullptr; mStreamListener = nullptr; return NS_OK; }
NS_IMETHODIMP InterceptedChannelContent::FinishSynthesizedResponse(const nsACString& aFinalURLSpec) { if (NS_WARN_IF(!mChannel)) { return NS_ERROR_NOT_AVAILABLE; } EnsureSynthesizedResponse(); 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) { mChannel->ForceIntercepted(mSynthesizedInput); mChannel->BeginNonIPCRedirect(responseURI, *mSynthesizedResponseHead.ptr()); } else { mChannel->OverrideWithSynthesizedResponse(mSynthesizedResponseHead.ref(), mSynthesizedInput, mStreamListener); } mResponseBody = nullptr; mChannel = nullptr; mStreamListener = 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; }