From 1d53a870dd6efa618e86d8040c9af84b11b8cc64 Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Sat, 12 Nov 2016 20:20:50 +0300 Subject: [PATCH] fix(http): return request url if it cannot be retrieved from response closes #12837 --- modules/@angular/http/src/backends/xhr_backend.ts | 5 ++--- .../http/test/backends/xhr_backend_spec.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/@angular/http/src/backends/xhr_backend.ts b/modules/@angular/http/src/backends/xhr_backend.ts index 7fedc3def3..df8ba12869 100644 --- a/modules/@angular/http/src/backends/xhr_backend.ts +++ b/modules/@angular/http/src/backends/xhr_backend.ts @@ -75,9 +75,8 @@ export class XHRConnection implements Connection { } const headers: Headers = Headers.fromResponseHeaderString(_xhr.getAllResponseHeaders()); - - const url: string = getResponseURL(_xhr); - + // IE 9 does not provide the way to get URL of response + const url = getResponseURL(_xhr) || req.url; const statusText: string = _xhr.statusText || 'OK'; let responseOptions = new ResponseOptions({body, status, headers, statusText, url}); diff --git a/modules/@angular/http/test/backends/xhr_backend_spec.ts b/modules/@angular/http/test/backends/xhr_backend_spec.ts index 988b74a477..c9a4236436 100644 --- a/modules/@angular/http/test/backends/xhr_backend_spec.ts +++ b/modules/@angular/http/test/backends/xhr_backend_spec.ts @@ -639,6 +639,21 @@ Connection: keep-alive`; existingXHRs[0].dispatchEvent('load'); })); + it('should return request url if it cannot be retrieved from response', + inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { + const statusCode = 200; + const connection = new XHRConnection( + sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode})); + + connection.response.subscribe((res: Response) => { + expect(res.url).toEqual('https://google.com'); + async.done(); + }); + + existingXHRs[0].setStatusCode(statusCode); + existingXHRs[0].dispatchEvent('load'); + })); + it('should set the status text property from the XMLHttpRequest instance if present', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => { const statusText = 'test';