Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(http): return request url if it cannot be retrieved from response #12837

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions modules/@angular/http/src/backends/xhr_backend.ts
Expand Up @@ -60,7 +60,8 @@ export class XHRConnection implements Connection {
if (typeof body === 'string') body = body.replace(XSSI_PREFIX, '');
const headers = Headers.fromResponseHeaderString(_xhr.getAllResponseHeaders());

const url = getResponseURL(_xhr);
// IE 9 does not provide the way to get URL of response
const url: string = getResponseURL(_xhr) || req.url;

// normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
let status: number = _xhr.status === 1223 ? 204 : _xhr.status;
Expand Down Expand Up @@ -161,7 +162,7 @@ export class XHRConnection implements Connection {
_xhr.setRequestHeader('content-type', 'text/plain');
break;
case ContentType.BLOB:
let blob = req.blob();
const blob = req.blob();
if (blob.type) {
_xhr.setRequestHeader('content-type', blob.type);
}
Expand Down
15 changes: 15 additions & 0 deletions modules/@angular/http/test/backends/xhr_backend_spec.ts
Expand Up @@ -623,6 +623,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';
Expand Down