Bug 1170937 - Set the URL on the Response object created from a fetch() properly if the underlying channel gets redirected; r=baku

This commit is contained in:
Ehsan Akhgari 2015-06-09 15:21:13 -04:00
parent 9c8c24b5db
commit 7b565bd4da
3 changed files with 20 additions and 11 deletions

View File

@ -548,14 +548,16 @@ FetchDriver::ContinueHttpFetchAfterNetworkFetch()
} }
already_AddRefed<InternalResponse> already_AddRefed<InternalResponse>
FetchDriver::BeginAndGetFilteredResponse(InternalResponse* aResponse) FetchDriver::BeginAndGetFilteredResponse(InternalResponse* aResponse, nsIURI* aFinalURI)
{ {
MOZ_ASSERT(aResponse); MOZ_ASSERT(aResponse);
if (!aResponse->FinalURL()) { nsAutoCString reqURL;
nsAutoCString reqURL; if (aFinalURI) {
aFinalURI->GetSpec(reqURL);
} else {
mRequest->GetURL(reqURL); mRequest->GetURL(reqURL);
aResponse->SetUrl(reqURL);
} }
aResponse->SetUrl(reqURL);
// FIXME(nsm): Handle mixed content check, step 7 of fetch. // FIXME(nsm): Handle mixed content check, step 7 of fetch.
@ -584,7 +586,7 @@ FetchDriver::BeginAndGetFilteredResponse(InternalResponse* aResponse)
void void
FetchDriver::BeginResponse(InternalResponse* aResponse) FetchDriver::BeginResponse(InternalResponse* aResponse)
{ {
nsRefPtr<InternalResponse> r = BeginAndGetFilteredResponse(aResponse); nsRefPtr<InternalResponse> r = BeginAndGetFilteredResponse(aResponse, nullptr);
// Release the ref. // Release the ref.
} }
@ -716,9 +718,17 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest,
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest); nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
response->InitChannelInfo(channel); response->InitChannelInfo(channel);
nsCOMPtr<nsIURI> channelURI;
rv = channel->GetURI(getter_AddRefs(channelURI));
if (NS_WARN_IF(NS_FAILED(rv))) {
FailWithNetworkError();
// Cancel request.
return rv;
}
// Resolves fetch() promise which may trigger code running in a worker. Make // Resolves fetch() promise which may trigger code running in a worker. Make
// sure the Response is fully initialized before calling this. // sure the Response is fully initialized before calling this.
mResponse = BeginAndGetFilteredResponse(response); mResponse = BeginAndGetFilteredResponse(response, channelURI);
nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv); nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {

View File

@ -88,8 +88,9 @@ private:
nsresult HttpFetch(bool aCORSFlag = false, bool aCORSPreflightFlag = false, bool aAuthenticationFlag = false); nsresult HttpFetch(bool aCORSFlag = false, bool aCORSPreflightFlag = false, bool aAuthenticationFlag = false);
nsresult ContinueHttpFetchAfterNetworkFetch(); nsresult ContinueHttpFetchAfterNetworkFetch();
// Returns the filtered response sent to the observer. // Returns the filtered response sent to the observer.
// Callers who don't have access to a channel can pass null for aFinalURI.
already_AddRefed<InternalResponse> already_AddRefed<InternalResponse>
BeginAndGetFilteredResponse(InternalResponse* aResponse); BeginAndGetFilteredResponse(InternalResponse* aResponse, nsIURI* aFinalURI);
// Utility since not all cases need to do any post processing of the filtered // Utility since not all cases need to do any post processing of the filtered
// response. // response.
void BeginResponse(InternalResponse* aResponse); void BeginResponse(InternalResponse* aResponse);

View File

@ -27,12 +27,10 @@ skip-if = buildapp == 'b2g' # Bug 1137683
skip-if = buildapp == 'b2g' # Bug 1137683 skip-if = buildapp == 'b2g' # Bug 1137683
[test_fetch_basic_http.html] [test_fetch_basic_http.html]
[test_fetch_basic_http_sw_reroute.html] [test_fetch_basic_http_sw_reroute.html]
skip-if = true # Bug 1170937, need fully support for redirects skip-if = e10s || buildapp == 'b2g' # Bug 1173163 for e10s, bug 1137683 for b2g
#skip-if = buildapp == 'b2g' # Bug 1137683
[test_fetch_cors.html] [test_fetch_cors.html]
[test_fetch_cors_sw_reroute.html] [test_fetch_cors_sw_reroute.html]
skip-if = true # Bug 1170937, need fully support for redirects skip-if = e10s || buildapp == 'b2g' # Bug 1173163 for e10s, bug 1137683 for b2g
#skip-if = buildapp == 'b2g' # Bug 1137683
[test_formdataparsing.html] [test_formdataparsing.html]
[test_formdataparsing_sw_reroute.html] [test_formdataparsing_sw_reroute.html]
skip-if = buildapp == 'b2g' # Bug 1137683 skip-if = buildapp == 'b2g' # Bug 1137683