MCPcopy Index your code
hub / github.com/angular/angular / validateXhrCompatibility

Function validateXhrCompatibility

packages/common/http/src/xhr.ts:44–98  ·  view source on GitHub ↗

* Validates whether the request is compatible with the XHR backend. * Show a warning if the request contains options that are not supported by XHR.

(req: HttpRequest<any>)

Source from the content-addressed store, hash-verified

42 * Show a warning if the request contains options that are not supported by XHR.
43 */
44function validateXhrCompatibility(req: HttpRequest<any>) {
45 const unsupportedOptions: {
46 property: keyof HttpRequest<any>;
47 errorCode: RuntimeErrorCode;
48 }[] = [
49 {
50 property: 'keepalive',
51 errorCode: RuntimeErrorCode.KEEPALIVE_NOT_SUPPORTED_WITH_XHR,
52 },
53 {
54 property: 'cache',
55 errorCode: RuntimeErrorCode.CACHE_NOT_SUPPORTED_WITH_XHR,
56 },
57 {
58 property: 'priority',
59 errorCode: RuntimeErrorCode.PRIORITY_NOT_SUPPORTED_WITH_XHR,
60 },
61 {
62 property: 'mode',
63 errorCode: RuntimeErrorCode.MODE_NOT_SUPPORTED_WITH_XHR,
64 },
65 {
66 property: 'redirect',
67 errorCode: RuntimeErrorCode.REDIRECT_NOT_SUPPORTED_WITH_XHR,
68 },
69 {
70 property: 'credentials',
71 errorCode: RuntimeErrorCode.CREDENTIALS_NOT_SUPPORTED_WITH_XHR,
72 },
73 {
74 property: 'integrity',
75 errorCode: RuntimeErrorCode.INTEGRITY_NOT_SUPPORTED_WITH_XHR,
76 },
77 {
78 property: 'referrer',
79 errorCode: RuntimeErrorCode.REFERRER_NOT_SUPPORTED_WITH_XHR,
80 },
81 {
82 property: 'referrerPolicy',
83 errorCode: RuntimeErrorCode.REFERRER_POLICY_NOT_SUPPORTED_WITH_XHR,
84 },
85 ];
86
87 // Check each unsupported option and warn if present
88 for (const {property, errorCode} of unsupportedOptions) {
89 if (req[property]) {
90 console.warn(
91 formatRuntimeError(
92 errorCode,
93 `Angular detected that a \`HttpClient\` request with the \`${property}\` option was sent using XHR, which does not support it. To use the \`${property}\` option, use the Fetch API by removing \`withXhr()\` from the \`provideHttpClient()\` call.`,
94 ),
95 );
96 }
97 }
98}
99
100/**
101 * Uses `XMLHttpRequest` to send requests to a backend server.

Callers 1

handleMethod · 0.85

Calls 2

formatRuntimeErrorFunction · 0.85
warnMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…