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 ,
@@ -52,6 +51,9 @@ export const XSRF_HEADER_NAME = new InjectionToken<string>(
5251 */
5352@Injectable ( { providedIn : 'root' } )
5453export class HttpXsrfCookieExtractor implements HttpXsrfTokenExtractor {
54+ private readonly cookieName = inject ( XSRF_COOKIE_NAME ) ;
55+ private readonly doc = inject ( DOCUMENT ) ;
56+
5557 private lastCookieString : string = '' ;
5658 private lastToken : string | null = null ;
5759
@@ -60,11 +62,6 @@ export class HttpXsrfCookieExtractor implements HttpXsrfTokenExtractor {
6062 */
6163 parseCount : number = 0 ;
6264
63- constructor (
64- @Inject ( DOCUMENT ) private doc : any ,
65- @Inject ( XSRF_COOKIE_NAME ) private cookieName : string ,
66- ) { }
67-
6865 getToken ( ) : string | null {
6966 if ( typeof ngServerMode !== 'undefined' && ngServerMode ) {
7067 return null ;
@@ -128,7 +125,7 @@ export function xsrfInterceptorFn(
128125 */
129126@Injectable ( )
130127export class HttpXsrfInterceptor implements HttpInterceptor {
131- constructor ( private injector : EnvironmentInjector ) { }
128+ private readonly injector = inject ( EnvironmentInjector ) ;
132129
133130 intercept ( initialRequest : HttpRequest < any > , next : HttpHandler ) : Observable < HttpEvent < any > > {
134131 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