Skip to content

Commit 8922cae

Browse files
committed
Revert "refactor(http): migrate XSRF classes to use inject() function"
This reverts commit 2ad6b72. Revert reason: the change relies on the code that is not available in the `20.3.x` branch (the `HttpXsrfCookieExtractor` class is not marked as `providedIn: "root"`).
1 parent 5047849 commit 8922cae

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

packages/common/http/src/xsrf.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import {DOCUMENT, ɵparseCookieValue as parseCookieValue} from '../../index';
1010
import {
1111
EnvironmentInjector,
12+
Inject,
1213
inject,
1314
Injectable,
1415
InjectionToken,
@@ -54,9 +55,6 @@ export abstract class HttpXsrfTokenExtractor {
5455
*/
5556
@Injectable()
5657
export 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()
115118
export 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, () =>

packages/common/http/test/xsrf_spec.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {DOCUMENT} from '../..';
109
import {HttpHeaders} from '../src/headers';
1110
import {HttpRequest} from '../src/request';
1211
import {
@@ -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');

0 commit comments

Comments
 (0)