feat(http): added withCredentials support
Taken into account the withCredentials property within the request options: - added corresponding property in the RequestOptions class - added corresponding property in the Request class - handle this property when merging options - set the withCredentials property on the XHR object when specified Added a test in the xhr_backend_spec.ts to check that the property is actually set on the XHR object Closes https://github.com/angular/http/issues/65 Closes #7281 Closes #7281
This commit is contained in:
committed by
Misko Hevery
parent
0f0a8ade7c
commit
95af14b97c
@@ -42,6 +42,7 @@ class MockBrowserXHR extends BrowserXhr {
|
||||
responseHeaders: string;
|
||||
responseURL: string;
|
||||
statusText: string;
|
||||
withCredentials: boolean;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -511,6 +512,26 @@ export function main() {
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
|
||||
it('should set withCredentials to true when defined in request options for CORS situations',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
var statusCode = 200;
|
||||
sampleRequest.withCredentials = true;
|
||||
var mockXhr = new MockBrowserXHR();
|
||||
var connection =
|
||||
new XHRConnection(sampleRequest, mockXhr, new ResponseOptions({status: statusCode}));
|
||||
var responseHeaders = `X-Request-URL: http://somedomain.com
|
||||
Foo: Bar`
|
||||
|
||||
connection.response.subscribe((res: Response) => {
|
||||
expect(res.url).toEqual('http://somedomain.com');
|
||||
expect(existingXHRs[0].withCredentials).toBeTruthy();
|
||||
async.done();
|
||||
});
|
||||
|
||||
existingXHRs[0].setResponseHeaders(responseHeaders);
|
||||
existingXHRs[0].setStatusCode(statusCode);
|
||||
existingXHRs[0].dispatchEvent('load');
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user