File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 99import { DOCUMENT , ɵparseCookieValue as parseCookieValue } from '../../index' ;
1010import {
1111 EnvironmentInjector ,
12- Inject ,
1312 inject ,
1413 Injectable ,
1514 InjectionToken ,
@@ -55,6 +54,9 @@ export abstract class HttpXsrfTokenExtractor {
5554 */
5655@Injectable ( )
5756export class HttpXsrfCookieExtractor implements HttpXsrfTokenExtractor {
57+ private readonly cookieName = inject ( XSRF_COOKIE_NAME ) ;
58+ private readonly doc = inject ( DOCUMENT ) ;
59+
5860 private lastCookieString : string = '' ;
5961 private lastToken : string | null = null ;
6062
@@ -63,11 +65,6 @@ export class HttpXsrfCookieExtractor implements HttpXsrfTokenExtractor {
6365 */
6466 parseCount : number = 0 ;
6567
66- constructor (
67- @Inject ( DOCUMENT ) private doc : any ,
68- @Inject ( XSRF_COOKIE_NAME ) private cookieName : string ,
69- ) { }
70-
7168 getToken ( ) : string | null {
7269 if ( typeof ngServerMode !== 'undefined' && ngServerMode ) {
7370 return null ;
@@ -116,7 +113,7 @@ export function xsrfInterceptorFn(
116113 */
117114@Injectable ( )
118115export class HttpXsrfInterceptor implements HttpInterceptor {
119- constructor ( private injector : EnvironmentInjector ) { }
116+ private readonly injector = inject ( EnvironmentInjector ) ;
120117
121118 intercept ( initialRequest : HttpRequest < any > , next : HttpHandler ) : Observable < HttpEvent < any > > {
122119 return runInInjectionContext ( this . injector , ( ) =>
Original file line number Diff line number Diff line change 66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9+ import { DOCUMENT } from '../..' ;
910import { HttpHeaders } from '../src/headers' ;
1011import { HttpRequest } from '../src/request' ;
1112import {
@@ -122,7 +123,15 @@ describe('HttpXsrfCookieExtractor', () => {
122123 document = {
123124 cookie : 'XSRF-TOKEN=test' ,
124125 } ;
125- extractor = new HttpXsrfCookieExtractor ( document , 'XSRF-TOKEN' ) ;
126+ TestBed . configureTestingModule ( {
127+ providers : [
128+ {
129+ provide : DOCUMENT ,
130+ useValue : document ,
131+ } ,
132+ ] ,
133+ } ) ;
134+ extractor = TestBed . inject ( HttpXsrfCookieExtractor ) ;
126135 } ) ;
127136 it ( 'parses the cookie from document.cookie' , ( ) => {
128137 expect ( extractor . getToken ( ) ) . toEqual ( 'test' ) ;
You can’t perform that action at this time.
0 commit comments