-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Expand file tree
/
Copy pathmodule.ts
More file actions
121 lines (115 loc) · 3.51 KB
/
module.ts
File metadata and controls
121 lines (115 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* @license
* Copyright Google LLC 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.dev/license
*/
import {ModuleWithProviders, NgModule} from '@angular/core';
import {HTTP_INTERCEPTORS} from './interceptor';
import {
provideHttpClient,
withInterceptorsFromDi,
withJsonpSupport,
withNoXsrfProtection,
withXhr,
withXsrfConfiguration,
} from './provider';
import {
HttpXsrfCookieExtractor,
HttpXsrfInterceptor,
HttpXsrfTokenExtractor,
XSRF_DEFAULT_COOKIE_NAME,
XSRF_DEFAULT_HEADER_NAME,
XSRF_ENABLED,
} from './xsrf';
/**
* Configures XSRF protection support for outgoing requests.
*
* For a server that supports a cookie-based XSRF protection system,
* use directly to configure XSRF protection with the correct
* cookie and header names.
*
* If no names are supplied, the default cookie name is `XSRF-TOKEN`
* and the default header name is `X-XSRF-TOKEN`.
*
* @publicApi
* @deprecated Use withXsrfConfiguration({cookieName: 'XSRF-TOKEN', headerName: 'X-XSRF-TOKEN'}) as
* providers instead or `withNoXsrfProtection` if you want to disabled XSRF protection.
*/
@NgModule({
providers: [
HttpXsrfInterceptor,
{provide: HTTP_INTERCEPTORS, useExisting: HttpXsrfInterceptor, multi: true},
{provide: HttpXsrfTokenExtractor, useClass: HttpXsrfCookieExtractor},
withXsrfConfiguration({
cookieName: XSRF_DEFAULT_COOKIE_NAME,
headerName: XSRF_DEFAULT_HEADER_NAME,
}).ɵproviders,
{provide: XSRF_ENABLED, useValue: true},
],
})
export class HttpClientXsrfModule {
/**
* Disable the default XSRF protection.
*/
static disable(): ModuleWithProviders<HttpClientXsrfModule> {
return {
ngModule: HttpClientXsrfModule,
providers: [withNoXsrfProtection().ɵproviders],
};
}
/**
* Configure XSRF protection.
* @param options An object that can specify either or both
* cookie name or header name.
* - Cookie name default is `XSRF-TOKEN`.
* - Header name default is `X-XSRF-TOKEN`.
*
*/
static withOptions(
options: {
cookieName?: string;
headerName?: string;
} = {},
): ModuleWithProviders<HttpClientXsrfModule> {
return {
ngModule: HttpClientXsrfModule,
providers: withXsrfConfiguration(options).ɵproviders,
};
}
}
/**
* Configures the dependency injector for `HttpClient`
* with supporting services for XSRF. Automatically imported by `HttpClientModule`.
*
* You can add interceptors to the chain behind `HttpClient` by binding them to the
* multiprovider for built-in DI token `HTTP_INTERCEPTORS`.
*
* When importing the `HttpClientModule`, the `HttpBackend` is set to using the `HttpXhrBackend`.
* If you want to use the `FetchBackend`, use `provideHttpClient` instead.
*
* @publicApi
* @deprecated use `provideHttpClient(withInterceptorsFromDi())` as providers instead
*/
@NgModule({
/**
* Configures the dependency injector where it is imported
* with supporting services for HTTP communications.
*/
providers: [provideHttpClient(withInterceptorsFromDi(), withXhr())],
})
export class HttpClientModule {}
/**
* Configures the dependency injector for `HttpClient`
* with supporting services for JSONP.
* Without this module, Jsonp requests reach the backend
* with method JSONP, where they are rejected.
*
* @publicApi
* @deprecated `withJsonpSupport()` as providers instead
*/
@NgModule({
providers: [withJsonpSupport().ɵproviders],
})
export class HttpClientJsonpModule {}