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:
Thierry Templier
2016-02-24 22:57:35 +01:00
committed by Misko Hevery
parent 0f0a8ade7c
commit 95af14b97c
6 changed files with 40 additions and 4 deletions

View File

@ -52,7 +52,11 @@ export class RequestOptions {
* Search parameters to be included in a {@link Request}.
*/
search: URLSearchParams;
constructor({method, headers, body, url, search}: RequestOptionsArgs = {}) {
/**
* Enable use credentials for a {@link Request}.
*/
withCredentials: boolean;
constructor({method, headers, body, url, search, withCredentials}: RequestOptionsArgs = {}) {
this.method = isPresent(method) ? normalizeMethodName(method) : null;
this.headers = isPresent(headers) ? headers : null;
this.body = isPresent(body) ? body : null;
@ -60,6 +64,7 @@ export class RequestOptions {
this.search = isPresent(search) ? (isString(search) ? new URLSearchParams(<string>(search)) :
<URLSearchParams>(search)) :
null;
this.withCredentials = isPresent(withCredentials) ? withCredentials : null;
}
/**
@ -96,7 +101,10 @@ export class RequestOptions {
search: isPresent(options) && isPresent(options.search) ?
(isString(options.search) ? new URLSearchParams(<string>(options.search)) :
(<URLSearchParams>(options.search)).clone()) :
this.search
this.search,
withCredentials: isPresent(options) && isPresent(options.withCredentials) ?
options.withCredentials :
this.withCredentials
});
}
}