You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2288 lines
75KB

  1. import {
  2. DOCUMENT,
  3. XhrFactory,
  4. isPlatformServer,
  5. parseCookieValue
  6. } from "./chunk-GBYLXCNQ.js";
  7. import {
  8. APP_BOOTSTRAP_LISTENER,
  9. ApplicationRef,
  10. Console,
  11. EnvironmentInjector,
  12. Inject,
  13. Injectable,
  14. InjectionToken,
  15. NgModule,
  16. NgZone,
  17. PLATFORM_ID,
  18. PendingTasks,
  19. RuntimeError,
  20. TransferState,
  21. formatRuntimeError,
  22. inject,
  23. makeEnvironmentProviders,
  24. makeStateKey,
  25. performanceMarkFeature,
  26. runInInjectionContext,
  27. setClassMetadata,
  28. truncateMiddle,
  29. whenStable,
  30. ɵɵdefineInjectable,
  31. ɵɵdefineInjector,
  32. ɵɵdefineNgModule,
  33. ɵɵinject
  34. } from "./chunk-NYIFMCVF.js";
  35. import {
  36. Observable,
  37. __async,
  38. __objRest,
  39. __spreadValues,
  40. concatMap,
  41. filter,
  42. finalize,
  43. from,
  44. map,
  45. of,
  46. switchMap,
  47. tap
  48. } from "./chunk-SXIXOCJ4.js";
  49. // node_modules/@angular/common/fesm2022/http.mjs
  50. var HttpHandler = class {
  51. };
  52. var HttpBackend = class {
  53. };
  54. var HttpHeaders = class _HttpHeaders {
  55. /** Constructs a new HTTP header object with the given values.*/
  56. constructor(headers) {
  57. this.normalizedNames = /* @__PURE__ */ new Map();
  58. this.lazyUpdate = null;
  59. if (!headers) {
  60. this.headers = /* @__PURE__ */ new Map();
  61. } else if (typeof headers === "string") {
  62. this.lazyInit = () => {
  63. this.headers = /* @__PURE__ */ new Map();
  64. headers.split("\n").forEach((line) => {
  65. const index = line.indexOf(":");
  66. if (index > 0) {
  67. const name = line.slice(0, index);
  68. const key = name.toLowerCase();
  69. const value = line.slice(index + 1).trim();
  70. this.maybeSetNormalizedName(name, key);
  71. if (this.headers.has(key)) {
  72. this.headers.get(key).push(value);
  73. } else {
  74. this.headers.set(key, [value]);
  75. }
  76. }
  77. });
  78. };
  79. } else if (typeof Headers !== "undefined" && headers instanceof Headers) {
  80. this.headers = /* @__PURE__ */ new Map();
  81. headers.forEach((values, name) => {
  82. this.setHeaderEntries(name, values);
  83. });
  84. } else {
  85. this.lazyInit = () => {
  86. if (typeof ngDevMode === "undefined" || ngDevMode) {
  87. assertValidHeaders(headers);
  88. }
  89. this.headers = /* @__PURE__ */ new Map();
  90. Object.entries(headers).forEach(([name, values]) => {
  91. this.setHeaderEntries(name, values);
  92. });
  93. };
  94. }
  95. }
  96. /**
  97. * Checks for existence of a given header.
  98. *
  99. * @param name The header name to check for existence.
  100. *
  101. * @returns True if the header exists, false otherwise.
  102. */
  103. has(name) {
  104. this.init();
  105. return this.headers.has(name.toLowerCase());
  106. }
  107. /**
  108. * Retrieves the first value of a given header.
  109. *
  110. * @param name The header name.
  111. *
  112. * @returns The value string if the header exists, null otherwise
  113. */
  114. get(name) {
  115. this.init();
  116. const values = this.headers.get(name.toLowerCase());
  117. return values && values.length > 0 ? values[0] : null;
  118. }
  119. /**
  120. * Retrieves the names of the headers.
  121. *
  122. * @returns A list of header names.
  123. */
  124. keys() {
  125. this.init();
  126. return Array.from(this.normalizedNames.values());
  127. }
  128. /**
  129. * Retrieves a list of values for a given header.
  130. *
  131. * @param name The header name from which to retrieve values.
  132. *
  133. * @returns A string of values if the header exists, null otherwise.
  134. */
  135. getAll(name) {
  136. this.init();
  137. return this.headers.get(name.toLowerCase()) || null;
  138. }
  139. /**
  140. * Appends a new value to the existing set of values for a header
  141. * and returns them in a clone of the original instance.
  142. *
  143. * @param name The header name for which to append the values.
  144. * @param value The value to append.
  145. *
  146. * @returns A clone of the HTTP headers object with the value appended to the given header.
  147. */
  148. append(name, value) {
  149. return this.clone({
  150. name,
  151. value,
  152. op: "a"
  153. });
  154. }
  155. /**
  156. * Sets or modifies a value for a given header in a clone of the original instance.
  157. * If the header already exists, its value is replaced with the given value
  158. * in the returned object.
  159. *
  160. * @param name The header name.
  161. * @param value The value or values to set or override for the given header.
  162. *
  163. * @returns A clone of the HTTP headers object with the newly set header value.
  164. */
  165. set(name, value) {
  166. return this.clone({
  167. name,
  168. value,
  169. op: "s"
  170. });
  171. }
  172. /**
  173. * Deletes values for a given header in a clone of the original instance.
  174. *
  175. * @param name The header name.
  176. * @param value The value or values to delete for the given header.
  177. *
  178. * @returns A clone of the HTTP headers object with the given value deleted.
  179. */
  180. delete(name, value) {
  181. return this.clone({
  182. name,
  183. value,
  184. op: "d"
  185. });
  186. }
  187. maybeSetNormalizedName(name, lcName) {
  188. if (!this.normalizedNames.has(lcName)) {
  189. this.normalizedNames.set(lcName, name);
  190. }
  191. }
  192. init() {
  193. if (!!this.lazyInit) {
  194. if (this.lazyInit instanceof _HttpHeaders) {
  195. this.copyFrom(this.lazyInit);
  196. } else {
  197. this.lazyInit();
  198. }
  199. this.lazyInit = null;
  200. if (!!this.lazyUpdate) {
  201. this.lazyUpdate.forEach((update) => this.applyUpdate(update));
  202. this.lazyUpdate = null;
  203. }
  204. }
  205. }
  206. copyFrom(other) {
  207. other.init();
  208. Array.from(other.headers.keys()).forEach((key) => {
  209. this.headers.set(key, other.headers.get(key));
  210. this.normalizedNames.set(key, other.normalizedNames.get(key));
  211. });
  212. }
  213. clone(update) {
  214. const clone = new _HttpHeaders();
  215. clone.lazyInit = !!this.lazyInit && this.lazyInit instanceof _HttpHeaders ? this.lazyInit : this;
  216. clone.lazyUpdate = (this.lazyUpdate || []).concat([update]);
  217. return clone;
  218. }
  219. applyUpdate(update) {
  220. const key = update.name.toLowerCase();
  221. switch (update.op) {
  222. case "a":
  223. case "s":
  224. let value = update.value;
  225. if (typeof value === "string") {
  226. value = [value];
  227. }
  228. if (value.length === 0) {
  229. return;
  230. }
  231. this.maybeSetNormalizedName(update.name, key);
  232. const base = (update.op === "a" ? this.headers.get(key) : void 0) || [];
  233. base.push(...value);
  234. this.headers.set(key, base);
  235. break;
  236. case "d":
  237. const toDelete = update.value;
  238. if (!toDelete) {
  239. this.headers.delete(key);
  240. this.normalizedNames.delete(key);
  241. } else {
  242. let existing = this.headers.get(key);
  243. if (!existing) {
  244. return;
  245. }
  246. existing = existing.filter((value2) => toDelete.indexOf(value2) === -1);
  247. if (existing.length === 0) {
  248. this.headers.delete(key);
  249. this.normalizedNames.delete(key);
  250. } else {
  251. this.headers.set(key, existing);
  252. }
  253. }
  254. break;
  255. }
  256. }
  257. setHeaderEntries(name, values) {
  258. const headerValues = (Array.isArray(values) ? values : [values]).map((value) => value.toString());
  259. const key = name.toLowerCase();
  260. this.headers.set(key, headerValues);
  261. this.maybeSetNormalizedName(name, key);
  262. }
  263. /**
  264. * @internal
  265. */
  266. forEach(fn) {
  267. this.init();
  268. Array.from(this.normalizedNames.keys()).forEach((key) => fn(this.normalizedNames.get(key), this.headers.get(key)));
  269. }
  270. };
  271. function assertValidHeaders(headers) {
  272. for (const [key, value] of Object.entries(headers)) {
  273. if (!(typeof value === "string" || typeof value === "number") && !Array.isArray(value)) {
  274. throw new Error(`Unexpected value of the \`${key}\` header provided. Expecting either a string, a number or an array, but got: \`${value}\`.`);
  275. }
  276. }
  277. }
  278. var HttpUrlEncodingCodec = class {
  279. /**
  280. * Encodes a key name for a URL parameter or query-string.
  281. * @param key The key name.
  282. * @returns The encoded key name.
  283. */
  284. encodeKey(key) {
  285. return standardEncoding(key);
  286. }
  287. /**
  288. * Encodes the value of a URL parameter or query-string.
  289. * @param value The value.
  290. * @returns The encoded value.
  291. */
  292. encodeValue(value) {
  293. return standardEncoding(value);
  294. }
  295. /**
  296. * Decodes an encoded URL parameter or query-string key.
  297. * @param key The encoded key name.
  298. * @returns The decoded key name.
  299. */
  300. decodeKey(key) {
  301. return decodeURIComponent(key);
  302. }
  303. /**
  304. * Decodes an encoded URL parameter or query-string value.
  305. * @param value The encoded value.
  306. * @returns The decoded value.
  307. */
  308. decodeValue(value) {
  309. return decodeURIComponent(value);
  310. }
  311. };
  312. function paramParser(rawParams, codec) {
  313. const map2 = /* @__PURE__ */ new Map();
  314. if (rawParams.length > 0) {
  315. const params = rawParams.replace(/^\?/, "").split("&");
  316. params.forEach((param) => {
  317. const eqIdx = param.indexOf("=");
  318. const [key, val] = eqIdx == -1 ? [codec.decodeKey(param), ""] : [codec.decodeKey(param.slice(0, eqIdx)), codec.decodeValue(param.slice(eqIdx + 1))];
  319. const list = map2.get(key) || [];
  320. list.push(val);
  321. map2.set(key, list);
  322. });
  323. }
  324. return map2;
  325. }
  326. var STANDARD_ENCODING_REGEX = /%(\d[a-f0-9])/gi;
  327. var STANDARD_ENCODING_REPLACEMENTS = {
  328. "40": "@",
  329. "3A": ":",
  330. "24": "$",
  331. "2C": ",",
  332. "3B": ";",
  333. "3D": "=",
  334. "3F": "?",
  335. "2F": "/"
  336. };
  337. function standardEncoding(v) {
  338. return encodeURIComponent(v).replace(STANDARD_ENCODING_REGEX, (s, t) => STANDARD_ENCODING_REPLACEMENTS[t] ?? s);
  339. }
  340. function valueToString(value) {
  341. return `${value}`;
  342. }
  343. var HttpParams = class _HttpParams {
  344. constructor(options = {}) {
  345. this.updates = null;
  346. this.cloneFrom = null;
  347. this.encoder = options.encoder || new HttpUrlEncodingCodec();
  348. if (!!options.fromString) {
  349. if (!!options.fromObject) {
  350. throw new Error(`Cannot specify both fromString and fromObject.`);
  351. }
  352. this.map = paramParser(options.fromString, this.encoder);
  353. } else if (!!options.fromObject) {
  354. this.map = /* @__PURE__ */ new Map();
  355. Object.keys(options.fromObject).forEach((key) => {
  356. const value = options.fromObject[key];
  357. const values = Array.isArray(value) ? value.map(valueToString) : [valueToString(value)];
  358. this.map.set(key, values);
  359. });
  360. } else {
  361. this.map = null;
  362. }
  363. }
  364. /**
  365. * Reports whether the body includes one or more values for a given parameter.
  366. * @param param The parameter name.
  367. * @returns True if the parameter has one or more values,
  368. * false if it has no value or is not present.
  369. */
  370. has(param) {
  371. this.init();
  372. return this.map.has(param);
  373. }
  374. /**
  375. * Retrieves the first value for a parameter.
  376. * @param param The parameter name.
  377. * @returns The first value of the given parameter,
  378. * or `null` if the parameter is not present.
  379. */
  380. get(param) {
  381. this.init();
  382. const res = this.map.get(param);
  383. return !!res ? res[0] : null;
  384. }
  385. /**
  386. * Retrieves all values for a parameter.
  387. * @param param The parameter name.
  388. * @returns All values in a string array,
  389. * or `null` if the parameter not present.
  390. */
  391. getAll(param) {
  392. this.init();
  393. return this.map.get(param) || null;
  394. }
  395. /**
  396. * Retrieves all the parameters for this body.
  397. * @returns The parameter names in a string array.
  398. */
  399. keys() {
  400. this.init();
  401. return Array.from(this.map.keys());
  402. }
  403. /**
  404. * Appends a new value to existing values for a parameter.
  405. * @param param The parameter name.
  406. * @param value The new value to add.
  407. * @return A new body with the appended value.
  408. */
  409. append(param, value) {
  410. return this.clone({
  411. param,
  412. value,
  413. op: "a"
  414. });
  415. }
  416. /**
  417. * Constructs a new body with appended values for the given parameter name.
  418. * @param params parameters and values
  419. * @return A new body with the new value.
  420. */
  421. appendAll(params) {
  422. const updates = [];
  423. Object.keys(params).forEach((param) => {
  424. const value = params[param];
  425. if (Array.isArray(value)) {
  426. value.forEach((_value) => {
  427. updates.push({
  428. param,
  429. value: _value,
  430. op: "a"
  431. });
  432. });
  433. } else {
  434. updates.push({
  435. param,
  436. value,
  437. op: "a"
  438. });
  439. }
  440. });
  441. return this.clone(updates);
  442. }
  443. /**
  444. * Replaces the value for a parameter.
  445. * @param param The parameter name.
  446. * @param value The new value.
  447. * @return A new body with the new value.
  448. */
  449. set(param, value) {
  450. return this.clone({
  451. param,
  452. value,
  453. op: "s"
  454. });
  455. }
  456. /**
  457. * Removes a given value or all values from a parameter.
  458. * @param param The parameter name.
  459. * @param value The value to remove, if provided.
  460. * @return A new body with the given value removed, or with all values
  461. * removed if no value is specified.
  462. */
  463. delete(param, value) {
  464. return this.clone({
  465. param,
  466. value,
  467. op: "d"
  468. });
  469. }
  470. /**
  471. * Serializes the body to an encoded string, where key-value pairs (separated by `=`) are
  472. * separated by `&`s.
  473. */
  474. toString() {
  475. this.init();
  476. return this.keys().map((key) => {
  477. const eKey = this.encoder.encodeKey(key);
  478. return this.map.get(key).map((value) => eKey + "=" + this.encoder.encodeValue(value)).join("&");
  479. }).filter((param) => param !== "").join("&");
  480. }
  481. clone(update) {
  482. const clone = new _HttpParams({
  483. encoder: this.encoder
  484. });
  485. clone.cloneFrom = this.cloneFrom || this;
  486. clone.updates = (this.updates || []).concat(update);
  487. return clone;
  488. }
  489. init() {
  490. if (this.map === null) {
  491. this.map = /* @__PURE__ */ new Map();
  492. }
  493. if (this.cloneFrom !== null) {
  494. this.cloneFrom.init();
  495. this.cloneFrom.keys().forEach((key) => this.map.set(key, this.cloneFrom.map.get(key)));
  496. this.updates.forEach((update) => {
  497. switch (update.op) {
  498. case "a":
  499. case "s":
  500. const base = (update.op === "a" ? this.map.get(update.param) : void 0) || [];
  501. base.push(valueToString(update.value));
  502. this.map.set(update.param, base);
  503. break;
  504. case "d":
  505. if (update.value !== void 0) {
  506. let base2 = this.map.get(update.param) || [];
  507. const idx = base2.indexOf(valueToString(update.value));
  508. if (idx !== -1) {
  509. base2.splice(idx, 1);
  510. }
  511. if (base2.length > 0) {
  512. this.map.set(update.param, base2);
  513. } else {
  514. this.map.delete(update.param);
  515. }
  516. } else {
  517. this.map.delete(update.param);
  518. break;
  519. }
  520. }
  521. });
  522. this.cloneFrom = this.updates = null;
  523. }
  524. }
  525. };
  526. var HttpContextToken = class {
  527. constructor(defaultValue) {
  528. this.defaultValue = defaultValue;
  529. }
  530. };
  531. var HttpContext = class {
  532. constructor() {
  533. this.map = /* @__PURE__ */ new Map();
  534. }
  535. /**
  536. * Store a value in the context. If a value is already present it will be overwritten.
  537. *
  538. * @param token The reference to an instance of `HttpContextToken`.
  539. * @param value The value to store.
  540. *
  541. * @returns A reference to itself for easy chaining.
  542. */
  543. set(token, value) {
  544. this.map.set(token, value);
  545. return this;
  546. }
  547. /**
  548. * Retrieve the value associated with the given token.
  549. *
  550. * @param token The reference to an instance of `HttpContextToken`.
  551. *
  552. * @returns The stored value or default if one is defined.
  553. */
  554. get(token) {
  555. if (!this.map.has(token)) {
  556. this.map.set(token, token.defaultValue());
  557. }
  558. return this.map.get(token);
  559. }
  560. /**
  561. * Delete the value associated with the given token.
  562. *
  563. * @param token The reference to an instance of `HttpContextToken`.
  564. *
  565. * @returns A reference to itself for easy chaining.
  566. */
  567. delete(token) {
  568. this.map.delete(token);
  569. return this;
  570. }
  571. /**
  572. * Checks for existence of a given token.
  573. *
  574. * @param token The reference to an instance of `HttpContextToken`.
  575. *
  576. * @returns True if the token exists, false otherwise.
  577. */
  578. has(token) {
  579. return this.map.has(token);
  580. }
  581. /**
  582. * @returns a list of tokens currently stored in the context.
  583. */
  584. keys() {
  585. return this.map.keys();
  586. }
  587. };
  588. function mightHaveBody(method) {
  589. switch (method) {
  590. case "DELETE":
  591. case "GET":
  592. case "HEAD":
  593. case "OPTIONS":
  594. case "JSONP":
  595. return false;
  596. default:
  597. return true;
  598. }
  599. }
  600. function isArrayBuffer(value) {
  601. return typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer;
  602. }
  603. function isBlob(value) {
  604. return typeof Blob !== "undefined" && value instanceof Blob;
  605. }
  606. function isFormData(value) {
  607. return typeof FormData !== "undefined" && value instanceof FormData;
  608. }
  609. function isUrlSearchParams(value) {
  610. return typeof URLSearchParams !== "undefined" && value instanceof URLSearchParams;
  611. }
  612. var HttpRequest = class _HttpRequest {
  613. constructor(method, url, third, fourth) {
  614. this.url = url;
  615. this.body = null;
  616. this.reportProgress = false;
  617. this.withCredentials = false;
  618. this.responseType = "json";
  619. this.method = method.toUpperCase();
  620. let options;
  621. if (mightHaveBody(this.method) || !!fourth) {
  622. this.body = third !== void 0 ? third : null;
  623. options = fourth;
  624. } else {
  625. options = third;
  626. }
  627. if (options) {
  628. this.reportProgress = !!options.reportProgress;
  629. this.withCredentials = !!options.withCredentials;
  630. if (!!options.responseType) {
  631. this.responseType = options.responseType;
  632. }
  633. if (!!options.headers) {
  634. this.headers = options.headers;
  635. }
  636. if (!!options.context) {
  637. this.context = options.context;
  638. }
  639. if (!!options.params) {
  640. this.params = options.params;
  641. }
  642. this.transferCache = options.transferCache;
  643. }
  644. this.headers ??= new HttpHeaders();
  645. this.context ??= new HttpContext();
  646. if (!this.params) {
  647. this.params = new HttpParams();
  648. this.urlWithParams = url;
  649. } else {
  650. const params = this.params.toString();
  651. if (params.length === 0) {
  652. this.urlWithParams = url;
  653. } else {
  654. const qIdx = url.indexOf("?");
  655. const sep = qIdx === -1 ? "?" : qIdx < url.length - 1 ? "&" : "";
  656. this.urlWithParams = url + sep + params;
  657. }
  658. }
  659. }
  660. /**
  661. * Transform the free-form body into a serialized format suitable for
  662. * transmission to the server.
  663. */
  664. serializeBody() {
  665. if (this.body === null) {
  666. return null;
  667. }
  668. if (isArrayBuffer(this.body) || isBlob(this.body) || isFormData(this.body) || isUrlSearchParams(this.body) || typeof this.body === "string") {
  669. return this.body;
  670. }
  671. if (this.body instanceof HttpParams) {
  672. return this.body.toString();
  673. }
  674. if (typeof this.body === "object" || typeof this.body === "boolean" || Array.isArray(this.body)) {
  675. return JSON.stringify(this.body);
  676. }
  677. return this.body.toString();
  678. }
  679. /**
  680. * Examine the body and attempt to infer an appropriate MIME type
  681. * for it.
  682. *
  683. * If no such type can be inferred, this method will return `null`.
  684. */
  685. detectContentTypeHeader() {
  686. if (this.body === null) {
  687. return null;
  688. }
  689. if (isFormData(this.body)) {
  690. return null;
  691. }
  692. if (isBlob(this.body)) {
  693. return this.body.type || null;
  694. }
  695. if (isArrayBuffer(this.body)) {
  696. return null;
  697. }
  698. if (typeof this.body === "string") {
  699. return "text/plain";
  700. }
  701. if (this.body instanceof HttpParams) {
  702. return "application/x-www-form-urlencoded;charset=UTF-8";
  703. }
  704. if (typeof this.body === "object" || typeof this.body === "number" || typeof this.body === "boolean") {
  705. return "application/json";
  706. }
  707. return null;
  708. }
  709. clone(update = {}) {
  710. const method = update.method || this.method;
  711. const url = update.url || this.url;
  712. const responseType = update.responseType || this.responseType;
  713. const body = update.body !== void 0 ? update.body : this.body;
  714. const withCredentials = update.withCredentials !== void 0 ? update.withCredentials : this.withCredentials;
  715. const reportProgress = update.reportProgress !== void 0 ? update.reportProgress : this.reportProgress;
  716. let headers = update.headers || this.headers;
  717. let params = update.params || this.params;
  718. const context = update.context ?? this.context;
  719. if (update.setHeaders !== void 0) {
  720. headers = Object.keys(update.setHeaders).reduce((headers2, name) => headers2.set(name, update.setHeaders[name]), headers);
  721. }
  722. if (update.setParams) {
  723. params = Object.keys(update.setParams).reduce((params2, param) => params2.set(param, update.setParams[param]), params);
  724. }
  725. return new _HttpRequest(method, url, body, {
  726. params,
  727. headers,
  728. context,
  729. reportProgress,
  730. responseType,
  731. withCredentials
  732. });
  733. }
  734. };
  735. var HttpEventType;
  736. (function(HttpEventType2) {
  737. HttpEventType2[HttpEventType2["Sent"] = 0] = "Sent";
  738. HttpEventType2[HttpEventType2["UploadProgress"] = 1] = "UploadProgress";
  739. HttpEventType2[HttpEventType2["ResponseHeader"] = 2] = "ResponseHeader";
  740. HttpEventType2[HttpEventType2["DownloadProgress"] = 3] = "DownloadProgress";
  741. HttpEventType2[HttpEventType2["Response"] = 4] = "Response";
  742. HttpEventType2[HttpEventType2["User"] = 5] = "User";
  743. })(HttpEventType || (HttpEventType = {}));
  744. var HttpResponseBase = class {
  745. /**
  746. * Super-constructor for all responses.
  747. *
  748. * The single parameter accepted is an initialization hash. Any properties
  749. * of the response passed there will override the default values.
  750. */
  751. constructor(init, defaultStatus = HttpStatusCode.Ok, defaultStatusText = "OK") {
  752. this.headers = init.headers || new HttpHeaders();
  753. this.status = init.status !== void 0 ? init.status : defaultStatus;
  754. this.statusText = init.statusText || defaultStatusText;
  755. this.url = init.url || null;
  756. this.ok = this.status >= 200 && this.status < 300;
  757. }
  758. };
  759. var HttpHeaderResponse = class _HttpHeaderResponse extends HttpResponseBase {
  760. /**
  761. * Create a new `HttpHeaderResponse` with the given parameters.
  762. */
  763. constructor(init = {}) {
  764. super(init);
  765. this.type = HttpEventType.ResponseHeader;
  766. }
  767. /**
  768. * Copy this `HttpHeaderResponse`, overriding its contents with the
  769. * given parameter hash.
  770. */
  771. clone(update = {}) {
  772. return new _HttpHeaderResponse({
  773. headers: update.headers || this.headers,
  774. status: update.status !== void 0 ? update.status : this.status,
  775. statusText: update.statusText || this.statusText,
  776. url: update.url || this.url || void 0
  777. });
  778. }
  779. };
  780. var HttpResponse = class _HttpResponse extends HttpResponseBase {
  781. /**
  782. * Construct a new `HttpResponse`.
  783. */
  784. constructor(init = {}) {
  785. super(init);
  786. this.type = HttpEventType.Response;
  787. this.body = init.body !== void 0 ? init.body : null;
  788. }
  789. clone(update = {}) {
  790. return new _HttpResponse({
  791. body: update.body !== void 0 ? update.body : this.body,
  792. headers: update.headers || this.headers,
  793. status: update.status !== void 0 ? update.status : this.status,
  794. statusText: update.statusText || this.statusText,
  795. url: update.url || this.url || void 0
  796. });
  797. }
  798. };
  799. var HttpErrorResponse = class extends HttpResponseBase {
  800. constructor(init) {
  801. super(init, 0, "Unknown Error");
  802. this.name = "HttpErrorResponse";
  803. this.ok = false;
  804. if (this.status >= 200 && this.status < 300) {
  805. this.message = `Http failure during parsing for ${init.url || "(unknown url)"}`;
  806. } else {
  807. this.message = `Http failure response for ${init.url || "(unknown url)"}: ${init.status} ${init.statusText}`;
  808. }
  809. this.error = init.error || null;
  810. }
  811. };
  812. var HttpStatusCode;
  813. (function(HttpStatusCode2) {
  814. HttpStatusCode2[HttpStatusCode2["Continue"] = 100] = "Continue";
  815. HttpStatusCode2[HttpStatusCode2["SwitchingProtocols"] = 101] = "SwitchingProtocols";
  816. HttpStatusCode2[HttpStatusCode2["Processing"] = 102] = "Processing";
  817. HttpStatusCode2[HttpStatusCode2["EarlyHints"] = 103] = "EarlyHints";
  818. HttpStatusCode2[HttpStatusCode2["Ok"] = 200] = "Ok";
  819. HttpStatusCode2[HttpStatusCode2["Created"] = 201] = "Created";
  820. HttpStatusCode2[HttpStatusCode2["Accepted"] = 202] = "Accepted";
  821. HttpStatusCode2[HttpStatusCode2["NonAuthoritativeInformation"] = 203] = "NonAuthoritativeInformation";
  822. HttpStatusCode2[HttpStatusCode2["NoContent"] = 204] = "NoContent";
  823. HttpStatusCode2[HttpStatusCode2["ResetContent"] = 205] = "ResetContent";
  824. HttpStatusCode2[HttpStatusCode2["PartialContent"] = 206] = "PartialContent";
  825. HttpStatusCode2[HttpStatusCode2["MultiStatus"] = 207] = "MultiStatus";
  826. HttpStatusCode2[HttpStatusCode2["AlreadyReported"] = 208] = "AlreadyReported";
  827. HttpStatusCode2[HttpStatusCode2["ImUsed"] = 226] = "ImUsed";
  828. HttpStatusCode2[HttpStatusCode2["MultipleChoices"] = 300] = "MultipleChoices";
  829. HttpStatusCode2[HttpStatusCode2["MovedPermanently"] = 301] = "MovedPermanently";
  830. HttpStatusCode2[HttpStatusCode2["Found"] = 302] = "Found";
  831. HttpStatusCode2[HttpStatusCode2["SeeOther"] = 303] = "SeeOther";
  832. HttpStatusCode2[HttpStatusCode2["NotModified"] = 304] = "NotModified";
  833. HttpStatusCode2[HttpStatusCode2["UseProxy"] = 305] = "UseProxy";
  834. HttpStatusCode2[HttpStatusCode2["Unused"] = 306] = "Unused";
  835. HttpStatusCode2[HttpStatusCode2["TemporaryRedirect"] = 307] = "TemporaryRedirect";
  836. HttpStatusCode2[HttpStatusCode2["PermanentRedirect"] = 308] = "PermanentRedirect";
  837. HttpStatusCode2[HttpStatusCode2["BadRequest"] = 400] = "BadRequest";
  838. HttpStatusCode2[HttpStatusCode2["Unauthorized"] = 401] = "Unauthorized";
  839. HttpStatusCode2[HttpStatusCode2["PaymentRequired"] = 402] = "PaymentRequired";
  840. HttpStatusCode2[HttpStatusCode2["Forbidden"] = 403] = "Forbidden";
  841. HttpStatusCode2[HttpStatusCode2["NotFound"] = 404] = "NotFound";
  842. HttpStatusCode2[HttpStatusCode2["MethodNotAllowed"] = 405] = "MethodNotAllowed";
  843. HttpStatusCode2[HttpStatusCode2["NotAcceptable"] = 406] = "NotAcceptable";
  844. HttpStatusCode2[HttpStatusCode2["ProxyAuthenticationRequired"] = 407] = "ProxyAuthenticationRequired";
  845. HttpStatusCode2[HttpStatusCode2["RequestTimeout"] = 408] = "RequestTimeout";
  846. HttpStatusCode2[HttpStatusCode2["Conflict"] = 409] = "Conflict";
  847. HttpStatusCode2[HttpStatusCode2["Gone"] = 410] = "Gone";
  848. HttpStatusCode2[HttpStatusCode2["LengthRequired"] = 411] = "LengthRequired";
  849. HttpStatusCode2[HttpStatusCode2["PreconditionFailed"] = 412] = "PreconditionFailed";
  850. HttpStatusCode2[HttpStatusCode2["PayloadTooLarge"] = 413] = "PayloadTooLarge";
  851. HttpStatusCode2[HttpStatusCode2["UriTooLong"] = 414] = "UriTooLong";
  852. HttpStatusCode2[HttpStatusCode2["UnsupportedMediaType"] = 415] = "UnsupportedMediaType";
  853. HttpStatusCode2[HttpStatusCode2["RangeNotSatisfiable"] = 416] = "RangeNotSatisfiable";
  854. HttpStatusCode2[HttpStatusCode2["ExpectationFailed"] = 417] = "ExpectationFailed";
  855. HttpStatusCode2[HttpStatusCode2["ImATeapot"] = 418] = "ImATeapot";
  856. HttpStatusCode2[HttpStatusCode2["MisdirectedRequest"] = 421] = "MisdirectedRequest";
  857. HttpStatusCode2[HttpStatusCode2["UnprocessableEntity"] = 422] = "UnprocessableEntity";
  858. HttpStatusCode2[HttpStatusCode2["Locked"] = 423] = "Locked";
  859. HttpStatusCode2[HttpStatusCode2["FailedDependency"] = 424] = "FailedDependency";
  860. HttpStatusCode2[HttpStatusCode2["TooEarly"] = 425] = "TooEarly";
  861. HttpStatusCode2[HttpStatusCode2["UpgradeRequired"] = 426] = "UpgradeRequired";
  862. HttpStatusCode2[HttpStatusCode2["PreconditionRequired"] = 428] = "PreconditionRequired";
  863. HttpStatusCode2[HttpStatusCode2["TooManyRequests"] = 429] = "TooManyRequests";
  864. HttpStatusCode2[HttpStatusCode2["RequestHeaderFieldsTooLarge"] = 431] = "RequestHeaderFieldsTooLarge";
  865. HttpStatusCode2[HttpStatusCode2["UnavailableForLegalReasons"] = 451] = "UnavailableForLegalReasons";
  866. HttpStatusCode2[HttpStatusCode2["InternalServerError"] = 500] = "InternalServerError";
  867. HttpStatusCode2[HttpStatusCode2["NotImplemented"] = 501] = "NotImplemented";
  868. HttpStatusCode2[HttpStatusCode2["BadGateway"] = 502] = "BadGateway";
  869. HttpStatusCode2[HttpStatusCode2["ServiceUnavailable"] = 503] = "ServiceUnavailable";
  870. HttpStatusCode2[HttpStatusCode2["GatewayTimeout"] = 504] = "GatewayTimeout";
  871. HttpStatusCode2[HttpStatusCode2["HttpVersionNotSupported"] = 505] = "HttpVersionNotSupported";
  872. HttpStatusCode2[HttpStatusCode2["VariantAlsoNegotiates"] = 506] = "VariantAlsoNegotiates";
  873. HttpStatusCode2[HttpStatusCode2["InsufficientStorage"] = 507] = "InsufficientStorage";
  874. HttpStatusCode2[HttpStatusCode2["LoopDetected"] = 508] = "LoopDetected";
  875. HttpStatusCode2[HttpStatusCode2["NotExtended"] = 510] = "NotExtended";
  876. HttpStatusCode2[HttpStatusCode2["NetworkAuthenticationRequired"] = 511] = "NetworkAuthenticationRequired";
  877. })(HttpStatusCode || (HttpStatusCode = {}));
  878. function addBody(options, body) {
  879. return {
  880. body,
  881. headers: options.headers,
  882. context: options.context,
  883. observe: options.observe,
  884. params: options.params,
  885. reportProgress: options.reportProgress,
  886. responseType: options.responseType,
  887. withCredentials: options.withCredentials,
  888. transferCache: options.transferCache
  889. };
  890. }
  891. var _HttpClient = class _HttpClient {
  892. constructor(handler) {
  893. this.handler = handler;
  894. }
  895. /**
  896. * Constructs an observable for a generic HTTP request that, when subscribed,
  897. * fires the request through the chain of registered interceptors and on to the
  898. * server.
  899. *
  900. * You can pass an `HttpRequest` directly as the only parameter. In this case,
  901. * the call returns an observable of the raw `HttpEvent` stream.
  902. *
  903. * Alternatively you can pass an HTTP method as the first parameter,
  904. * a URL string as the second, and an options hash containing the request body as the third.
  905. * See `addBody()`. In this case, the specified `responseType` and `observe` options determine the
  906. * type of returned observable.
  907. * * The `responseType` value determines how a successful response body is parsed.
  908. * * If `responseType` is the default `json`, you can pass a type interface for the resulting
  909. * object as a type parameter to the call.
  910. *
  911. * The `observe` value determines the return type, according to what you are interested in
  912. * observing.
  913. * * An `observe` value of events returns an observable of the raw `HttpEvent` stream, including
  914. * progress events by default.
  915. * * An `observe` value of response returns an observable of `HttpResponse<T>`,
  916. * where the `T` parameter depends on the `responseType` and any optionally provided type
  917. * parameter.
  918. * * An `observe` value of body returns an observable of `<T>` with the same `T` body type.
  919. *
  920. */
  921. request(first, url, options = {}) {
  922. let req;
  923. if (first instanceof HttpRequest) {
  924. req = first;
  925. } else {
  926. let headers = void 0;
  927. if (options.headers instanceof HttpHeaders) {
  928. headers = options.headers;
  929. } else {
  930. headers = new HttpHeaders(options.headers);
  931. }
  932. let params = void 0;
  933. if (!!options.params) {
  934. if (options.params instanceof HttpParams) {
  935. params = options.params;
  936. } else {
  937. params = new HttpParams({
  938. fromObject: options.params
  939. });
  940. }
  941. }
  942. req = new HttpRequest(first, url, options.body !== void 0 ? options.body : null, {
  943. headers,
  944. context: options.context,
  945. params,
  946. reportProgress: options.reportProgress,
  947. // By default, JSON is assumed to be returned for all calls.
  948. responseType: options.responseType || "json",
  949. withCredentials: options.withCredentials,
  950. transferCache: options.transferCache
  951. });
  952. }
  953. const events$ = of(req).pipe(concatMap((req2) => this.handler.handle(req2)));
  954. if (first instanceof HttpRequest || options.observe === "events") {
  955. return events$;
  956. }
  957. const res$ = events$.pipe(filter((event) => event instanceof HttpResponse));
  958. switch (options.observe || "body") {
  959. case "body":
  960. switch (req.responseType) {
  961. case "arraybuffer":
  962. return res$.pipe(map((res) => {
  963. if (res.body !== null && !(res.body instanceof ArrayBuffer)) {
  964. throw new Error("Response is not an ArrayBuffer.");
  965. }
  966. return res.body;
  967. }));
  968. case "blob":
  969. return res$.pipe(map((res) => {
  970. if (res.body !== null && !(res.body instanceof Blob)) {
  971. throw new Error("Response is not a Blob.");
  972. }
  973. return res.body;
  974. }));
  975. case "text":
  976. return res$.pipe(map((res) => {
  977. if (res.body !== null && typeof res.body !== "string") {
  978. throw new Error("Response is not a string.");
  979. }
  980. return res.body;
  981. }));
  982. case "json":
  983. default:
  984. return res$.pipe(map((res) => res.body));
  985. }
  986. case "response":
  987. return res$;
  988. default:
  989. throw new Error(`Unreachable: unhandled observe type ${options.observe}}`);
  990. }
  991. }
  992. /**
  993. * Constructs an observable that, when subscribed, causes the configured
  994. * `DELETE` request to execute on the server. See the individual overloads for
  995. * details on the return type.
  996. *
  997. * @param url The endpoint URL.
  998. * @param options The HTTP options to send with the request.
  999. *
  1000. */
  1001. delete(url, options = {}) {
  1002. return this.request("DELETE", url, options);
  1003. }
  1004. /**
  1005. * Constructs an observable that, when subscribed, causes the configured
  1006. * `GET` request to execute on the server. See the individual overloads for
  1007. * details on the return type.
  1008. */
  1009. get(url, options = {}) {
  1010. return this.request("GET", url, options);
  1011. }
  1012. /**
  1013. * Constructs an observable that, when subscribed, causes the configured
  1014. * `HEAD` request to execute on the server. The `HEAD` method returns
  1015. * meta information about the resource without transferring the
  1016. * resource itself. See the individual overloads for
  1017. * details on the return type.
  1018. */
  1019. head(url, options = {}) {
  1020. return this.request("HEAD", url, options);
  1021. }
  1022. /**
  1023. * Constructs an `Observable` that, when subscribed, causes a request with the special method
  1024. * `JSONP` to be dispatched via the interceptor pipeline.
  1025. * The [JSONP pattern](https://en.wikipedia.org/wiki/JSONP) works around limitations of certain
  1026. * API endpoints that don't support newer,
  1027. * and preferable [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) protocol.
  1028. * JSONP treats the endpoint API as a JavaScript file and tricks the browser to process the
  1029. * requests even if the API endpoint is not located on the same domain (origin) as the client-side
  1030. * application making the request.
  1031. * The endpoint API must support JSONP callback for JSONP requests to work.
  1032. * The resource API returns the JSON response wrapped in a callback function.
  1033. * You can pass the callback function name as one of the query parameters.
  1034. * Note that JSONP requests can only be used with `GET` requests.
  1035. *
  1036. * @param url The resource URL.
  1037. * @param callbackParam The callback function name.
  1038. *
  1039. */
  1040. jsonp(url, callbackParam) {
  1041. return this.request("JSONP", url, {
  1042. params: new HttpParams().append(callbackParam, "JSONP_CALLBACK"),
  1043. observe: "body",
  1044. responseType: "json"
  1045. });
  1046. }
  1047. /**
  1048. * Constructs an `Observable` that, when subscribed, causes the configured
  1049. * `OPTIONS` request to execute on the server. This method allows the client
  1050. * to determine the supported HTTP methods and other capabilities of an endpoint,
  1051. * without implying a resource action. See the individual overloads for
  1052. * details on the return type.
  1053. */
  1054. options(url, options = {}) {
  1055. return this.request("OPTIONS", url, options);
  1056. }
  1057. /**
  1058. * Constructs an observable that, when subscribed, causes the configured
  1059. * `PATCH` request to execute on the server. See the individual overloads for
  1060. * details on the return type.
  1061. */
  1062. patch(url, body, options = {}) {
  1063. return this.request("PATCH", url, addBody(options, body));
  1064. }
  1065. /**
  1066. * Constructs an observable that, when subscribed, causes the configured
  1067. * `POST` request to execute on the server. The server responds with the location of
  1068. * the replaced resource. See the individual overloads for
  1069. * details on the return type.
  1070. */
  1071. post(url, body, options = {}) {
  1072. return this.request("POST", url, addBody(options, body));
  1073. }
  1074. /**
  1075. * Constructs an observable that, when subscribed, causes the configured
  1076. * `PUT` request to execute on the server. The `PUT` method replaces an existing resource
  1077. * with a new set of values.
  1078. * See the individual overloads for details on the return type.
  1079. */
  1080. put(url, body, options = {}) {
  1081. return this.request("PUT", url, addBody(options, body));
  1082. }
  1083. };
  1084. _HttpClient.ɵfac = function HttpClient_Factory(t) {
  1085. return new (t || _HttpClient)(ɵɵinject(HttpHandler));
  1086. };
  1087. _HttpClient.ɵprov = ɵɵdefineInjectable({
  1088. token: _HttpClient,
  1089. factory: _HttpClient.ɵfac
  1090. });
  1091. var HttpClient = _HttpClient;
  1092. (() => {
  1093. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(HttpClient, [{
  1094. type: Injectable
  1095. }], () => [{
  1096. type: HttpHandler
  1097. }], null);
  1098. })();
  1099. var XSSI_PREFIX$1 = /^\)\]\}',?\n/;
  1100. var REQUEST_URL_HEADER = `X-Request-URL`;
  1101. function getResponseUrl$1(response) {
  1102. if (response.url) {
  1103. return response.url;
  1104. }
  1105. const xRequestUrl = REQUEST_URL_HEADER.toLocaleLowerCase();
  1106. return response.headers.get(xRequestUrl);
  1107. }
  1108. var _FetchBackend = class _FetchBackend {
  1109. constructor() {
  1110. this.fetchImpl = inject(FetchFactory, {
  1111. optional: true
  1112. })?.fetch ?? fetch.bind(globalThis);
  1113. this.ngZone = inject(NgZone);
  1114. }
  1115. handle(request) {
  1116. return new Observable((observer) => {
  1117. const aborter = new AbortController();
  1118. this.doRequest(request, aborter.signal, observer).then(noop, (error) => observer.error(new HttpErrorResponse({
  1119. error
  1120. })));
  1121. return () => aborter.abort();
  1122. });
  1123. }
  1124. doRequest(request, signal, observer) {
  1125. return __async(this, null, function* () {
  1126. const init = this.createRequestInit(request);
  1127. let response;
  1128. try {
  1129. const fetchPromise = this.fetchImpl(request.urlWithParams, __spreadValues({
  1130. signal
  1131. }, init));
  1132. silenceSuperfluousUnhandledPromiseRejection(fetchPromise);
  1133. observer.next({
  1134. type: HttpEventType.Sent
  1135. });
  1136. response = yield fetchPromise;
  1137. } catch (error) {
  1138. observer.error(new HttpErrorResponse({
  1139. error,
  1140. status: error.status ?? 0,
  1141. statusText: error.statusText,
  1142. url: request.urlWithParams,
  1143. headers: error.headers
  1144. }));
  1145. return;
  1146. }
  1147. const headers = new HttpHeaders(response.headers);
  1148. const statusText = response.statusText;
  1149. const url = getResponseUrl$1(response) ?? request.urlWithParams;
  1150. let status = response.status;
  1151. let body = null;
  1152. if (request.reportProgress) {
  1153. observer.next(new HttpHeaderResponse({
  1154. headers,
  1155. status,
  1156. statusText,
  1157. url
  1158. }));
  1159. }
  1160. if (response.body) {
  1161. const contentLength = response.headers.get("content-length");
  1162. const chunks = [];
  1163. const reader = response.body.getReader();
  1164. let receivedLength = 0;
  1165. let decoder;
  1166. let partialText;
  1167. const reqZone = typeof Zone !== "undefined" && Zone.current;
  1168. yield this.ngZone.runOutsideAngular(() => __async(this, null, function* () {
  1169. while (true) {
  1170. const {
  1171. done,
  1172. value
  1173. } = yield reader.read();
  1174. if (done) {
  1175. break;
  1176. }
  1177. chunks.push(value);
  1178. receivedLength += value.length;
  1179. if (request.reportProgress) {
  1180. partialText = request.responseType === "text" ? (partialText ?? "") + (decoder ??= new TextDecoder()).decode(value, {
  1181. stream: true
  1182. }) : void 0;
  1183. const reportProgress = () => observer.next({
  1184. type: HttpEventType.DownloadProgress,
  1185. total: contentLength ? +contentLength : void 0,
  1186. loaded: receivedLength,
  1187. partialText
  1188. });
  1189. reqZone ? reqZone.run(reportProgress) : reportProgress();
  1190. }
  1191. }
  1192. }));
  1193. const chunksAll = this.concatChunks(chunks, receivedLength);
  1194. try {
  1195. const contentType = response.headers.get("Content-Type") ?? "";
  1196. body = this.parseBody(request, chunksAll, contentType);
  1197. } catch (error) {
  1198. observer.error(new HttpErrorResponse({
  1199. error,
  1200. headers: new HttpHeaders(response.headers),
  1201. status: response.status,
  1202. statusText: response.statusText,
  1203. url: getResponseUrl$1(response) ?? request.urlWithParams
  1204. }));
  1205. return;
  1206. }
  1207. }
  1208. if (status === 0) {
  1209. status = body ? HttpStatusCode.Ok : 0;
  1210. }
  1211. const ok = status >= 200 && status < 300;
  1212. if (ok) {
  1213. observer.next(new HttpResponse({
  1214. body,
  1215. headers,
  1216. status,
  1217. statusText,
  1218. url
  1219. }));
  1220. observer.complete();
  1221. } else {
  1222. observer.error(new HttpErrorResponse({
  1223. error: body,
  1224. headers,
  1225. status,
  1226. statusText,
  1227. url
  1228. }));
  1229. }
  1230. });
  1231. }
  1232. parseBody(request, binContent, contentType) {
  1233. switch (request.responseType) {
  1234. case "json":
  1235. const text = new TextDecoder().decode(binContent).replace(XSSI_PREFIX$1, "");
  1236. return text === "" ? null : JSON.parse(text);
  1237. case "text":
  1238. return new TextDecoder().decode(binContent);
  1239. case "blob":
  1240. return new Blob([binContent], {
  1241. type: contentType
  1242. });
  1243. case "arraybuffer":
  1244. return binContent.buffer;
  1245. }
  1246. }
  1247. createRequestInit(req) {
  1248. const headers = {};
  1249. const credentials = req.withCredentials ? "include" : void 0;
  1250. req.headers.forEach((name, values) => headers[name] = values.join(","));
  1251. headers["Accept"] ??= "application/json, text/plain, */*";
  1252. if (!headers["Content-Type"]) {
  1253. const detectedType = req.detectContentTypeHeader();
  1254. if (detectedType !== null) {
  1255. headers["Content-Type"] = detectedType;
  1256. }
  1257. }
  1258. return {
  1259. body: req.serializeBody(),
  1260. method: req.method,
  1261. headers,
  1262. credentials
  1263. };
  1264. }
  1265. concatChunks(chunks, totalLength) {
  1266. const chunksAll = new Uint8Array(totalLength);
  1267. let position = 0;
  1268. for (const chunk of chunks) {
  1269. chunksAll.set(chunk, position);
  1270. position += chunk.length;
  1271. }
  1272. return chunksAll;
  1273. }
  1274. };
  1275. _FetchBackend.ɵfac = function FetchBackend_Factory(t) {
  1276. return new (t || _FetchBackend)();
  1277. };
  1278. _FetchBackend.ɵprov = ɵɵdefineInjectable({
  1279. token: _FetchBackend,
  1280. factory: _FetchBackend.ɵfac
  1281. });
  1282. var FetchBackend = _FetchBackend;
  1283. (() => {
  1284. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(FetchBackend, [{
  1285. type: Injectable
  1286. }], null, null);
  1287. })();
  1288. var FetchFactory = class {
  1289. };
  1290. function noop() {
  1291. }
  1292. function silenceSuperfluousUnhandledPromiseRejection(promise) {
  1293. promise.then(noop, noop);
  1294. }
  1295. function interceptorChainEndFn(req, finalHandlerFn) {
  1296. return finalHandlerFn(req);
  1297. }
  1298. function adaptLegacyInterceptorToChain(chainTailFn, interceptor) {
  1299. return (initialRequest, finalHandlerFn) => interceptor.intercept(initialRequest, {
  1300. handle: (downstreamRequest) => chainTailFn(downstreamRequest, finalHandlerFn)
  1301. });
  1302. }
  1303. function chainedInterceptorFn(chainTailFn, interceptorFn, injector) {
  1304. return (initialRequest, finalHandlerFn) => runInInjectionContext(injector, () => interceptorFn(initialRequest, (downstreamRequest) => chainTailFn(downstreamRequest, finalHandlerFn)));
  1305. }
  1306. var HTTP_INTERCEPTORS = new InjectionToken(ngDevMode ? "HTTP_INTERCEPTORS" : "");
  1307. var HTTP_INTERCEPTOR_FNS = new InjectionToken(ngDevMode ? "HTTP_INTERCEPTOR_FNS" : "");
  1308. var HTTP_ROOT_INTERCEPTOR_FNS = new InjectionToken(ngDevMode ? "HTTP_ROOT_INTERCEPTOR_FNS" : "");
  1309. var PRIMARY_HTTP_BACKEND = new InjectionToken(ngDevMode ? "PRIMARY_HTTP_BACKEND" : "");
  1310. function legacyInterceptorFnFactory() {
  1311. let chain = null;
  1312. return (req, handler) => {
  1313. if (chain === null) {
  1314. const interceptors = inject(HTTP_INTERCEPTORS, {
  1315. optional: true
  1316. }) ?? [];
  1317. chain = interceptors.reduceRight(adaptLegacyInterceptorToChain, interceptorChainEndFn);
  1318. }
  1319. const pendingTasks = inject(PendingTasks);
  1320. const taskId = pendingTasks.add();
  1321. return chain(req, handler).pipe(finalize(() => pendingTasks.remove(taskId)));
  1322. };
  1323. }
  1324. var fetchBackendWarningDisplayed = false;
  1325. var _HttpInterceptorHandler = class _HttpInterceptorHandler extends HttpHandler {
  1326. constructor(backend, injector) {
  1327. super();
  1328. this.backend = backend;
  1329. this.injector = injector;
  1330. this.chain = null;
  1331. this.pendingTasks = inject(PendingTasks);
  1332. const primaryHttpBackend = inject(PRIMARY_HTTP_BACKEND, {
  1333. optional: true
  1334. });
  1335. this.backend = primaryHttpBackend ?? backend;
  1336. if ((typeof ngDevMode === "undefined" || ngDevMode) && !fetchBackendWarningDisplayed) {
  1337. const isServer = isPlatformServer(injector.get(PLATFORM_ID));
  1338. if (isServer && !(this.backend instanceof FetchBackend)) {
  1339. fetchBackendWarningDisplayed = true;
  1340. injector.get(Console).warn(formatRuntimeError(2801, "Angular detected that `HttpClient` is not configured to use `fetch` APIs. It's strongly recommended to enable `fetch` for applications that use Server-Side Rendering for better performance and compatibility. To enable `fetch`, add the `withFetch()` to the `provideHttpClient()` call at the root of the application."));
  1341. }
  1342. }
  1343. }
  1344. handle(initialRequest) {
  1345. if (this.chain === null) {
  1346. const dedupedInterceptorFns = Array.from(/* @__PURE__ */ new Set([...this.injector.get(HTTP_INTERCEPTOR_FNS), ...this.injector.get(HTTP_ROOT_INTERCEPTOR_FNS, [])]));
  1347. this.chain = dedupedInterceptorFns.reduceRight((nextSequencedFn, interceptorFn) => chainedInterceptorFn(nextSequencedFn, interceptorFn, this.injector), interceptorChainEndFn);
  1348. }
  1349. const taskId = this.pendingTasks.add();
  1350. return this.chain(initialRequest, (downstreamRequest) => this.backend.handle(downstreamRequest)).pipe(finalize(() => this.pendingTasks.remove(taskId)));
  1351. }
  1352. };
  1353. _HttpInterceptorHandler.ɵfac = function HttpInterceptorHandler_Factory(t) {
  1354. return new (t || _HttpInterceptorHandler)(ɵɵinject(HttpBackend), ɵɵinject(EnvironmentInjector));
  1355. };
  1356. _HttpInterceptorHandler.ɵprov = ɵɵdefineInjectable({
  1357. token: _HttpInterceptorHandler,
  1358. factory: _HttpInterceptorHandler.ɵfac
  1359. });
  1360. var HttpInterceptorHandler = _HttpInterceptorHandler;
  1361. (() => {
  1362. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(HttpInterceptorHandler, [{
  1363. type: Injectable
  1364. }], () => [{
  1365. type: HttpBackend
  1366. }, {
  1367. type: EnvironmentInjector
  1368. }], null);
  1369. })();
  1370. var nextRequestId = 0;
  1371. var foreignDocument;
  1372. var JSONP_ERR_NO_CALLBACK = "JSONP injected script did not invoke callback.";
  1373. var JSONP_ERR_WRONG_METHOD = "JSONP requests must use JSONP request method.";
  1374. var JSONP_ERR_WRONG_RESPONSE_TYPE = "JSONP requests must use Json response type.";
  1375. var JSONP_ERR_HEADERS_NOT_SUPPORTED = "JSONP requests do not support headers.";
  1376. var JsonpCallbackContext = class {
  1377. };
  1378. function jsonpCallbackContext() {
  1379. if (typeof window === "object") {
  1380. return window;
  1381. }
  1382. return {};
  1383. }
  1384. var _JsonpClientBackend = class _JsonpClientBackend {
  1385. constructor(callbackMap, document) {
  1386. this.callbackMap = callbackMap;
  1387. this.document = document;
  1388. this.resolvedPromise = Promise.resolve();
  1389. }
  1390. /**
  1391. * Get the name of the next callback method, by incrementing the global `nextRequestId`.
  1392. */
  1393. nextCallback() {
  1394. return `ng_jsonp_callback_${nextRequestId++}`;
  1395. }
  1396. /**
  1397. * Processes a JSONP request and returns an event stream of the results.
  1398. * @param req The request object.
  1399. * @returns An observable of the response events.
  1400. *
  1401. */
  1402. handle(req) {
  1403. if (req.method !== "JSONP") {
  1404. throw new Error(JSONP_ERR_WRONG_METHOD);
  1405. } else if (req.responseType !== "json") {
  1406. throw new Error(JSONP_ERR_WRONG_RESPONSE_TYPE);
  1407. }
  1408. if (req.headers.keys().length > 0) {
  1409. throw new Error(JSONP_ERR_HEADERS_NOT_SUPPORTED);
  1410. }
  1411. return new Observable((observer) => {
  1412. const callback = this.nextCallback();
  1413. const url = req.urlWithParams.replace(/=JSONP_CALLBACK(&|$)/, `=${callback}$1`);
  1414. const node = this.document.createElement("script");
  1415. node.src = url;
  1416. let body = null;
  1417. let finished = false;
  1418. this.callbackMap[callback] = (data) => {
  1419. delete this.callbackMap[callback];
  1420. body = data;
  1421. finished = true;
  1422. };
  1423. const cleanup = () => {
  1424. if (node.parentNode) {
  1425. node.parentNode.removeChild(node);
  1426. }
  1427. delete this.callbackMap[callback];
  1428. };
  1429. const onLoad = (event) => {
  1430. this.resolvedPromise.then(() => {
  1431. cleanup();
  1432. if (!finished) {
  1433. observer.error(new HttpErrorResponse({
  1434. url,
  1435. status: 0,
  1436. statusText: "JSONP Error",
  1437. error: new Error(JSONP_ERR_NO_CALLBACK)
  1438. }));
  1439. return;
  1440. }
  1441. observer.next(new HttpResponse({
  1442. body,
  1443. status: HttpStatusCode.Ok,
  1444. statusText: "OK",
  1445. url
  1446. }));
  1447. observer.complete();
  1448. });
  1449. };
  1450. const onError = (error) => {
  1451. cleanup();
  1452. observer.error(new HttpErrorResponse({
  1453. error,
  1454. status: 0,
  1455. statusText: "JSONP Error",
  1456. url
  1457. }));
  1458. };
  1459. node.addEventListener("load", onLoad);
  1460. node.addEventListener("error", onError);
  1461. this.document.body.appendChild(node);
  1462. observer.next({
  1463. type: HttpEventType.Sent
  1464. });
  1465. return () => {
  1466. if (!finished) {
  1467. this.removeListeners(node);
  1468. }
  1469. cleanup();
  1470. };
  1471. });
  1472. }
  1473. removeListeners(script) {
  1474. foreignDocument ??= this.document.implementation.createHTMLDocument();
  1475. foreignDocument.adoptNode(script);
  1476. }
  1477. };
  1478. _JsonpClientBackend.ɵfac = function JsonpClientBackend_Factory(t) {
  1479. return new (t || _JsonpClientBackend)(ɵɵinject(JsonpCallbackContext), ɵɵinject(DOCUMENT));
  1480. };
  1481. _JsonpClientBackend.ɵprov = ɵɵdefineInjectable({
  1482. token: _JsonpClientBackend,
  1483. factory: _JsonpClientBackend.ɵfac
  1484. });
  1485. var JsonpClientBackend = _JsonpClientBackend;
  1486. (() => {
  1487. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(JsonpClientBackend, [{
  1488. type: Injectable
  1489. }], () => [{
  1490. type: JsonpCallbackContext
  1491. }, {
  1492. type: void 0,
  1493. decorators: [{
  1494. type: Inject,
  1495. args: [DOCUMENT]
  1496. }]
  1497. }], null);
  1498. })();
  1499. function jsonpInterceptorFn(req, next) {
  1500. if (req.method === "JSONP") {
  1501. return inject(JsonpClientBackend).handle(req);
  1502. }
  1503. return next(req);
  1504. }
  1505. var _JsonpInterceptor = class _JsonpInterceptor {
  1506. constructor(injector) {
  1507. this.injector = injector;
  1508. }
  1509. /**
  1510. * Identifies and handles a given JSONP request.
  1511. * @param initialRequest The outgoing request object to handle.
  1512. * @param next The next interceptor in the chain, or the backend
  1513. * if no interceptors remain in the chain.
  1514. * @returns An observable of the event stream.
  1515. */
  1516. intercept(initialRequest, next) {
  1517. return runInInjectionContext(this.injector, () => jsonpInterceptorFn(initialRequest, (downstreamRequest) => next.handle(downstreamRequest)));
  1518. }
  1519. };
  1520. _JsonpInterceptor.ɵfac = function JsonpInterceptor_Factory(t) {
  1521. return new (t || _JsonpInterceptor)(ɵɵinject(EnvironmentInjector));
  1522. };
  1523. _JsonpInterceptor.ɵprov = ɵɵdefineInjectable({
  1524. token: _JsonpInterceptor,
  1525. factory: _JsonpInterceptor.ɵfac
  1526. });
  1527. var JsonpInterceptor = _JsonpInterceptor;
  1528. (() => {
  1529. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(JsonpInterceptor, [{
  1530. type: Injectable
  1531. }], () => [{
  1532. type: EnvironmentInjector
  1533. }], null);
  1534. })();
  1535. var XSSI_PREFIX = /^\)\]\}',?\n/;
  1536. function getResponseUrl(xhr) {
  1537. if ("responseURL" in xhr && xhr.responseURL) {
  1538. return xhr.responseURL;
  1539. }
  1540. if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
  1541. return xhr.getResponseHeader("X-Request-URL");
  1542. }
  1543. return null;
  1544. }
  1545. var _HttpXhrBackend = class _HttpXhrBackend {
  1546. constructor(xhrFactory) {
  1547. this.xhrFactory = xhrFactory;
  1548. }
  1549. /**
  1550. * Processes a request and returns a stream of response events.
  1551. * @param req The request object.
  1552. * @returns An observable of the response events.
  1553. */
  1554. handle(req) {
  1555. if (req.method === "JSONP") {
  1556. throw new RuntimeError(-2800, (typeof ngDevMode === "undefined" || ngDevMode) && `Cannot make a JSONP request without JSONP support. To fix the problem, either add the \`withJsonpSupport()\` call (if \`provideHttpClient()\` is used) or import the \`HttpClientJsonpModule\` in the root NgModule.`);
  1557. }
  1558. const xhrFactory = this.xhrFactory;
  1559. const source = xhrFactory.ɵloadImpl ? from(xhrFactory.ɵloadImpl()) : of(null);
  1560. return source.pipe(switchMap(() => {
  1561. return new Observable((observer) => {
  1562. const xhr = xhrFactory.build();
  1563. xhr.open(req.method, req.urlWithParams);
  1564. if (req.withCredentials) {
  1565. xhr.withCredentials = true;
  1566. }
  1567. req.headers.forEach((name, values) => xhr.setRequestHeader(name, values.join(",")));
  1568. if (!req.headers.has("Accept")) {
  1569. xhr.setRequestHeader("Accept", "application/json, text/plain, */*");
  1570. }
  1571. if (!req.headers.has("Content-Type")) {
  1572. const detectedType = req.detectContentTypeHeader();
  1573. if (detectedType !== null) {
  1574. xhr.setRequestHeader("Content-Type", detectedType);
  1575. }
  1576. }
  1577. if (req.responseType) {
  1578. const responseType = req.responseType.toLowerCase();
  1579. xhr.responseType = responseType !== "json" ? responseType : "text";
  1580. }
  1581. const reqBody = req.serializeBody();
  1582. let headerResponse = null;
  1583. const partialFromXhr = () => {
  1584. if (headerResponse !== null) {
  1585. return headerResponse;
  1586. }
  1587. const statusText = xhr.statusText || "OK";
  1588. const headers = new HttpHeaders(xhr.getAllResponseHeaders());
  1589. const url = getResponseUrl(xhr) || req.url;
  1590. headerResponse = new HttpHeaderResponse({
  1591. headers,
  1592. status: xhr.status,
  1593. statusText,
  1594. url
  1595. });
  1596. return headerResponse;
  1597. };
  1598. const onLoad = () => {
  1599. let {
  1600. headers,
  1601. status,
  1602. statusText,
  1603. url
  1604. } = partialFromXhr();
  1605. let body = null;
  1606. if (status !== HttpStatusCode.NoContent) {
  1607. body = typeof xhr.response === "undefined" ? xhr.responseText : xhr.response;
  1608. }
  1609. if (status === 0) {
  1610. status = !!body ? HttpStatusCode.Ok : 0;
  1611. }
  1612. let ok = status >= 200 && status < 300;
  1613. if (req.responseType === "json" && typeof body === "string") {
  1614. const originalBody = body;
  1615. body = body.replace(XSSI_PREFIX, "");
  1616. try {
  1617. body = body !== "" ? JSON.parse(body) : null;
  1618. } catch (error) {
  1619. body = originalBody;
  1620. if (ok) {
  1621. ok = false;
  1622. body = {
  1623. error,
  1624. text: body
  1625. };
  1626. }
  1627. }
  1628. }
  1629. if (ok) {
  1630. observer.next(new HttpResponse({
  1631. body,
  1632. headers,
  1633. status,
  1634. statusText,
  1635. url: url || void 0
  1636. }));
  1637. observer.complete();
  1638. } else {
  1639. observer.error(new HttpErrorResponse({
  1640. // The error in this case is the response body (error from the server).
  1641. error: body,
  1642. headers,
  1643. status,
  1644. statusText,
  1645. url: url || void 0
  1646. }));
  1647. }
  1648. };
  1649. const onError = (error) => {
  1650. const {
  1651. url
  1652. } = partialFromXhr();
  1653. const res = new HttpErrorResponse({
  1654. error,
  1655. status: xhr.status || 0,
  1656. statusText: xhr.statusText || "Unknown Error",
  1657. url: url || void 0
  1658. });
  1659. observer.error(res);
  1660. };
  1661. let sentHeaders = false;
  1662. const onDownProgress = (event) => {
  1663. if (!sentHeaders) {
  1664. observer.next(partialFromXhr());
  1665. sentHeaders = true;
  1666. }
  1667. let progressEvent = {
  1668. type: HttpEventType.DownloadProgress,
  1669. loaded: event.loaded
  1670. };
  1671. if (event.lengthComputable) {
  1672. progressEvent.total = event.total;
  1673. }
  1674. if (req.responseType === "text" && !!xhr.responseText) {
  1675. progressEvent.partialText = xhr.responseText;
  1676. }
  1677. observer.next(progressEvent);
  1678. };
  1679. const onUpProgress = (event) => {
  1680. let progress = {
  1681. type: HttpEventType.UploadProgress,
  1682. loaded: event.loaded
  1683. };
  1684. if (event.lengthComputable) {
  1685. progress.total = event.total;
  1686. }
  1687. observer.next(progress);
  1688. };
  1689. xhr.addEventListener("load", onLoad);
  1690. xhr.addEventListener("error", onError);
  1691. xhr.addEventListener("timeout", onError);
  1692. xhr.addEventListener("abort", onError);
  1693. if (req.reportProgress) {
  1694. xhr.addEventListener("progress", onDownProgress);
  1695. if (reqBody !== null && xhr.upload) {
  1696. xhr.upload.addEventListener("progress", onUpProgress);
  1697. }
  1698. }
  1699. xhr.send(reqBody);
  1700. observer.next({
  1701. type: HttpEventType.Sent
  1702. });
  1703. return () => {
  1704. xhr.removeEventListener("error", onError);
  1705. xhr.removeEventListener("abort", onError);
  1706. xhr.removeEventListener("load", onLoad);
  1707. xhr.removeEventListener("timeout", onError);
  1708. if (req.reportProgress) {
  1709. xhr.removeEventListener("progress", onDownProgress);
  1710. if (reqBody !== null && xhr.upload) {
  1711. xhr.upload.removeEventListener("progress", onUpProgress);
  1712. }
  1713. }
  1714. if (xhr.readyState !== xhr.DONE) {
  1715. xhr.abort();
  1716. }
  1717. };
  1718. });
  1719. }));
  1720. }
  1721. };
  1722. _HttpXhrBackend.ɵfac = function HttpXhrBackend_Factory(t) {
  1723. return new (t || _HttpXhrBackend)(ɵɵinject(XhrFactory));
  1724. };
  1725. _HttpXhrBackend.ɵprov = ɵɵdefineInjectable({
  1726. token: _HttpXhrBackend,
  1727. factory: _HttpXhrBackend.ɵfac
  1728. });
  1729. var HttpXhrBackend = _HttpXhrBackend;
  1730. (() => {
  1731. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(HttpXhrBackend, [{
  1732. type: Injectable
  1733. }], () => [{
  1734. type: XhrFactory
  1735. }], null);
  1736. })();
  1737. var XSRF_ENABLED = new InjectionToken(ngDevMode ? "XSRF_ENABLED" : "");
  1738. var XSRF_DEFAULT_COOKIE_NAME = "XSRF-TOKEN";
  1739. var XSRF_COOKIE_NAME = new InjectionToken(ngDevMode ? "XSRF_COOKIE_NAME" : "", {
  1740. providedIn: "root",
  1741. factory: () => XSRF_DEFAULT_COOKIE_NAME
  1742. });
  1743. var XSRF_DEFAULT_HEADER_NAME = "X-XSRF-TOKEN";
  1744. var XSRF_HEADER_NAME = new InjectionToken(ngDevMode ? "XSRF_HEADER_NAME" : "", {
  1745. providedIn: "root",
  1746. factory: () => XSRF_DEFAULT_HEADER_NAME
  1747. });
  1748. var HttpXsrfTokenExtractor = class {
  1749. };
  1750. var _HttpXsrfCookieExtractor = class _HttpXsrfCookieExtractor {
  1751. constructor(doc, platform, cookieName) {
  1752. this.doc = doc;
  1753. this.platform = platform;
  1754. this.cookieName = cookieName;
  1755. this.lastCookieString = "";
  1756. this.lastToken = null;
  1757. this.parseCount = 0;
  1758. }
  1759. getToken() {
  1760. if (this.platform === "server") {
  1761. return null;
  1762. }
  1763. const cookieString = this.doc.cookie || "";
  1764. if (cookieString !== this.lastCookieString) {
  1765. this.parseCount++;
  1766. this.lastToken = parseCookieValue(cookieString, this.cookieName);
  1767. this.lastCookieString = cookieString;
  1768. }
  1769. return this.lastToken;
  1770. }
  1771. };
  1772. _HttpXsrfCookieExtractor.ɵfac = function HttpXsrfCookieExtractor_Factory(t) {
  1773. return new (t || _HttpXsrfCookieExtractor)(ɵɵinject(DOCUMENT), ɵɵinject(PLATFORM_ID), ɵɵinject(XSRF_COOKIE_NAME));
  1774. };
  1775. _HttpXsrfCookieExtractor.ɵprov = ɵɵdefineInjectable({
  1776. token: _HttpXsrfCookieExtractor,
  1777. factory: _HttpXsrfCookieExtractor.ɵfac
  1778. });
  1779. var HttpXsrfCookieExtractor = _HttpXsrfCookieExtractor;
  1780. (() => {
  1781. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(HttpXsrfCookieExtractor, [{
  1782. type: Injectable
  1783. }], () => [{
  1784. type: void 0,
  1785. decorators: [{
  1786. type: Inject,
  1787. args: [DOCUMENT]
  1788. }]
  1789. }, {
  1790. type: void 0,
  1791. decorators: [{
  1792. type: Inject,
  1793. args: [PLATFORM_ID]
  1794. }]
  1795. }, {
  1796. type: void 0,
  1797. decorators: [{
  1798. type: Inject,
  1799. args: [XSRF_COOKIE_NAME]
  1800. }]
  1801. }], null);
  1802. })();
  1803. function xsrfInterceptorFn(req, next) {
  1804. const lcUrl = req.url.toLowerCase();
  1805. if (!inject(XSRF_ENABLED) || req.method === "GET" || req.method === "HEAD" || lcUrl.startsWith("http://") || lcUrl.startsWith("https://")) {
  1806. return next(req);
  1807. }
  1808. const token = inject(HttpXsrfTokenExtractor).getToken();
  1809. const headerName = inject(XSRF_HEADER_NAME);
  1810. if (token != null && !req.headers.has(headerName)) {
  1811. req = req.clone({
  1812. headers: req.headers.set(headerName, token)
  1813. });
  1814. }
  1815. return next(req);
  1816. }
  1817. var _HttpXsrfInterceptor = class _HttpXsrfInterceptor {
  1818. constructor(injector) {
  1819. this.injector = injector;
  1820. }
  1821. intercept(initialRequest, next) {
  1822. return runInInjectionContext(this.injector, () => xsrfInterceptorFn(initialRequest, (downstreamRequest) => next.handle(downstreamRequest)));
  1823. }
  1824. };
  1825. _HttpXsrfInterceptor.ɵfac = function HttpXsrfInterceptor_Factory(t) {
  1826. return new (t || _HttpXsrfInterceptor)(ɵɵinject(EnvironmentInjector));
  1827. };
  1828. _HttpXsrfInterceptor.ɵprov = ɵɵdefineInjectable({
  1829. token: _HttpXsrfInterceptor,
  1830. factory: _HttpXsrfInterceptor.ɵfac
  1831. });
  1832. var HttpXsrfInterceptor = _HttpXsrfInterceptor;
  1833. (() => {
  1834. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(HttpXsrfInterceptor, [{
  1835. type: Injectable
  1836. }], () => [{
  1837. type: EnvironmentInjector
  1838. }], null);
  1839. })();
  1840. var HttpFeatureKind;
  1841. (function(HttpFeatureKind2) {
  1842. HttpFeatureKind2[HttpFeatureKind2["Interceptors"] = 0] = "Interceptors";
  1843. HttpFeatureKind2[HttpFeatureKind2["LegacyInterceptors"] = 1] = "LegacyInterceptors";
  1844. HttpFeatureKind2[HttpFeatureKind2["CustomXsrfConfiguration"] = 2] = "CustomXsrfConfiguration";
  1845. HttpFeatureKind2[HttpFeatureKind2["NoXsrfProtection"] = 3] = "NoXsrfProtection";
  1846. HttpFeatureKind2[HttpFeatureKind2["JsonpSupport"] = 4] = "JsonpSupport";
  1847. HttpFeatureKind2[HttpFeatureKind2["RequestsMadeViaParent"] = 5] = "RequestsMadeViaParent";
  1848. HttpFeatureKind2[HttpFeatureKind2["Fetch"] = 6] = "Fetch";
  1849. })(HttpFeatureKind || (HttpFeatureKind = {}));
  1850. function makeHttpFeature(kind, providers) {
  1851. return {
  1852. ɵkind: kind,
  1853. ɵproviders: providers
  1854. };
  1855. }
  1856. function provideHttpClient(...features) {
  1857. if (ngDevMode) {
  1858. const featureKinds = new Set(features.map((f) => f.ɵkind));
  1859. if (featureKinds.has(HttpFeatureKind.NoXsrfProtection) && featureKinds.has(HttpFeatureKind.CustomXsrfConfiguration)) {
  1860. throw new Error(ngDevMode ? `Configuration error: found both withXsrfConfiguration() and withNoXsrfProtection() in the same call to provideHttpClient(), which is a contradiction.` : "");
  1861. }
  1862. }
  1863. const providers = [HttpClient, HttpXhrBackend, HttpInterceptorHandler, {
  1864. provide: HttpHandler,
  1865. useExisting: HttpInterceptorHandler
  1866. }, {
  1867. provide: HttpBackend,
  1868. useExisting: HttpXhrBackend
  1869. }, {
  1870. provide: HTTP_INTERCEPTOR_FNS,
  1871. useValue: xsrfInterceptorFn,
  1872. multi: true
  1873. }, {
  1874. provide: XSRF_ENABLED,
  1875. useValue: true
  1876. }, {
  1877. provide: HttpXsrfTokenExtractor,
  1878. useClass: HttpXsrfCookieExtractor
  1879. }];
  1880. for (const feature of features) {
  1881. providers.push(...feature.ɵproviders);
  1882. }
  1883. return makeEnvironmentProviders(providers);
  1884. }
  1885. function withInterceptors(interceptorFns) {
  1886. return makeHttpFeature(HttpFeatureKind.Interceptors, interceptorFns.map((interceptorFn) => {
  1887. return {
  1888. provide: HTTP_INTERCEPTOR_FNS,
  1889. useValue: interceptorFn,
  1890. multi: true
  1891. };
  1892. }));
  1893. }
  1894. var LEGACY_INTERCEPTOR_FN = new InjectionToken(ngDevMode ? "LEGACY_INTERCEPTOR_FN" : "");
  1895. function withInterceptorsFromDi() {
  1896. return makeHttpFeature(HttpFeatureKind.LegacyInterceptors, [{
  1897. provide: LEGACY_INTERCEPTOR_FN,
  1898. useFactory: legacyInterceptorFnFactory
  1899. }, {
  1900. provide: HTTP_INTERCEPTOR_FNS,
  1901. useExisting: LEGACY_INTERCEPTOR_FN,
  1902. multi: true
  1903. }]);
  1904. }
  1905. function withXsrfConfiguration({
  1906. cookieName,
  1907. headerName
  1908. }) {
  1909. const providers = [];
  1910. if (cookieName !== void 0) {
  1911. providers.push({
  1912. provide: XSRF_COOKIE_NAME,
  1913. useValue: cookieName
  1914. });
  1915. }
  1916. if (headerName !== void 0) {
  1917. providers.push({
  1918. provide: XSRF_HEADER_NAME,
  1919. useValue: headerName
  1920. });
  1921. }
  1922. return makeHttpFeature(HttpFeatureKind.CustomXsrfConfiguration, providers);
  1923. }
  1924. function withNoXsrfProtection() {
  1925. return makeHttpFeature(HttpFeatureKind.NoXsrfProtection, [{
  1926. provide: XSRF_ENABLED,
  1927. useValue: false
  1928. }]);
  1929. }
  1930. function withJsonpSupport() {
  1931. return makeHttpFeature(HttpFeatureKind.JsonpSupport, [JsonpClientBackend, {
  1932. provide: JsonpCallbackContext,
  1933. useFactory: jsonpCallbackContext
  1934. }, {
  1935. provide: HTTP_INTERCEPTOR_FNS,
  1936. useValue: jsonpInterceptorFn,
  1937. multi: true
  1938. }]);
  1939. }
  1940. function withRequestsMadeViaParent() {
  1941. return makeHttpFeature(HttpFeatureKind.RequestsMadeViaParent, [{
  1942. provide: HttpBackend,
  1943. useFactory: () => {
  1944. const handlerFromParent = inject(HttpHandler, {
  1945. skipSelf: true,
  1946. optional: true
  1947. });
  1948. if (ngDevMode && handlerFromParent === null) {
  1949. throw new Error("withRequestsMadeViaParent() can only be used when the parent injector also configures HttpClient");
  1950. }
  1951. return handlerFromParent;
  1952. }
  1953. }]);
  1954. }
  1955. function withFetch() {
  1956. if ((typeof ngDevMode === "undefined" || ngDevMode) && typeof fetch !== "function") {
  1957. throw new Error("The `withFetch` feature of HttpClient requires the `fetch` API to be available. If you run the code in a Node environment, make sure you use Node v18.10 or later.");
  1958. }
  1959. return makeHttpFeature(HttpFeatureKind.Fetch, [FetchBackend, {
  1960. provide: HttpBackend,
  1961. useExisting: FetchBackend
  1962. }, {
  1963. provide: PRIMARY_HTTP_BACKEND,
  1964. useExisting: FetchBackend
  1965. }]);
  1966. }
  1967. var _HttpClientXsrfModule = class _HttpClientXsrfModule {
  1968. /**
  1969. * Disable the default XSRF protection.
  1970. */
  1971. static disable() {
  1972. return {
  1973. ngModule: _HttpClientXsrfModule,
  1974. providers: [withNoXsrfProtection().ɵproviders]
  1975. };
  1976. }
  1977. /**
  1978. * Configure XSRF protection.
  1979. * @param options An object that can specify either or both
  1980. * cookie name or header name.
  1981. * - Cookie name default is `XSRF-TOKEN`.
  1982. * - Header name default is `X-XSRF-TOKEN`.
  1983. *
  1984. */
  1985. static withOptions(options = {}) {
  1986. return {
  1987. ngModule: _HttpClientXsrfModule,
  1988. providers: withXsrfConfiguration(options).ɵproviders
  1989. };
  1990. }
  1991. };
  1992. _HttpClientXsrfModule.ɵfac = function HttpClientXsrfModule_Factory(t) {
  1993. return new (t || _HttpClientXsrfModule)();
  1994. };
  1995. _HttpClientXsrfModule.ɵmod = ɵɵdefineNgModule({
  1996. type: _HttpClientXsrfModule
  1997. });
  1998. _HttpClientXsrfModule.ɵinj = ɵɵdefineInjector({
  1999. providers: [HttpXsrfInterceptor, {
  2000. provide: HTTP_INTERCEPTORS,
  2001. useExisting: HttpXsrfInterceptor,
  2002. multi: true
  2003. }, {
  2004. provide: HttpXsrfTokenExtractor,
  2005. useClass: HttpXsrfCookieExtractor
  2006. }, withXsrfConfiguration({
  2007. cookieName: XSRF_DEFAULT_COOKIE_NAME,
  2008. headerName: XSRF_DEFAULT_HEADER_NAME
  2009. }).ɵproviders, {
  2010. provide: XSRF_ENABLED,
  2011. useValue: true
  2012. }]
  2013. });
  2014. var HttpClientXsrfModule = _HttpClientXsrfModule;
  2015. (() => {
  2016. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(HttpClientXsrfModule, [{
  2017. type: NgModule,
  2018. args: [{
  2019. providers: [HttpXsrfInterceptor, {
  2020. provide: HTTP_INTERCEPTORS,
  2021. useExisting: HttpXsrfInterceptor,
  2022. multi: true
  2023. }, {
  2024. provide: HttpXsrfTokenExtractor,
  2025. useClass: HttpXsrfCookieExtractor
  2026. }, withXsrfConfiguration({
  2027. cookieName: XSRF_DEFAULT_COOKIE_NAME,
  2028. headerName: XSRF_DEFAULT_HEADER_NAME
  2029. }).ɵproviders, {
  2030. provide: XSRF_ENABLED,
  2031. useValue: true
  2032. }]
  2033. }]
  2034. }], null, null);
  2035. })();
  2036. var _HttpClientModule = class _HttpClientModule {
  2037. };
  2038. _HttpClientModule.ɵfac = function HttpClientModule_Factory(t) {
  2039. return new (t || _HttpClientModule)();
  2040. };
  2041. _HttpClientModule.ɵmod = ɵɵdefineNgModule({
  2042. type: _HttpClientModule
  2043. });
  2044. _HttpClientModule.ɵinj = ɵɵdefineInjector({
  2045. providers: [provideHttpClient(withInterceptorsFromDi())]
  2046. });
  2047. var HttpClientModule = _HttpClientModule;
  2048. (() => {
  2049. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(HttpClientModule, [{
  2050. type: NgModule,
  2051. args: [{
  2052. /**
  2053. * Configures the [dependency injector](guide/glossary#injector) where it is imported
  2054. * with supporting services for HTTP communications.
  2055. */
  2056. providers: [provideHttpClient(withInterceptorsFromDi())]
  2057. }]
  2058. }], null, null);
  2059. })();
  2060. var _HttpClientJsonpModule = class _HttpClientJsonpModule {
  2061. };
  2062. _HttpClientJsonpModule.ɵfac = function HttpClientJsonpModule_Factory(t) {
  2063. return new (t || _HttpClientJsonpModule)();
  2064. };
  2065. _HttpClientJsonpModule.ɵmod = ɵɵdefineNgModule({
  2066. type: _HttpClientJsonpModule
  2067. });
  2068. _HttpClientJsonpModule.ɵinj = ɵɵdefineInjector({
  2069. providers: [withJsonpSupport().ɵproviders]
  2070. });
  2071. var HttpClientJsonpModule = _HttpClientJsonpModule;
  2072. (() => {
  2073. (typeof ngDevMode === "undefined" || ngDevMode) && setClassMetadata(HttpClientJsonpModule, [{
  2074. type: NgModule,
  2075. args: [{
  2076. providers: [withJsonpSupport().ɵproviders]
  2077. }]
  2078. }], null, null);
  2079. })();
  2080. var BODY = "b";
  2081. var HEADERS = "h";
  2082. var STATUS = "s";
  2083. var STATUS_TEXT = "st";
  2084. var URL = "u";
  2085. var RESPONSE_TYPE = "rt";
  2086. var CACHE_OPTIONS = new InjectionToken(ngDevMode ? "HTTP_TRANSFER_STATE_CACHE_OPTIONS" : "");
  2087. var ALLOWED_METHODS = ["GET", "HEAD"];
  2088. function transferCacheInterceptorFn(req, next) {
  2089. const _a = inject(CACHE_OPTIONS), {
  2090. isCacheActive
  2091. } = _a, globalOptions = __objRest(_a, [
  2092. "isCacheActive"
  2093. ]);
  2094. const {
  2095. transferCache: requestOptions,
  2096. method: requestMethod
  2097. } = req;
  2098. if (!isCacheActive || // POST requests are allowed either globally or at request level
  2099. requestMethod === "POST" && !globalOptions.includePostRequests && !requestOptions || requestMethod !== "POST" && !ALLOWED_METHODS.includes(requestMethod) || requestOptions === false || //
  2100. globalOptions.filter?.(req) === false) {
  2101. return next(req);
  2102. }
  2103. const transferState = inject(TransferState);
  2104. const storeKey = makeCacheKey(req);
  2105. const response = transferState.get(storeKey, null);
  2106. let headersToInclude = globalOptions.includeHeaders;
  2107. if (typeof requestOptions === "object" && requestOptions.includeHeaders) {
  2108. headersToInclude = requestOptions.includeHeaders;
  2109. }
  2110. if (response) {
  2111. const {
  2112. [BODY]: undecodedBody,
  2113. [RESPONSE_TYPE]: responseType,
  2114. [HEADERS]: httpHeaders,
  2115. [STATUS]: status,
  2116. [STATUS_TEXT]: statusText,
  2117. [URL]: url
  2118. } = response;
  2119. let body = undecodedBody;
  2120. switch (responseType) {
  2121. case "arraybuffer":
  2122. body = new TextEncoder().encode(undecodedBody).buffer;
  2123. break;
  2124. case "blob":
  2125. body = new Blob([undecodedBody]);
  2126. break;
  2127. }
  2128. let headers = new HttpHeaders(httpHeaders);
  2129. if (typeof ngDevMode === "undefined" || ngDevMode) {
  2130. headers = appendMissingHeadersDetection(req.url, headers, headersToInclude ?? []);
  2131. }
  2132. return of(new HttpResponse({
  2133. body,
  2134. headers,
  2135. status,
  2136. statusText,
  2137. url
  2138. }));
  2139. }
  2140. return next(req).pipe(tap((event) => {
  2141. if (event instanceof HttpResponse) {
  2142. transferState.set(storeKey, {
  2143. [BODY]: event.body,
  2144. [HEADERS]: getFilteredHeaders(event.headers, headersToInclude),
  2145. [STATUS]: event.status,
  2146. [STATUS_TEXT]: event.statusText,
  2147. [URL]: event.url || "",
  2148. [RESPONSE_TYPE]: req.responseType
  2149. });
  2150. }
  2151. }));
  2152. }
  2153. function getFilteredHeaders(headers, includeHeaders) {
  2154. if (!includeHeaders) {
  2155. return {};
  2156. }
  2157. const headersMap = {};
  2158. for (const key of includeHeaders) {
  2159. const values = headers.getAll(key);
  2160. if (values !== null) {
  2161. headersMap[key] = values;
  2162. }
  2163. }
  2164. return headersMap;
  2165. }
  2166. function makeCacheKey(request) {
  2167. const {
  2168. params,
  2169. method,
  2170. responseType,
  2171. url,
  2172. body
  2173. } = request;
  2174. const encodedParams = params.keys().sort().map((k) => `${k}=${params.getAll(k)}`).join("&");
  2175. const strBody = typeof body === "string" ? body : "";
  2176. const key = [method, responseType, url, strBody, encodedParams].join("|");
  2177. const hash = generateHash(key);
  2178. return makeStateKey(hash);
  2179. }
  2180. function generateHash(value) {
  2181. let hash = 0;
  2182. for (const char of value) {
  2183. hash = Math.imul(31, hash) + char.charCodeAt(0) << 0;
  2184. }
  2185. hash += 2147483647 + 1;
  2186. return hash.toString();
  2187. }
  2188. function withHttpTransferCache(cacheOptions) {
  2189. return [{
  2190. provide: CACHE_OPTIONS,
  2191. useFactory: () => {
  2192. performanceMarkFeature("NgHttpTransferCache");
  2193. return __spreadValues({
  2194. isCacheActive: true
  2195. }, cacheOptions);
  2196. }
  2197. }, {
  2198. provide: HTTP_ROOT_INTERCEPTOR_FNS,
  2199. useValue: transferCacheInterceptorFn,
  2200. multi: true,
  2201. deps: [TransferState, CACHE_OPTIONS]
  2202. }, {
  2203. provide: APP_BOOTSTRAP_LISTENER,
  2204. multi: true,
  2205. useFactory: () => {
  2206. const appRef = inject(ApplicationRef);
  2207. const cacheState = inject(CACHE_OPTIONS);
  2208. return () => {
  2209. whenStable(appRef).then(() => {
  2210. cacheState.isCacheActive = false;
  2211. });
  2212. };
  2213. }
  2214. }];
  2215. }
  2216. function appendMissingHeadersDetection(url, headers, headersToInclude) {
  2217. const warningProduced = /* @__PURE__ */ new Set();
  2218. return new Proxy(headers, {
  2219. get(target, prop) {
  2220. const value = Reflect.get(target, prop);
  2221. const methods = /* @__PURE__ */ new Set(["get", "has", "getAll"]);
  2222. if (typeof value !== "function" || !methods.has(prop)) {
  2223. return value;
  2224. }
  2225. return (headerName) => {
  2226. const key = (prop + ":" + headerName).toLowerCase();
  2227. if (!headersToInclude.includes(headerName) && !warningProduced.has(key)) {
  2228. warningProduced.add(key);
  2229. const truncatedUrl = truncateMiddle(url);
  2230. console.warn(formatRuntimeError(2802, `Angular detected that the \`${headerName}\` header is accessed, but the value of the header was not transferred from the server to the client by the HttpTransferCache. To include the value of the \`${headerName}\` header for the \`${truncatedUrl}\` request, use the \`includeHeaders\` list. The \`includeHeaders\` can be defined either on a request level by adding the \`transferCache\` parameter, or on an application level by adding the \`httpCacheTransfer.includeHeaders\` argument to the \`provideClientHydration()\` call. `));
  2231. }
  2232. return value.apply(target, [headerName]);
  2233. };
  2234. }
  2235. });
  2236. }
  2237. export {
  2238. HttpHandler,
  2239. HttpBackend,
  2240. HttpHeaders,
  2241. HttpUrlEncodingCodec,
  2242. HttpParams,
  2243. HttpContextToken,
  2244. HttpContext,
  2245. HttpRequest,
  2246. HttpEventType,
  2247. HttpResponseBase,
  2248. HttpHeaderResponse,
  2249. HttpResponse,
  2250. HttpErrorResponse,
  2251. HttpStatusCode,
  2252. HttpClient,
  2253. FetchBackend,
  2254. HTTP_INTERCEPTORS,
  2255. HTTP_ROOT_INTERCEPTOR_FNS,
  2256. PRIMARY_HTTP_BACKEND,
  2257. HttpInterceptorHandler,
  2258. JsonpClientBackend,
  2259. JsonpInterceptor,
  2260. HttpXhrBackend,
  2261. HttpXsrfTokenExtractor,
  2262. HttpFeatureKind,
  2263. provideHttpClient,
  2264. withInterceptors,
  2265. withInterceptorsFromDi,
  2266. withXsrfConfiguration,
  2267. withNoXsrfProtection,
  2268. withJsonpSupport,
  2269. withRequestsMadeViaParent,
  2270. withFetch,
  2271. HttpClientXsrfModule,
  2272. HttpClientModule,
  2273. HttpClientJsonpModule,
  2274. withHttpTransferCache
  2275. };
  2276. /*! Bundled license information:
  2277. @angular/common/fesm2022/http.mjs:
  2278. (**
  2279. * @license Angular v17.2.2
  2280. * (c) 2010-2022 Google LLC. https://angular.io/
  2281. * License: MIT
  2282. *)
  2283. */
  2284. //# sourceMappingURL=chunk-65KGLH7J.js.map