feat(common): on-by-default XSRF support in HttpClient (#18108)
Fixes #18100
This commit is contained in:

committed by
Igor Minar

parent
3d85f72652
commit
dd04f09483
@ -13,6 +13,7 @@
|
||||
*/
|
||||
export * from './location/index';
|
||||
export {NgLocaleLocalization, NgLocalization} from './localization';
|
||||
export {parseCookieValue as ɵparseCookieValue} from './cookie';
|
||||
export {CommonModule} from './common_module';
|
||||
export {NgClass, NgFor, NgForOf, NgForOfContext, NgIf, NgIfContext, NgPlural, NgPluralCase, NgStyle, NgSwitch, NgSwitchCase, NgSwitchDefault, NgTemplateOutlet, NgComponentOutlet} from './directives/index';
|
||||
export {DOCUMENT} from './dom_tokens';
|
||||
|
20
packages/common/src/cookie.ts
Normal file
20
packages/common/src/cookie.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
export function parseCookieValue(cookieStr: string, name: string): string|null {
|
||||
name = encodeURIComponent(name);
|
||||
for (const cookie of cookieStr.split(';')) {
|
||||
const eqIndex = cookie.indexOf('=');
|
||||
const [cookieName, cookieValue]: string[] =
|
||||
eqIndex == -1 ? [cookie, ''] : [cookie.slice(0, eqIndex), cookie.slice(eqIndex + 1)];
|
||||
if (cookieName.trim() === name) {
|
||||
return decodeURIComponent(cookieValue);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
Reference in New Issue
Block a user