File tree Expand file tree Collapse file tree 2 files changed +8
-14
lines changed Expand file tree Collapse file tree 2 files changed +8
-14
lines changed Original file line number Diff line number Diff line change 99import { DOCUMENT , ɵparseCookieValue as parseCookieValue } from '../../index' ;
1010import {
1111 EnvironmentInjector ,
12+ Inject ,
1213 inject ,
1314 Injectable ,
1415 InjectionToken ,
@@ -54,9 +55,6 @@ export abstract class HttpXsrfTokenExtractor {
5455 */
5556@Injectable ( )
5657export class HttpXsrfCookieExtractor implements HttpXsrfTokenExtractor {
57- private readonly cookieName = inject ( XSRF_COOKIE_NAME ) ;
58- private readonly doc = inject ( DOCUMENT ) ;
59-
6058 private lastCookieString : string = '' ;
6159 private lastToken : string | null = null ;
6260
@@ -65,6 +63,11 @@ export class HttpXsrfCookieExtractor implements HttpXsrfTokenExtractor {
6563 */
6664 parseCount : number = 0 ;
6765
66+ constructor (
67+ @Inject ( DOCUMENT ) private doc : any ,
68+ @Inject ( XSRF_COOKIE_NAME ) private cookieName : string ,
69+ ) { }
70+
6871 getToken ( ) : string | null {
6972 if ( typeof ngServerMode !== 'undefined' && ngServerMode ) {
7073 return null ;
@@ -113,7 +116,7 @@ export function xsrfInterceptorFn(
113116 */
114117@Injectable ( )
115118export class HttpXsrfInterceptor implements HttpInterceptor {
116- private readonly injector = inject ( EnvironmentInjector ) ;
119+ constructor ( private injector : EnvironmentInjector ) { }
117120
118121 intercept ( initialRequest : HttpRequest < any > , next : HttpHandler ) : Observable < HttpEvent < any > > {
119122 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 '../..' ;
109import { HttpHeaders } from '../src/headers' ;
1110import { HttpRequest } from '../src/request' ;
1211import {
@@ -123,15 +122,7 @@ describe('HttpXsrfCookieExtractor', () => {
123122 document = {
124123 cookie : 'XSRF-TOKEN=test' ,
125124 } ;
126- TestBed . configureTestingModule ( {
127- providers : [
128- {
129- provide : DOCUMENT ,
130- useValue : document ,
131- } ,
132- ] ,
133- } ) ;
134- extractor = TestBed . inject ( HttpXsrfCookieExtractor ) ;
125+ extractor = new HttpXsrfCookieExtractor ( document , 'XSRF-TOKEN' ) ;
135126 } ) ;
136127 it ( 'parses the cookie from document.cookie' , ( ) => {
137128 expect ( extractor . getToken ( ) ) . toEqual ( 'test' ) ;
You can’t perform that action at this time.
0 commit comments