common-http.umd.js 103KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/observable/of'), require('rxjs/operator/concatMap'), require('rxjs/operator/filter'), require('rxjs/operator/map'), require('tslib'), require('@angular/common'), require('rxjs/Observable')) :
  8. typeof define === 'function' && define.amd ? define('@angular/common/http', ['exports', '@angular/core', 'rxjs/observable/of', 'rxjs/operator/concatMap', 'rxjs/operator/filter', 'rxjs/operator/map', 'tslib', '@angular/common', 'rxjs/Observable'], factory) :
  9. (factory((global.ng = global.ng || {}, global.ng.common = global.ng.common || {}, global.ng.common.http = {}),global.ng.core,global.Rx.Observable,global.Rx.Observable.prototype,global.Rx.Observable.prototype,global.Rx.Observable.prototype,global.tslib,global.ng.common,global.Rx));
  10. }(this, (function (exports,_angular_core,rxjs_observable_of,rxjs_operator_concatMap,rxjs_operator_filter,rxjs_operator_map,tslib,_angular_common,rxjs_Observable) { 'use strict';
  11. /**
  12. * @license Angular v5.2.11
  13. * (c) 2010-2018 Google, Inc. https://angular.io/
  14. * License: MIT
  15. */
  16. /**
  17. * @fileoverview added by tsickle
  18. * @suppress {checkTypes} checked by tsc
  19. */
  20. /**
  21. * @license
  22. * Copyright Google Inc. All Rights Reserved.
  23. *
  24. * Use of this source code is governed by an MIT-style license that can be
  25. * found in the LICENSE file at https://angular.io/license
  26. */
  27. /**
  28. * Transforms an `HttpRequest` into a stream of `HttpEvent`s, one of which will likely be a
  29. * `HttpResponse`.
  30. *
  31. * `HttpHandler` is injectable. When injected, the handler instance dispatches requests to the
  32. * first interceptor in the chain, which dispatches to the second, etc, eventually reaching the
  33. * `HttpBackend`.
  34. *
  35. * In an `HttpInterceptor`, the `HttpHandler` parameter is the next interceptor in the chain.
  36. *
  37. * \@stable
  38. * @abstract
  39. */
  40. var HttpHandler = /** @class */ (function () {
  41. function HttpHandler() {
  42. }
  43. return HttpHandler;
  44. }());
  45. /**
  46. * A final `HttpHandler` which will dispatch the request via browser HTTP APIs to a backend.
  47. *
  48. * Interceptors sit between the `HttpClient` interface and the `HttpBackend`.
  49. *
  50. * When injected, `HttpBackend` dispatches requests directly to the backend, without going
  51. * through the interceptor chain.
  52. *
  53. * \@stable
  54. * @abstract
  55. */
  56. var HttpBackend = /** @class */ (function () {
  57. function HttpBackend() {
  58. }
  59. return HttpBackend;
  60. }());
  61. /**
  62. * @fileoverview added by tsickle
  63. * @suppress {checkTypes} checked by tsc
  64. */
  65. /**
  66. * @license
  67. * Copyright Google Inc. All Rights Reserved.
  68. *
  69. * Use of this source code is governed by an MIT-style license that can be
  70. * found in the LICENSE file at https://angular.io/license
  71. */
  72. /**
  73. * @record
  74. */
  75. /**
  76. * Immutable set of Http headers, with lazy parsing.
  77. * \@stable
  78. */
  79. var HttpHeaders = /** @class */ (function () {
  80. function HttpHeaders(headers) {
  81. var _this = this;
  82. /**
  83. * Internal map of lowercased header names to the normalized
  84. * form of the name (the form seen first).
  85. */
  86. this.normalizedNames = new Map();
  87. /**
  88. * Queued updates to be materialized the next initialization.
  89. */
  90. this.lazyUpdate = null;
  91. if (!headers) {
  92. this.headers = new Map();
  93. }
  94. else if (typeof headers === 'string') {
  95. this.lazyInit = function () {
  96. _this.headers = new Map();
  97. headers.split('\n').forEach(function (line) {
  98. var /** @type {?} */ index = line.indexOf(':');
  99. if (index > 0) {
  100. var /** @type {?} */ name_1 = line.slice(0, index);
  101. var /** @type {?} */ key = name_1.toLowerCase();
  102. var /** @type {?} */ value = line.slice(index + 1).trim();
  103. _this.maybeSetNormalizedName(name_1, key);
  104. if (_this.headers.has(key)) {
  105. /** @type {?} */ ((_this.headers.get(key))).push(value);
  106. }
  107. else {
  108. _this.headers.set(key, [value]);
  109. }
  110. }
  111. });
  112. };
  113. }
  114. else {
  115. this.lazyInit = function () {
  116. _this.headers = new Map();
  117. Object.keys(headers).forEach(function (name) {
  118. var /** @type {?} */ values = headers[name];
  119. var /** @type {?} */ key = name.toLowerCase();
  120. if (typeof values === 'string') {
  121. values = [values];
  122. }
  123. if (values.length > 0) {
  124. _this.headers.set(key, values);
  125. _this.maybeSetNormalizedName(name, key);
  126. }
  127. });
  128. };
  129. }
  130. }
  131. /**
  132. * Checks for existence of header by given name.
  133. */
  134. /**
  135. * Checks for existence of header by given name.
  136. * @param {?} name
  137. * @return {?}
  138. */
  139. HttpHeaders.prototype.has = /**
  140. * Checks for existence of header by given name.
  141. * @param {?} name
  142. * @return {?}
  143. */
  144. function (name) {
  145. this.init();
  146. return this.headers.has(name.toLowerCase());
  147. };
  148. /**
  149. * Returns first header that matches given name.
  150. */
  151. /**
  152. * Returns first header that matches given name.
  153. * @param {?} name
  154. * @return {?}
  155. */
  156. HttpHeaders.prototype.get = /**
  157. * Returns first header that matches given name.
  158. * @param {?} name
  159. * @return {?}
  160. */
  161. function (name) {
  162. this.init();
  163. var /** @type {?} */ values = this.headers.get(name.toLowerCase());
  164. return values && values.length > 0 ? values[0] : null;
  165. };
  166. /**
  167. * Returns the names of the headers
  168. */
  169. /**
  170. * Returns the names of the headers
  171. * @return {?}
  172. */
  173. HttpHeaders.prototype.keys = /**
  174. * Returns the names of the headers
  175. * @return {?}
  176. */
  177. function () {
  178. this.init();
  179. return Array.from(this.normalizedNames.values());
  180. };
  181. /**
  182. * Returns list of header values for a given name.
  183. */
  184. /**
  185. * Returns list of header values for a given name.
  186. * @param {?} name
  187. * @return {?}
  188. */
  189. HttpHeaders.prototype.getAll = /**
  190. * Returns list of header values for a given name.
  191. * @param {?} name
  192. * @return {?}
  193. */
  194. function (name) {
  195. this.init();
  196. return this.headers.get(name.toLowerCase()) || null;
  197. };
  198. /**
  199. * @param {?} name
  200. * @param {?} value
  201. * @return {?}
  202. */
  203. HttpHeaders.prototype.append = /**
  204. * @param {?} name
  205. * @param {?} value
  206. * @return {?}
  207. */
  208. function (name, value) {
  209. return this.clone({ name: name, value: value, op: 'a' });
  210. };
  211. /**
  212. * @param {?} name
  213. * @param {?} value
  214. * @return {?}
  215. */
  216. HttpHeaders.prototype.set = /**
  217. * @param {?} name
  218. * @param {?} value
  219. * @return {?}
  220. */
  221. function (name, value) {
  222. return this.clone({ name: name, value: value, op: 's' });
  223. };
  224. /**
  225. * @param {?} name
  226. * @param {?=} value
  227. * @return {?}
  228. */
  229. HttpHeaders.prototype.delete = /**
  230. * @param {?} name
  231. * @param {?=} value
  232. * @return {?}
  233. */
  234. function (name, value) {
  235. return this.clone({ name: name, value: value, op: 'd' });
  236. };
  237. /**
  238. * @param {?} name
  239. * @param {?} lcName
  240. * @return {?}
  241. */
  242. HttpHeaders.prototype.maybeSetNormalizedName = /**
  243. * @param {?} name
  244. * @param {?} lcName
  245. * @return {?}
  246. */
  247. function (name, lcName) {
  248. if (!this.normalizedNames.has(lcName)) {
  249. this.normalizedNames.set(lcName, name);
  250. }
  251. };
  252. /**
  253. * @return {?}
  254. */
  255. HttpHeaders.prototype.init = /**
  256. * @return {?}
  257. */
  258. function () {
  259. var _this = this;
  260. if (!!this.lazyInit) {
  261. if (this.lazyInit instanceof HttpHeaders) {
  262. this.copyFrom(this.lazyInit);
  263. }
  264. else {
  265. this.lazyInit();
  266. }
  267. this.lazyInit = null;
  268. if (!!this.lazyUpdate) {
  269. this.lazyUpdate.forEach(function (update) { return _this.applyUpdate(update); });
  270. this.lazyUpdate = null;
  271. }
  272. }
  273. };
  274. /**
  275. * @param {?} other
  276. * @return {?}
  277. */
  278. HttpHeaders.prototype.copyFrom = /**
  279. * @param {?} other
  280. * @return {?}
  281. */
  282. function (other) {
  283. var _this = this;
  284. other.init();
  285. Array.from(other.headers.keys()).forEach(function (key) {
  286. _this.headers.set(key, /** @type {?} */ ((other.headers.get(key))));
  287. _this.normalizedNames.set(key, /** @type {?} */ ((other.normalizedNames.get(key))));
  288. });
  289. };
  290. /**
  291. * @param {?} update
  292. * @return {?}
  293. */
  294. HttpHeaders.prototype.clone = /**
  295. * @param {?} update
  296. * @return {?}
  297. */
  298. function (update) {
  299. var /** @type {?} */ clone = new HttpHeaders();
  300. clone.lazyInit =
  301. (!!this.lazyInit && this.lazyInit instanceof HttpHeaders) ? this.lazyInit : this;
  302. clone.lazyUpdate = (this.lazyUpdate || []).concat([update]);
  303. return clone;
  304. };
  305. /**
  306. * @param {?} update
  307. * @return {?}
  308. */
  309. HttpHeaders.prototype.applyUpdate = /**
  310. * @param {?} update
  311. * @return {?}
  312. */
  313. function (update) {
  314. var /** @type {?} */ key = update.name.toLowerCase();
  315. switch (update.op) {
  316. case 'a':
  317. case 's':
  318. var /** @type {?} */ value = /** @type {?} */ ((update.value));
  319. if (typeof value === 'string') {
  320. value = [value];
  321. }
  322. if (value.length === 0) {
  323. return;
  324. }
  325. this.maybeSetNormalizedName(update.name, key);
  326. var /** @type {?} */ base = (update.op === 'a' ? this.headers.get(key) : undefined) || [];
  327. base.push.apply(base, value);
  328. this.headers.set(key, base);
  329. break;
  330. case 'd':
  331. var /** @type {?} */ toDelete_1 = /** @type {?} */ (update.value);
  332. if (!toDelete_1) {
  333. this.headers.delete(key);
  334. this.normalizedNames.delete(key);
  335. }
  336. else {
  337. var /** @type {?} */ existing = this.headers.get(key);
  338. if (!existing) {
  339. return;
  340. }
  341. existing = existing.filter(function (value) { return toDelete_1.indexOf(value) === -1; });
  342. if (existing.length === 0) {
  343. this.headers.delete(key);
  344. this.normalizedNames.delete(key);
  345. }
  346. else {
  347. this.headers.set(key, existing);
  348. }
  349. }
  350. break;
  351. }
  352. };
  353. /**
  354. * @internal
  355. */
  356. /**
  357. * \@internal
  358. * @param {?} fn
  359. * @return {?}
  360. */
  361. HttpHeaders.prototype.forEach = /**
  362. * \@internal
  363. * @param {?} fn
  364. * @return {?}
  365. */
  366. function (fn) {
  367. var _this = this;
  368. this.init();
  369. Array.from(this.normalizedNames.keys())
  370. .forEach(function (key) { return fn(/** @type {?} */ ((_this.normalizedNames.get(key))), /** @type {?} */ ((_this.headers.get(key)))); });
  371. };
  372. return HttpHeaders;
  373. }());
  374. /**
  375. * @fileoverview added by tsickle
  376. * @suppress {checkTypes} checked by tsc
  377. */
  378. /**
  379. * @license
  380. * Copyright Google Inc. All Rights Reserved.
  381. *
  382. * Use of this source code is governed by an MIT-style license that can be
  383. * found in the LICENSE file at https://angular.io/license
  384. */
  385. /**
  386. * A codec for encoding and decoding parameters in URLs.
  387. *
  388. * Used by `HttpParams`.
  389. *
  390. * \@stable
  391. *
  392. * @record
  393. */
  394. /**
  395. * A `HttpParameterCodec` that uses `encodeURIComponent` and `decodeURIComponent` to
  396. * serialize and parse URL parameter keys and values.
  397. *
  398. * \@stable
  399. */
  400. var HttpUrlEncodingCodec = /** @class */ (function () {
  401. function HttpUrlEncodingCodec() {
  402. }
  403. /**
  404. * @param {?} k
  405. * @return {?}
  406. */
  407. HttpUrlEncodingCodec.prototype.encodeKey = /**
  408. * @param {?} k
  409. * @return {?}
  410. */
  411. function (k) { return standardEncoding(k); };
  412. /**
  413. * @param {?} v
  414. * @return {?}
  415. */
  416. HttpUrlEncodingCodec.prototype.encodeValue = /**
  417. * @param {?} v
  418. * @return {?}
  419. */
  420. function (v) { return standardEncoding(v); };
  421. /**
  422. * @param {?} k
  423. * @return {?}
  424. */
  425. HttpUrlEncodingCodec.prototype.decodeKey = /**
  426. * @param {?} k
  427. * @return {?}
  428. */
  429. function (k) { return decodeURIComponent(k); };
  430. /**
  431. * @param {?} v
  432. * @return {?}
  433. */
  434. HttpUrlEncodingCodec.prototype.decodeValue = /**
  435. * @param {?} v
  436. * @return {?}
  437. */
  438. function (v) { return decodeURIComponent(v); };
  439. return HttpUrlEncodingCodec;
  440. }());
  441. /**
  442. * @param {?} rawParams
  443. * @param {?} codec
  444. * @return {?}
  445. */
  446. function paramParser(rawParams, codec) {
  447. var /** @type {?} */ map$$1 = new Map();
  448. if (rawParams.length > 0) {
  449. var /** @type {?} */ params = rawParams.split('&');
  450. params.forEach(function (param) {
  451. var /** @type {?} */ eqIdx = param.indexOf('=');
  452. var _a = eqIdx == -1 ?
  453. [codec.decodeKey(param), ''] :
  454. [codec.decodeKey(param.slice(0, eqIdx)), codec.decodeValue(param.slice(eqIdx + 1))], key = _a[0], val = _a[1];
  455. var /** @type {?} */ list = map$$1.get(key) || [];
  456. list.push(val);
  457. map$$1.set(key, list);
  458. });
  459. }
  460. return map$$1;
  461. }
  462. /**
  463. * @param {?} v
  464. * @return {?}
  465. */
  466. function standardEncoding(v) {
  467. return encodeURIComponent(v)
  468. .replace(/%40/gi, '@')
  469. .replace(/%3A/gi, ':')
  470. .replace(/%24/gi, '$')
  471. .replace(/%2C/gi, ',')
  472. .replace(/%3B/gi, ';')
  473. .replace(/%2B/gi, '+')
  474. .replace(/%3D/gi, '=')
  475. .replace(/%3F/gi, '?')
  476. .replace(/%2F/gi, '/');
  477. }
  478. /**
  479. * An HTTP request/response body that represents serialized parameters,
  480. * per the MIME type `application/x-www-form-urlencoded`.
  481. *
  482. * This class is immutable - all mutation operations return a new instance.
  483. *
  484. * \@stable
  485. */
  486. var HttpParams = /** @class */ (function () {
  487. function HttpParams(options) {
  488. if (options === void 0) { options = /** @type {?} */ ({}); }
  489. var _this = this;
  490. this.updates = null;
  491. this.cloneFrom = null;
  492. this.encoder = options.encoder || new HttpUrlEncodingCodec();
  493. if (!!options.fromString) {
  494. if (!!options.fromObject) {
  495. throw new Error("Cannot specify both fromString and fromObject.");
  496. }
  497. this.map = paramParser(options.fromString, this.encoder);
  498. }
  499. else if (!!options.fromObject) {
  500. this.map = new Map();
  501. Object.keys(options.fromObject).forEach(function (key) {
  502. var /** @type {?} */ value = (/** @type {?} */ (options.fromObject))[key]; /** @type {?} */
  503. ((_this.map)).set(key, Array.isArray(value) ? value : [value]);
  504. });
  505. }
  506. else {
  507. this.map = null;
  508. }
  509. }
  510. /**
  511. * Check whether the body has one or more values for the given parameter name.
  512. */
  513. /**
  514. * Check whether the body has one or more values for the given parameter name.
  515. * @param {?} param
  516. * @return {?}
  517. */
  518. HttpParams.prototype.has = /**
  519. * Check whether the body has one or more values for the given parameter name.
  520. * @param {?} param
  521. * @return {?}
  522. */
  523. function (param) {
  524. this.init();
  525. return /** @type {?} */ ((this.map)).has(param);
  526. };
  527. /**
  528. * Get the first value for the given parameter name, or `null` if it's not present.
  529. */
  530. /**
  531. * Get the first value for the given parameter name, or `null` if it's not present.
  532. * @param {?} param
  533. * @return {?}
  534. */
  535. HttpParams.prototype.get = /**
  536. * Get the first value for the given parameter name, or `null` if it's not present.
  537. * @param {?} param
  538. * @return {?}
  539. */
  540. function (param) {
  541. this.init();
  542. var /** @type {?} */ res = /** @type {?} */ ((this.map)).get(param);
  543. return !!res ? res[0] : null;
  544. };
  545. /**
  546. * Get all values for the given parameter name, or `null` if it's not present.
  547. */
  548. /**
  549. * Get all values for the given parameter name, or `null` if it's not present.
  550. * @param {?} param
  551. * @return {?}
  552. */
  553. HttpParams.prototype.getAll = /**
  554. * Get all values for the given parameter name, or `null` if it's not present.
  555. * @param {?} param
  556. * @return {?}
  557. */
  558. function (param) {
  559. this.init();
  560. return /** @type {?} */ ((this.map)).get(param) || null;
  561. };
  562. /**
  563. * Get all the parameter names for this body.
  564. */
  565. /**
  566. * Get all the parameter names for this body.
  567. * @return {?}
  568. */
  569. HttpParams.prototype.keys = /**
  570. * Get all the parameter names for this body.
  571. * @return {?}
  572. */
  573. function () {
  574. this.init();
  575. return Array.from(/** @type {?} */ ((this.map)).keys());
  576. };
  577. /**
  578. * Construct a new body with an appended value for the given parameter name.
  579. */
  580. /**
  581. * Construct a new body with an appended value for the given parameter name.
  582. * @param {?} param
  583. * @param {?} value
  584. * @return {?}
  585. */
  586. HttpParams.prototype.append = /**
  587. * Construct a new body with an appended value for the given parameter name.
  588. * @param {?} param
  589. * @param {?} value
  590. * @return {?}
  591. */
  592. function (param, value) { return this.clone({ param: param, value: value, op: 'a' }); };
  593. /**
  594. * Construct a new body with a new value for the given parameter name.
  595. */
  596. /**
  597. * Construct a new body with a new value for the given parameter name.
  598. * @param {?} param
  599. * @param {?} value
  600. * @return {?}
  601. */
  602. HttpParams.prototype.set = /**
  603. * Construct a new body with a new value for the given parameter name.
  604. * @param {?} param
  605. * @param {?} value
  606. * @return {?}
  607. */
  608. function (param, value) { return this.clone({ param: param, value: value, op: 's' }); };
  609. /**
  610. * Construct a new body with either the given value for the given parameter
  611. * removed, if a value is given, or all values for the given parameter removed
  612. * if not.
  613. */
  614. /**
  615. * Construct a new body with either the given value for the given parameter
  616. * removed, if a value is given, or all values for the given parameter removed
  617. * if not.
  618. * @param {?} param
  619. * @param {?=} value
  620. * @return {?}
  621. */
  622. HttpParams.prototype.delete = /**
  623. * Construct a new body with either the given value for the given parameter
  624. * removed, if a value is given, or all values for the given parameter removed
  625. * if not.
  626. * @param {?} param
  627. * @param {?=} value
  628. * @return {?}
  629. */
  630. function (param, value) { return this.clone({ param: param, value: value, op: 'd' }); };
  631. /**
  632. * Serialize the body to an encoded string, where key-value pairs (separated by `=`) are
  633. * separated by `&`s.
  634. */
  635. /**
  636. * Serialize the body to an encoded string, where key-value pairs (separated by `=`) are
  637. * separated by `&`s.
  638. * @return {?}
  639. */
  640. HttpParams.prototype.toString = /**
  641. * Serialize the body to an encoded string, where key-value pairs (separated by `=`) are
  642. * separated by `&`s.
  643. * @return {?}
  644. */
  645. function () {
  646. var _this = this;
  647. this.init();
  648. return this.keys()
  649. .map(function (key) {
  650. var /** @type {?} */ eKey = _this.encoder.encodeKey(key);
  651. return /** @type {?} */ ((/** @type {?} */ ((_this.map)).get(key))).map(function (value) { return eKey + '=' + _this.encoder.encodeValue(value); }).join('&');
  652. })
  653. .join('&');
  654. };
  655. /**
  656. * @param {?} update
  657. * @return {?}
  658. */
  659. HttpParams.prototype.clone = /**
  660. * @param {?} update
  661. * @return {?}
  662. */
  663. function (update) {
  664. var /** @type {?} */ clone = new HttpParams({ encoder: this.encoder });
  665. clone.cloneFrom = this.cloneFrom || this;
  666. clone.updates = (this.updates || []).concat([update]);
  667. return clone;
  668. };
  669. /**
  670. * @return {?}
  671. */
  672. HttpParams.prototype.init = /**
  673. * @return {?}
  674. */
  675. function () {
  676. var _this = this;
  677. if (this.map === null) {
  678. this.map = new Map();
  679. }
  680. if (this.cloneFrom !== null) {
  681. this.cloneFrom.init();
  682. this.cloneFrom.keys().forEach(function (key) { return ((_this.map)).set(key, /** @type {?} */ ((/** @type {?} */ ((/** @type {?} */ ((_this.cloneFrom)).map)).get(key)))); }); /** @type {?} */
  683. ((this.updates)).forEach(function (update) {
  684. switch (update.op) {
  685. case 'a':
  686. case 's':
  687. var /** @type {?} */ base = (update.op === 'a' ? /** @type {?} */ ((_this.map)).get(update.param) : undefined) || [];
  688. base.push(/** @type {?} */ ((update.value))); /** @type {?} */
  689. ((_this.map)).set(update.param, base);
  690. break;
  691. case 'd':
  692. if (update.value !== undefined) {
  693. var /** @type {?} */ base_1 = /** @type {?} */ ((_this.map)).get(update.param) || [];
  694. var /** @type {?} */ idx = base_1.indexOf(update.value);
  695. if (idx !== -1) {
  696. base_1.splice(idx, 1);
  697. }
  698. if (base_1.length > 0) {
  699. /** @type {?} */ ((_this.map)).set(update.param, base_1);
  700. }
  701. else {
  702. /** @type {?} */ ((_this.map)).delete(update.param);
  703. }
  704. }
  705. else {
  706. /** @type {?} */ ((_this.map)).delete(update.param);
  707. break;
  708. }
  709. }
  710. });
  711. this.cloneFrom = null;
  712. }
  713. };
  714. return HttpParams;
  715. }());
  716. /**
  717. * @fileoverview added by tsickle
  718. * @suppress {checkTypes} checked by tsc
  719. */
  720. /**
  721. * @license
  722. * Copyright Google Inc. All Rights Reserved.
  723. *
  724. * Use of this source code is governed by an MIT-style license that can be
  725. * found in the LICENSE file at https://angular.io/license
  726. */
  727. /**
  728. * Determine whether the given HTTP method may include a body.
  729. * @param {?} method
  730. * @return {?}
  731. */
  732. function mightHaveBody(method) {
  733. switch (method) {
  734. case 'DELETE':
  735. case 'GET':
  736. case 'HEAD':
  737. case 'OPTIONS':
  738. case 'JSONP':
  739. return false;
  740. default:
  741. return true;
  742. }
  743. }
  744. /**
  745. * Safely assert whether the given value is an ArrayBuffer.
  746. *
  747. * In some execution environments ArrayBuffer is not defined.
  748. * @param {?} value
  749. * @return {?}
  750. */
  751. function isArrayBuffer(value) {
  752. return typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer;
  753. }
  754. /**
  755. * Safely assert whether the given value is a Blob.
  756. *
  757. * In some execution environments Blob is not defined.
  758. * @param {?} value
  759. * @return {?}
  760. */
  761. function isBlob(value) {
  762. return typeof Blob !== 'undefined' && value instanceof Blob;
  763. }
  764. /**
  765. * Safely assert whether the given value is a FormData instance.
  766. *
  767. * In some execution environments FormData is not defined.
  768. * @param {?} value
  769. * @return {?}
  770. */
  771. function isFormData(value) {
  772. return typeof FormData !== 'undefined' && value instanceof FormData;
  773. }
  774. /**
  775. * An outgoing HTTP request with an optional typed body.
  776. *
  777. * `HttpRequest` represents an outgoing request, including URL, method,
  778. * headers, body, and other request configuration options. Instances should be
  779. * assumed to be immutable. To modify a `HttpRequest`, the `clone`
  780. * method should be used.
  781. *
  782. * \@stable
  783. * @template T
  784. */
  785. var HttpRequest = /** @class */ (function () {
  786. function HttpRequest(method, url, third, fourth) {
  787. this.url = url;
  788. /**
  789. * The request body, or `null` if one isn't set.
  790. *
  791. * Bodies are not enforced to be immutable, as they can include a reference to any
  792. * user-defined data type. However, interceptors should take care to preserve
  793. * idempotence by treating them as such.
  794. */
  795. this.body = null;
  796. /**
  797. * Whether this request should be made in a way that exposes progress events.
  798. *
  799. * Progress events are expensive (change detection runs on each event) and so
  800. * they should only be requested if the consumer intends to monitor them.
  801. */
  802. this.reportProgress = false;
  803. /**
  804. * Whether this request should be sent with outgoing credentials (cookies).
  805. */
  806. this.withCredentials = false;
  807. /**
  808. * The expected response type of the server.
  809. *
  810. * This is used to parse the response appropriately before returning it to
  811. * the requestee.
  812. */
  813. this.responseType = 'json';
  814. this.method = method.toUpperCase();
  815. // Next, need to figure out which argument holds the HttpRequestInit
  816. // options, if any.
  817. var /** @type {?} */ options;
  818. // Check whether a body argument is expected. The only valid way to omit
  819. // the body argument is to use a known no-body method like GET.
  820. if (mightHaveBody(this.method) || !!fourth) {
  821. // Body is the third argument, options are the fourth.
  822. this.body = (third !== undefined) ? /** @type {?} */ (third) : null;
  823. options = fourth;
  824. }
  825. else {
  826. // No body required, options are the third argument. The body stays null.
  827. options = /** @type {?} */ (third);
  828. }
  829. // If options have been passed, interpret them.
  830. if (options) {
  831. // Normalize reportProgress and withCredentials.
  832. this.reportProgress = !!options.reportProgress;
  833. this.withCredentials = !!options.withCredentials;
  834. // Override default response type of 'json' if one is provided.
  835. if (!!options.responseType) {
  836. this.responseType = options.responseType;
  837. }
  838. // Override headers if they're provided.
  839. if (!!options.headers) {
  840. this.headers = options.headers;
  841. }
  842. if (!!options.params) {
  843. this.params = options.params;
  844. }
  845. }
  846. // If no headers have been passed in, construct a new HttpHeaders instance.
  847. if (!this.headers) {
  848. this.headers = new HttpHeaders();
  849. }
  850. // If no parameters have been passed in, construct a new HttpUrlEncodedParams instance.
  851. if (!this.params) {
  852. this.params = new HttpParams();
  853. this.urlWithParams = url;
  854. }
  855. else {
  856. // Encode the parameters to a string in preparation for inclusion in the URL.
  857. var /** @type {?} */ params = this.params.toString();
  858. if (params.length === 0) {
  859. // No parameters, the visible URL is just the URL given at creation time.
  860. this.urlWithParams = url;
  861. }
  862. else {
  863. // Does the URL already have query parameters? Look for '?'.
  864. var /** @type {?} */ qIdx = url.indexOf('?');
  865. // There are 3 cases to handle:
  866. // 1) No existing parameters -> append '?' followed by params.
  867. // 2) '?' exists and is followed by existing query string ->
  868. // append '&' followed by params.
  869. // 3) '?' exists at the end of the url -> append params directly.
  870. // This basically amounts to determining the character, if any, with
  871. // which to join the URL and parameters.
  872. var /** @type {?} */ sep = qIdx === -1 ? '?' : (qIdx < url.length - 1 ? '&' : '');
  873. this.urlWithParams = url + sep + params;
  874. }
  875. }
  876. }
  877. /**
  878. * Transform the free-form body into a serialized format suitable for
  879. * transmission to the server.
  880. */
  881. /**
  882. * Transform the free-form body into a serialized format suitable for
  883. * transmission to the server.
  884. * @return {?}
  885. */
  886. HttpRequest.prototype.serializeBody = /**
  887. * Transform the free-form body into a serialized format suitable for
  888. * transmission to the server.
  889. * @return {?}
  890. */
  891. function () {
  892. // If no body is present, no need to serialize it.
  893. if (this.body === null) {
  894. return null;
  895. }
  896. // Check whether the body is already in a serialized form. If so,
  897. // it can just be returned directly.
  898. if (isArrayBuffer(this.body) || isBlob(this.body) || isFormData(this.body) ||
  899. typeof this.body === 'string') {
  900. return this.body;
  901. }
  902. // Check whether the body is an instance of HttpUrlEncodedParams.
  903. if (this.body instanceof HttpParams) {
  904. return this.body.toString();
  905. }
  906. // Check whether the body is an object or array, and serialize with JSON if so.
  907. if (typeof this.body === 'object' || typeof this.body === 'boolean' ||
  908. Array.isArray(this.body)) {
  909. return JSON.stringify(this.body);
  910. }
  911. // Fall back on toString() for everything else.
  912. return (/** @type {?} */ (this.body)).toString();
  913. };
  914. /**
  915. * Examine the body and attempt to infer an appropriate MIME type
  916. * for it.
  917. *
  918. * If no such type can be inferred, this method will return `null`.
  919. */
  920. /**
  921. * Examine the body and attempt to infer an appropriate MIME type
  922. * for it.
  923. *
  924. * If no such type can be inferred, this method will return `null`.
  925. * @return {?}
  926. */
  927. HttpRequest.prototype.detectContentTypeHeader = /**
  928. * Examine the body and attempt to infer an appropriate MIME type
  929. * for it.
  930. *
  931. * If no such type can be inferred, this method will return `null`.
  932. * @return {?}
  933. */
  934. function () {
  935. // An empty body has no content type.
  936. if (this.body === null) {
  937. return null;
  938. }
  939. // FormData bodies rely on the browser's content type assignment.
  940. if (isFormData(this.body)) {
  941. return null;
  942. }
  943. // Blobs usually have their own content type. If it doesn't, then
  944. // no type can be inferred.
  945. if (isBlob(this.body)) {
  946. return this.body.type || null;
  947. }
  948. // Array buffers have unknown contents and thus no type can be inferred.
  949. if (isArrayBuffer(this.body)) {
  950. return null;
  951. }
  952. // Technically, strings could be a form of JSON data, but it's safe enough
  953. // to assume they're plain strings.
  954. if (typeof this.body === 'string') {
  955. return 'text/plain';
  956. }
  957. // `HttpUrlEncodedParams` has its own content-type.
  958. if (this.body instanceof HttpParams) {
  959. return 'application/x-www-form-urlencoded;charset=UTF-8';
  960. }
  961. // Arrays, objects, and numbers will be encoded as JSON.
  962. if (typeof this.body === 'object' || typeof this.body === 'number' ||
  963. Array.isArray(this.body)) {
  964. return 'application/json';
  965. }
  966. // No type could be inferred.
  967. return null;
  968. };
  969. /**
  970. * @param {?=} update
  971. * @return {?}
  972. */
  973. HttpRequest.prototype.clone = /**
  974. * @param {?=} update
  975. * @return {?}
  976. */
  977. function (update) {
  978. if (update === void 0) { update = {}; }
  979. // For method, url, and responseType, take the current value unless
  980. // it is overridden in the update hash.
  981. var /** @type {?} */ method = update.method || this.method;
  982. var /** @type {?} */ url = update.url || this.url;
  983. var /** @type {?} */ responseType = update.responseType || this.responseType;
  984. // The body is somewhat special - a `null` value in update.body means
  985. // whatever current body is present is being overridden with an empty
  986. // body, whereas an `undefined` value in update.body implies no
  987. // override.
  988. var /** @type {?} */ body = (update.body !== undefined) ? update.body : this.body;
  989. // Carefully handle the boolean options to differentiate between
  990. // `false` and `undefined` in the update args.
  991. var /** @type {?} */ withCredentials = (update.withCredentials !== undefined) ? update.withCredentials : this.withCredentials;
  992. var /** @type {?} */ reportProgress = (update.reportProgress !== undefined) ? update.reportProgress : this.reportProgress;
  993. // Headers and params may be appended to if `setHeaders` or
  994. // `setParams` are used.
  995. var /** @type {?} */ headers = update.headers || this.headers;
  996. var /** @type {?} */ params = update.params || this.params;
  997. // Check whether the caller has asked to add headers.
  998. if (update.setHeaders !== undefined) {
  999. // Set every requested header.
  1000. headers =
  1001. Object.keys(update.setHeaders)
  1002. .reduce(function (headers, name) { return headers.set(name, /** @type {?} */ ((update.setHeaders))[name]); }, headers);
  1003. }
  1004. // Check whether the caller has asked to set params.
  1005. if (update.setParams) {
  1006. // Set every requested param.
  1007. params = Object.keys(update.setParams)
  1008. .reduce(function (params, param) { return params.set(param, /** @type {?} */ ((update.setParams))[param]); }, params);
  1009. }
  1010. // Finally, construct the new HttpRequest using the pieces from above.
  1011. return new HttpRequest(method, url, body, {
  1012. params: params, headers: headers, reportProgress: reportProgress, responseType: responseType, withCredentials: withCredentials,
  1013. });
  1014. };
  1015. return HttpRequest;
  1016. }());
  1017. /**
  1018. * @fileoverview added by tsickle
  1019. * @suppress {checkTypes} checked by tsc
  1020. */
  1021. /**
  1022. * @license
  1023. * Copyright Google Inc. All Rights Reserved.
  1024. *
  1025. * Use of this source code is governed by an MIT-style license that can be
  1026. * found in the LICENSE file at https://angular.io/license
  1027. */
  1028. /** @enum {number} */
  1029. var HttpEventType = {
  1030. /**
  1031. * The request was sent out over the wire.
  1032. */
  1033. Sent: 0,
  1034. /**
  1035. * An upload progress event was received.
  1036. */
  1037. UploadProgress: 1,
  1038. /**
  1039. * The response status code and headers were received.
  1040. */
  1041. ResponseHeader: 2,
  1042. /**
  1043. * A download progress event was received.
  1044. */
  1045. DownloadProgress: 3,
  1046. /**
  1047. * The full response including the body was received.
  1048. */
  1049. Response: 4,
  1050. /**
  1051. * A custom event from an interceptor or a backend.
  1052. */
  1053. User: 5,
  1054. };
  1055. HttpEventType[HttpEventType.Sent] = "Sent";
  1056. HttpEventType[HttpEventType.UploadProgress] = "UploadProgress";
  1057. HttpEventType[HttpEventType.ResponseHeader] = "ResponseHeader";
  1058. HttpEventType[HttpEventType.DownloadProgress] = "DownloadProgress";
  1059. HttpEventType[HttpEventType.Response] = "Response";
  1060. HttpEventType[HttpEventType.User] = "User";
  1061. /**
  1062. * Base interface for progress events.
  1063. *
  1064. * \@stable
  1065. * @record
  1066. */
  1067. /**
  1068. * A download progress event.
  1069. *
  1070. * \@stable
  1071. * @record
  1072. */
  1073. /**
  1074. * An upload progress event.
  1075. *
  1076. * \@stable
  1077. * @record
  1078. */
  1079. /**
  1080. * An event indicating that the request was sent to the server. Useful
  1081. * when a request may be retried multiple times, to distinguish between
  1082. * retries on the final event stream.
  1083. *
  1084. * \@stable
  1085. * @record
  1086. */
  1087. /**
  1088. * A user-defined event.
  1089. *
  1090. * Grouping all custom events under this type ensures they will be handled
  1091. * and forwarded by all implementations of interceptors.
  1092. *
  1093. * \@stable
  1094. * @record
  1095. * @template T
  1096. */
  1097. /**
  1098. * An error that represents a failed attempt to JSON.parse text coming back
  1099. * from the server.
  1100. *
  1101. * It bundles the Error object with the actual response body that failed to parse.
  1102. *
  1103. * \@stable
  1104. * @record
  1105. */
  1106. /**
  1107. * Base class for both `HttpResponse` and `HttpHeaderResponse`.
  1108. *
  1109. * \@stable
  1110. * @abstract
  1111. */
  1112. var HttpResponseBase = /** @class */ (function () {
  1113. /**
  1114. * Super-constructor for all responses.
  1115. *
  1116. * The single parameter accepted is an initialization hash. Any properties
  1117. * of the response passed there will override the default values.
  1118. */
  1119. function HttpResponseBase(init, defaultStatus, defaultStatusText) {
  1120. if (defaultStatus === void 0) { defaultStatus = 200; }
  1121. if (defaultStatusText === void 0) { defaultStatusText = 'OK'; }
  1122. // If the hash has values passed, use them to initialize the response.
  1123. // Otherwise use the default values.
  1124. this.headers = init.headers || new HttpHeaders();
  1125. this.status = init.status !== undefined ? init.status : defaultStatus;
  1126. this.statusText = init.statusText || defaultStatusText;
  1127. this.url = init.url || null;
  1128. // Cache the ok value to avoid defining a getter.
  1129. this.ok = this.status >= 200 && this.status < 300;
  1130. }
  1131. return HttpResponseBase;
  1132. }());
  1133. /**
  1134. * A partial HTTP response which only includes the status and header data,
  1135. * but no response body.
  1136. *
  1137. * `HttpHeaderResponse` is a `HttpEvent` available on the response
  1138. * event stream, only when progress events are requested.
  1139. *
  1140. * \@stable
  1141. */
  1142. var HttpHeaderResponse = /** @class */ (function (_super) {
  1143. tslib.__extends(HttpHeaderResponse, _super);
  1144. /**
  1145. * Create a new `HttpHeaderResponse` with the given parameters.
  1146. */
  1147. function HttpHeaderResponse(init) {
  1148. if (init === void 0) { init = {}; }
  1149. var _this = _super.call(this, init) || this;
  1150. _this.type = HttpEventType.ResponseHeader;
  1151. return _this;
  1152. }
  1153. /**
  1154. * Copy this `HttpHeaderResponse`, overriding its contents with the
  1155. * given parameter hash.
  1156. */
  1157. /**
  1158. * Copy this `HttpHeaderResponse`, overriding its contents with the
  1159. * given parameter hash.
  1160. * @param {?=} update
  1161. * @return {?}
  1162. */
  1163. HttpHeaderResponse.prototype.clone = /**
  1164. * Copy this `HttpHeaderResponse`, overriding its contents with the
  1165. * given parameter hash.
  1166. * @param {?=} update
  1167. * @return {?}
  1168. */
  1169. function (update) {
  1170. if (update === void 0) { update = {}; }
  1171. // Perform a straightforward initialization of the new HttpHeaderResponse,
  1172. // overriding the current parameters with new ones if given.
  1173. return new HttpHeaderResponse({
  1174. headers: update.headers || this.headers,
  1175. status: update.status !== undefined ? update.status : this.status,
  1176. statusText: update.statusText || this.statusText,
  1177. url: update.url || this.url || undefined,
  1178. });
  1179. };
  1180. return HttpHeaderResponse;
  1181. }(HttpResponseBase));
  1182. /**
  1183. * A full HTTP response, including a typed response body (which may be `null`
  1184. * if one was not returned).
  1185. *
  1186. * `HttpResponse` is a `HttpEvent` available on the response event
  1187. * stream.
  1188. *
  1189. * \@stable
  1190. * @template T
  1191. */
  1192. var HttpResponse = /** @class */ (function (_super) {
  1193. tslib.__extends(HttpResponse, _super);
  1194. /**
  1195. * Construct a new `HttpResponse`.
  1196. */
  1197. function HttpResponse(init) {
  1198. if (init === void 0) { init = {}; }
  1199. var _this = _super.call(this, init) || this;
  1200. _this.type = HttpEventType.Response;
  1201. _this.body = init.body !== undefined ? init.body : null;
  1202. return _this;
  1203. }
  1204. /**
  1205. * @param {?=} update
  1206. * @return {?}
  1207. */
  1208. HttpResponse.prototype.clone = /**
  1209. * @param {?=} update
  1210. * @return {?}
  1211. */
  1212. function (update) {
  1213. if (update === void 0) { update = {}; }
  1214. return new HttpResponse({
  1215. body: (update.body !== undefined) ? update.body : this.body,
  1216. headers: update.headers || this.headers,
  1217. status: (update.status !== undefined) ? update.status : this.status,
  1218. statusText: update.statusText || this.statusText,
  1219. url: update.url || this.url || undefined,
  1220. });
  1221. };
  1222. return HttpResponse;
  1223. }(HttpResponseBase));
  1224. /**
  1225. * A response that represents an error or failure, either from a
  1226. * non-successful HTTP status, an error while executing the request,
  1227. * or some other failure which occurred during the parsing of the response.
  1228. *
  1229. * Any error returned on the `Observable` response stream will be
  1230. * wrapped in an `HttpErrorResponse` to provide additional context about
  1231. * the state of the HTTP layer when the error occurred. The error property
  1232. * will contain either a wrapped Error object or the error response returned
  1233. * from the server.
  1234. *
  1235. * \@stable
  1236. */
  1237. var HttpErrorResponse = /** @class */ (function (_super) {
  1238. tslib.__extends(HttpErrorResponse, _super);
  1239. function HttpErrorResponse(init) {
  1240. var _this =
  1241. // Initialize with a default status of 0 / Unknown Error.
  1242. _super.call(this, init, 0, 'Unknown Error') || this;
  1243. _this.name = 'HttpErrorResponse';
  1244. /**
  1245. * Errors are never okay, even when the status code is in the 2xx success range.
  1246. */
  1247. _this.ok = false;
  1248. // If the response was successful, then this was a parse error. Otherwise, it was
  1249. // a protocol-level failure of some sort. Either the request failed in transit
  1250. // or the server returned an unsuccessful status code.
  1251. if (_this.status >= 200 && _this.status < 300) {
  1252. _this.message = "Http failure during parsing for " + (init.url || '(unknown url)');
  1253. }
  1254. else {
  1255. _this.message =
  1256. "Http failure response for " + (init.url || '(unknown url)') + ": " + init.status + " " + init.statusText;
  1257. }
  1258. _this.error = init.error || null;
  1259. return _this;
  1260. }
  1261. return HttpErrorResponse;
  1262. }(HttpResponseBase));
  1263. /**
  1264. * @fileoverview added by tsickle
  1265. * @suppress {checkTypes} checked by tsc
  1266. */
  1267. /**
  1268. * @license
  1269. * Copyright Google Inc. All Rights Reserved.
  1270. *
  1271. * Use of this source code is governed by an MIT-style license that can be
  1272. * found in the LICENSE file at https://angular.io/license
  1273. */
  1274. /**
  1275. * Construct an instance of `HttpRequestOptions<T>` from a source `HttpMethodOptions` and
  1276. * the given `body`. Basically, this clones the object and adds the body.
  1277. * @template T
  1278. * @param {?} options
  1279. * @param {?} body
  1280. * @return {?}
  1281. */
  1282. function addBody(options, body) {
  1283. return {
  1284. body: body,
  1285. headers: options.headers,
  1286. observe: options.observe,
  1287. params: options.params,
  1288. reportProgress: options.reportProgress,
  1289. responseType: options.responseType,
  1290. withCredentials: options.withCredentials,
  1291. };
  1292. }
  1293. /**
  1294. * Perform HTTP requests.
  1295. *
  1296. * `HttpClient` is available as an injectable class, with methods to perform HTTP requests.
  1297. * Each request method has multiple signatures, and the return type varies according to which
  1298. * signature is called (mainly the values of `observe` and `responseType`).
  1299. *
  1300. * \@stable
  1301. */
  1302. var HttpClient = /** @class */ (function () {
  1303. function HttpClient(handler) {
  1304. this.handler = handler;
  1305. }
  1306. /**
  1307. * Constructs an `Observable` for a particular HTTP request that, when subscribed,
  1308. * fires the request through the chain of registered interceptors and on to the
  1309. * server.
  1310. *
  1311. * This method can be called in one of two ways. Either an `HttpRequest`
  1312. * instance can be passed directly as the only parameter, or a method can be
  1313. * passed as the first parameter, a string URL as the second, and an
  1314. * options hash as the third.
  1315. *
  1316. * If a `HttpRequest` object is passed directly, an `Observable` of the
  1317. * raw `HttpEvent` stream will be returned.
  1318. *
  1319. * If a request is instead built by providing a URL, the options object
  1320. * determines the return type of `request()`. In addition to configuring
  1321. * request parameters such as the outgoing headers and/or the body, the options
  1322. * hash specifies two key pieces of information about the request: the
  1323. * `responseType` and what to `observe`.
  1324. *
  1325. * The `responseType` value determines how a successful response body will be
  1326. * parsed. If `responseType` is the default `json`, a type interface for the
  1327. * resulting object may be passed as a type parameter to `request()`.
  1328. *
  1329. * The `observe` value determines the return type of `request()`, based on what
  1330. * the consumer is interested in observing. A value of `events` will return an
  1331. * `Observable<HttpEvent>` representing the raw `HttpEvent` stream,
  1332. * including progress events by default. A value of `response` will return an
  1333. * `Observable<HttpResponse<T>>` where the `T` parameter of `HttpResponse`
  1334. * depends on the `responseType` and any optionally provided type parameter.
  1335. * A value of `body` will return an `Observable<T>` with the same `T` body type.
  1336. */
  1337. /**
  1338. * Constructs an `Observable` for a particular HTTP request that, when subscribed,
  1339. * fires the request through the chain of registered interceptors and on to the
  1340. * server.
  1341. *
  1342. * This method can be called in one of two ways. Either an `HttpRequest`
  1343. * instance can be passed directly as the only parameter, or a method can be
  1344. * passed as the first parameter, a string URL as the second, and an
  1345. * options hash as the third.
  1346. *
  1347. * If a `HttpRequest` object is passed directly, an `Observable` of the
  1348. * raw `HttpEvent` stream will be returned.
  1349. *
  1350. * If a request is instead built by providing a URL, the options object
  1351. * determines the return type of `request()`. In addition to configuring
  1352. * request parameters such as the outgoing headers and/or the body, the options
  1353. * hash specifies two key pieces of information about the request: the
  1354. * `responseType` and what to `observe`.
  1355. *
  1356. * The `responseType` value determines how a successful response body will be
  1357. * parsed. If `responseType` is the default `json`, a type interface for the
  1358. * resulting object may be passed as a type parameter to `request()`.
  1359. *
  1360. * The `observe` value determines the return type of `request()`, based on what
  1361. * the consumer is interested in observing. A value of `events` will return an
  1362. * `Observable<HttpEvent>` representing the raw `HttpEvent` stream,
  1363. * including progress events by default. A value of `response` will return an
  1364. * `Observable<HttpResponse<T>>` where the `T` parameter of `HttpResponse`
  1365. * depends on the `responseType` and any optionally provided type parameter.
  1366. * A value of `body` will return an `Observable<T>` with the same `T` body type.
  1367. * @param {?} first
  1368. * @param {?=} url
  1369. * @param {?=} options
  1370. * @return {?}
  1371. */
  1372. HttpClient.prototype.request = /**
  1373. * Constructs an `Observable` for a particular HTTP request that, when subscribed,
  1374. * fires the request through the chain of registered interceptors and on to the
  1375. * server.
  1376. *
  1377. * This method can be called in one of two ways. Either an `HttpRequest`
  1378. * instance can be passed directly as the only parameter, or a method can be
  1379. * passed as the first parameter, a string URL as the second, and an
  1380. * options hash as the third.
  1381. *
  1382. * If a `HttpRequest` object is passed directly, an `Observable` of the
  1383. * raw `HttpEvent` stream will be returned.
  1384. *
  1385. * If a request is instead built by providing a URL, the options object
  1386. * determines the return type of `request()`. In addition to configuring
  1387. * request parameters such as the outgoing headers and/or the body, the options
  1388. * hash specifies two key pieces of information about the request: the
  1389. * `responseType` and what to `observe`.
  1390. *
  1391. * The `responseType` value determines how a successful response body will be
  1392. * parsed. If `responseType` is the default `json`, a type interface for the
  1393. * resulting object may be passed as a type parameter to `request()`.
  1394. *
  1395. * The `observe` value determines the return type of `request()`, based on what
  1396. * the consumer is interested in observing. A value of `events` will return an
  1397. * `Observable<HttpEvent>` representing the raw `HttpEvent` stream,
  1398. * including progress events by default. A value of `response` will return an
  1399. * `Observable<HttpResponse<T>>` where the `T` parameter of `HttpResponse`
  1400. * depends on the `responseType` and any optionally provided type parameter.
  1401. * A value of `body` will return an `Observable<T>` with the same `T` body type.
  1402. * @param {?} first
  1403. * @param {?=} url
  1404. * @param {?=} options
  1405. * @return {?}
  1406. */
  1407. function (first, url, options) {
  1408. var _this = this;
  1409. if (options === void 0) { options = {}; }
  1410. var /** @type {?} */ req;
  1411. // Firstly, check whether the primary argument is an instance of `HttpRequest`.
  1412. if (first instanceof HttpRequest) {
  1413. // It is. The other arguments must be undefined (per the signatures) and can be
  1414. // ignored.
  1415. req = /** @type {?} */ (first);
  1416. }
  1417. else {
  1418. // It's a string, so it represents a URL. Construct a request based on it,
  1419. // and incorporate the remaining arguments (assuming GET unless a method is
  1420. // provided.
  1421. // Figure out the headers.
  1422. var /** @type {?} */ headers = undefined;
  1423. if (options.headers instanceof HttpHeaders) {
  1424. headers = options.headers;
  1425. }
  1426. else {
  1427. headers = new HttpHeaders(options.headers);
  1428. }
  1429. // Sort out parameters.
  1430. var /** @type {?} */ params = undefined;
  1431. if (!!options.params) {
  1432. if (options.params instanceof HttpParams) {
  1433. params = options.params;
  1434. }
  1435. else {
  1436. params = new HttpParams({ fromObject: options.params });
  1437. }
  1438. }
  1439. // Construct the request.
  1440. req = new HttpRequest(first, /** @type {?} */ ((url)), (options.body !== undefined ? options.body : null), {
  1441. headers: headers,
  1442. params: params,
  1443. reportProgress: options.reportProgress,
  1444. // By default, JSON is assumed to be returned for all calls.
  1445. responseType: options.responseType || 'json',
  1446. withCredentials: options.withCredentials,
  1447. });
  1448. }
  1449. // Start with an Observable.of() the initial request, and run the handler (which
  1450. // includes all interceptors) inside a concatMap(). This way, the handler runs
  1451. // inside an Observable chain, which causes interceptors to be re-run on every
  1452. // subscription (this also makes retries re-run the handler, including interceptors).
  1453. var /** @type {?} */ events$ = rxjs_operator_concatMap.concatMap.call(rxjs_observable_of.of(req), function (req) { return _this.handler.handle(req); });
  1454. // If coming via the API signature which accepts a previously constructed HttpRequest,
  1455. // the only option is to get the event stream. Otherwise, return the event stream if
  1456. // that is what was requested.
  1457. if (first instanceof HttpRequest || options.observe === 'events') {
  1458. return events$;
  1459. }
  1460. // The requested stream contains either the full response or the body. In either
  1461. // case, the first step is to filter the event stream to extract a stream of
  1462. // responses(s).
  1463. var /** @type {?} */ res$ = rxjs_operator_filter.filter.call(events$, function (event) { return event instanceof HttpResponse; });
  1464. // Decide which stream to return.
  1465. switch (options.observe || 'body') {
  1466. case 'body':
  1467. // The requested stream is the body. Map the response stream to the response
  1468. // body. This could be done more simply, but a misbehaving interceptor might
  1469. // transform the response body into a different format and ignore the requested
  1470. // responseType. Guard against this by validating that the response is of the
  1471. // requested type.
  1472. switch (req.responseType) {
  1473. case 'arraybuffer':
  1474. return rxjs_operator_map.map.call(res$, function (res) {
  1475. // Validate that the body is an ArrayBuffer.
  1476. if (res.body !== null && !(res.body instanceof ArrayBuffer)) {
  1477. throw new Error('Response is not an ArrayBuffer.');
  1478. }
  1479. return res.body;
  1480. });
  1481. case 'blob':
  1482. return rxjs_operator_map.map.call(res$, function (res) {
  1483. // Validate that the body is a Blob.
  1484. if (res.body !== null && !(res.body instanceof Blob)) {
  1485. throw new Error('Response is not a Blob.');
  1486. }
  1487. return res.body;
  1488. });
  1489. case 'text':
  1490. return rxjs_operator_map.map.call(res$, function (res) {
  1491. // Validate that the body is a string.
  1492. if (res.body !== null && typeof res.body !== 'string') {
  1493. throw new Error('Response is not a string.');
  1494. }
  1495. return res.body;
  1496. });
  1497. case 'json':
  1498. default:
  1499. // No validation needed for JSON responses, as they can be of any type.
  1500. return rxjs_operator_map.map.call(res$, function (res) { return res.body; });
  1501. }
  1502. case 'response':
  1503. // The response stream was requested directly, so return it.
  1504. return res$;
  1505. default:
  1506. // Guard against new future observe types being added.
  1507. throw new Error("Unreachable: unhandled observe type " + options.observe + "}");
  1508. }
  1509. };
  1510. /**
  1511. * Constructs an `Observable` which, when subscribed, will cause the configured
  1512. * DELETE request to be executed on the server. See the individual overloads for
  1513. * details of `delete()`'s return type based on the provided options.
  1514. */
  1515. /**
  1516. * Constructs an `Observable` which, when subscribed, will cause the configured
  1517. * DELETE request to be executed on the server. See the individual overloads for
  1518. * details of `delete()`'s return type based on the provided options.
  1519. * @param {?} url
  1520. * @param {?=} options
  1521. * @return {?}
  1522. */
  1523. HttpClient.prototype.delete = /**
  1524. * Constructs an `Observable` which, when subscribed, will cause the configured
  1525. * DELETE request to be executed on the server. See the individual overloads for
  1526. * details of `delete()`'s return type based on the provided options.
  1527. * @param {?} url
  1528. * @param {?=} options
  1529. * @return {?}
  1530. */
  1531. function (url, options) {
  1532. if (options === void 0) { options = {}; }
  1533. return this.request('DELETE', url, /** @type {?} */ (options));
  1534. };
  1535. /**
  1536. * Constructs an `Observable` which, when subscribed, will cause the configured
  1537. * GET request to be executed on the server. See the individual overloads for
  1538. * details of `get()`'s return type based on the provided options.
  1539. */
  1540. /**
  1541. * Constructs an `Observable` which, when subscribed, will cause the configured
  1542. * GET request to be executed on the server. See the individual overloads for
  1543. * details of `get()`'s return type based on the provided options.
  1544. * @param {?} url
  1545. * @param {?=} options
  1546. * @return {?}
  1547. */
  1548. HttpClient.prototype.get = /**
  1549. * Constructs an `Observable` which, when subscribed, will cause the configured
  1550. * GET request to be executed on the server. See the individual overloads for
  1551. * details of `get()`'s return type based on the provided options.
  1552. * @param {?} url
  1553. * @param {?=} options
  1554. * @return {?}
  1555. */
  1556. function (url, options) {
  1557. if (options === void 0) { options = {}; }
  1558. return this.request('GET', url, /** @type {?} */ (options));
  1559. };
  1560. /**
  1561. * Constructs an `Observable` which, when subscribed, will cause the configured
  1562. * HEAD request to be executed on the server. See the individual overloads for
  1563. * details of `head()`'s return type based on the provided options.
  1564. */
  1565. /**
  1566. * Constructs an `Observable` which, when subscribed, will cause the configured
  1567. * HEAD request to be executed on the server. See the individual overloads for
  1568. * details of `head()`'s return type based on the provided options.
  1569. * @param {?} url
  1570. * @param {?=} options
  1571. * @return {?}
  1572. */
  1573. HttpClient.prototype.head = /**
  1574. * Constructs an `Observable` which, when subscribed, will cause the configured
  1575. * HEAD request to be executed on the server. See the individual overloads for
  1576. * details of `head()`'s return type based on the provided options.
  1577. * @param {?} url
  1578. * @param {?=} options
  1579. * @return {?}
  1580. */
  1581. function (url, options) {
  1582. if (options === void 0) { options = {}; }
  1583. return this.request('HEAD', url, /** @type {?} */ (options));
  1584. };
  1585. /**
  1586. * Constructs an `Observable` which, when subscribed, will cause a request
  1587. * with the special method `JSONP` to be dispatched via the interceptor pipeline.
  1588. *
  1589. * A suitable interceptor must be installed (e.g. via the `HttpClientJsonpModule`).
  1590. * If no such interceptor is reached, then the `JSONP` request will likely be
  1591. * rejected by the configured backend.
  1592. */
  1593. /**
  1594. * Constructs an `Observable` which, when subscribed, will cause a request
  1595. * with the special method `JSONP` to be dispatched via the interceptor pipeline.
  1596. *
  1597. * A suitable interceptor must be installed (e.g. via the `HttpClientJsonpModule`).
  1598. * If no such interceptor is reached, then the `JSONP` request will likely be
  1599. * rejected by the configured backend.
  1600. * @template T
  1601. * @param {?} url
  1602. * @param {?} callbackParam
  1603. * @return {?}
  1604. */
  1605. HttpClient.prototype.jsonp = /**
  1606. * Constructs an `Observable` which, when subscribed, will cause a request
  1607. * with the special method `JSONP` to be dispatched via the interceptor pipeline.
  1608. *
  1609. * A suitable interceptor must be installed (e.g. via the `HttpClientJsonpModule`).
  1610. * If no such interceptor is reached, then the `JSONP` request will likely be
  1611. * rejected by the configured backend.
  1612. * @template T
  1613. * @param {?} url
  1614. * @param {?} callbackParam
  1615. * @return {?}
  1616. */
  1617. function (url, callbackParam) {
  1618. return this.request('JSONP', url, {
  1619. params: new HttpParams().append(callbackParam, 'JSONP_CALLBACK'),
  1620. observe: 'body',
  1621. responseType: 'json',
  1622. });
  1623. };
  1624. /**
  1625. * Constructs an `Observable` which, when subscribed, will cause the configured
  1626. * OPTIONS request to be executed on the server. See the individual overloads for
  1627. * details of `options()`'s return type based on the provided options.
  1628. */
  1629. /**
  1630. * Constructs an `Observable` which, when subscribed, will cause the configured
  1631. * OPTIONS request to be executed on the server. See the individual overloads for
  1632. * details of `options()`'s return type based on the provided options.
  1633. * @param {?} url
  1634. * @param {?=} options
  1635. * @return {?}
  1636. */
  1637. HttpClient.prototype.options = /**
  1638. * Constructs an `Observable` which, when subscribed, will cause the configured
  1639. * OPTIONS request to be executed on the server. See the individual overloads for
  1640. * details of `options()`'s return type based on the provided options.
  1641. * @param {?} url
  1642. * @param {?=} options
  1643. * @return {?}
  1644. */
  1645. function (url, options) {
  1646. if (options === void 0) { options = {}; }
  1647. return this.request('OPTIONS', url, /** @type {?} */ (options));
  1648. };
  1649. /**
  1650. * Constructs an `Observable` which, when subscribed, will cause the configured
  1651. * PATCH request to be executed on the server. See the individual overloads for
  1652. * details of `patch()`'s return type based on the provided options.
  1653. */
  1654. /**
  1655. * Constructs an `Observable` which, when subscribed, will cause the configured
  1656. * PATCH request to be executed on the server. See the individual overloads for
  1657. * details of `patch()`'s return type based on the provided options.
  1658. * @param {?} url
  1659. * @param {?} body
  1660. * @param {?=} options
  1661. * @return {?}
  1662. */
  1663. HttpClient.prototype.patch = /**
  1664. * Constructs an `Observable` which, when subscribed, will cause the configured
  1665. * PATCH request to be executed on the server. See the individual overloads for
  1666. * details of `patch()`'s return type based on the provided options.
  1667. * @param {?} url
  1668. * @param {?} body
  1669. * @param {?=} options
  1670. * @return {?}
  1671. */
  1672. function (url, body, options) {
  1673. if (options === void 0) { options = {}; }
  1674. return this.request('PATCH', url, addBody(options, body));
  1675. };
  1676. /**
  1677. * Constructs an `Observable` which, when subscribed, will cause the configured
  1678. * POST request to be executed on the server. See the individual overloads for
  1679. * details of `post()`'s return type based on the provided options.
  1680. */
  1681. /**
  1682. * Constructs an `Observable` which, when subscribed, will cause the configured
  1683. * POST request to be executed on the server. See the individual overloads for
  1684. * details of `post()`'s return type based on the provided options.
  1685. * @param {?} url
  1686. * @param {?} body
  1687. * @param {?=} options
  1688. * @return {?}
  1689. */
  1690. HttpClient.prototype.post = /**
  1691. * Constructs an `Observable` which, when subscribed, will cause the configured
  1692. * POST request to be executed on the server. See the individual overloads for
  1693. * details of `post()`'s return type based on the provided options.
  1694. * @param {?} url
  1695. * @param {?} body
  1696. * @param {?=} options
  1697. * @return {?}
  1698. */
  1699. function (url, body, options) {
  1700. if (options === void 0) { options = {}; }
  1701. return this.request('POST', url, addBody(options, body));
  1702. };
  1703. /**
  1704. * Constructs an `Observable` which, when subscribed, will cause the configured
  1705. * POST request to be executed on the server. See the individual overloads for
  1706. * details of `post()`'s return type based on the provided options.
  1707. */
  1708. /**
  1709. * Constructs an `Observable` which, when subscribed, will cause the configured
  1710. * POST request to be executed on the server. See the individual overloads for
  1711. * details of `post()`'s return type based on the provided options.
  1712. * @param {?} url
  1713. * @param {?} body
  1714. * @param {?=} options
  1715. * @return {?}
  1716. */
  1717. HttpClient.prototype.put = /**
  1718. * Constructs an `Observable` which, when subscribed, will cause the configured
  1719. * POST request to be executed on the server. See the individual overloads for
  1720. * details of `post()`'s return type based on the provided options.
  1721. * @param {?} url
  1722. * @param {?} body
  1723. * @param {?=} options
  1724. * @return {?}
  1725. */
  1726. function (url, body, options) {
  1727. if (options === void 0) { options = {}; }
  1728. return this.request('PUT', url, addBody(options, body));
  1729. };
  1730. HttpClient.decorators = [
  1731. { type: _angular_core.Injectable },
  1732. ];
  1733. /** @nocollapse */
  1734. HttpClient.ctorParameters = function () { return [
  1735. { type: HttpHandler, },
  1736. ]; };
  1737. return HttpClient;
  1738. }());
  1739. /**
  1740. * @fileoverview added by tsickle
  1741. * @suppress {checkTypes} checked by tsc
  1742. */
  1743. /**
  1744. * @license
  1745. * Copyright Google Inc. All Rights Reserved.
  1746. *
  1747. * Use of this source code is governed by an MIT-style license that can be
  1748. * found in the LICENSE file at https://angular.io/license
  1749. */
  1750. /**
  1751. * Intercepts `HttpRequest` and handles them.
  1752. *
  1753. * Most interceptors will transform the outgoing request before passing it to the
  1754. * next interceptor in the chain, by calling `next.handle(transformedReq)`.
  1755. *
  1756. * In rare cases, interceptors may wish to completely handle a request themselves,
  1757. * and not delegate to the remainder of the chain. This behavior is allowed.
  1758. *
  1759. * \@stable
  1760. * @record
  1761. */
  1762. /**
  1763. * `HttpHandler` which applies an `HttpInterceptor` to an `HttpRequest`.
  1764. *
  1765. * \@stable
  1766. */
  1767. var HttpInterceptorHandler = /** @class */ (function () {
  1768. function HttpInterceptorHandler(next, interceptor) {
  1769. this.next = next;
  1770. this.interceptor = interceptor;
  1771. }
  1772. /**
  1773. * @param {?} req
  1774. * @return {?}
  1775. */
  1776. HttpInterceptorHandler.prototype.handle = /**
  1777. * @param {?} req
  1778. * @return {?}
  1779. */
  1780. function (req) {
  1781. return this.interceptor.intercept(req, this.next);
  1782. };
  1783. return HttpInterceptorHandler;
  1784. }());
  1785. /**
  1786. * A multi-provider token which represents the array of `HttpInterceptor`s that
  1787. * are registered.
  1788. *
  1789. * \@stable
  1790. */
  1791. var HTTP_INTERCEPTORS = new _angular_core.InjectionToken('HTTP_INTERCEPTORS');
  1792. var NoopInterceptor = /** @class */ (function () {
  1793. function NoopInterceptor() {
  1794. }
  1795. /**
  1796. * @param {?} req
  1797. * @param {?} next
  1798. * @return {?}
  1799. */
  1800. NoopInterceptor.prototype.intercept = /**
  1801. * @param {?} req
  1802. * @param {?} next
  1803. * @return {?}
  1804. */
  1805. function (req, next) {
  1806. return next.handle(req);
  1807. };
  1808. NoopInterceptor.decorators = [
  1809. { type: _angular_core.Injectable },
  1810. ];
  1811. /** @nocollapse */
  1812. NoopInterceptor.ctorParameters = function () { return []; };
  1813. return NoopInterceptor;
  1814. }());
  1815. /**
  1816. * @fileoverview added by tsickle
  1817. * @suppress {checkTypes} checked by tsc
  1818. */
  1819. /**
  1820. * @license
  1821. * Copyright Google Inc. All Rights Reserved.
  1822. *
  1823. * Use of this source code is governed by an MIT-style license that can be
  1824. * found in the LICENSE file at https://angular.io/license
  1825. */
  1826. // Every request made through JSONP needs a callback name that's unique across the
  1827. // whole page. Each request is assigned an id and the callback name is constructed
  1828. // from that. The next id to be assigned is tracked in a global variable here that
  1829. // is shared among all applications on the page.
  1830. var nextRequestId = 0;
  1831. // Error text given when a JSONP script is injected, but doesn't invoke the callback
  1832. // passed in its URL.
  1833. var JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
  1834. // Error text given when a request is passed to the JsonpClientBackend that doesn't
  1835. // have a request method JSONP.
  1836. var JSONP_ERR_WRONG_METHOD = 'JSONP requests must use JSONP request method.';
  1837. var JSONP_ERR_WRONG_RESPONSE_TYPE = 'JSONP requests must use Json response type.';
  1838. /**
  1839. * DI token/abstract type representing a map of JSONP callbacks.
  1840. *
  1841. * In the browser, this should always be the `window` object.
  1842. *
  1843. * \@stable
  1844. * @abstract
  1845. */
  1846. var JsonpCallbackContext = /** @class */ (function () {
  1847. function JsonpCallbackContext() {
  1848. }
  1849. return JsonpCallbackContext;
  1850. }());
  1851. /**
  1852. * `HttpBackend` that only processes `HttpRequest` with the JSONP method,
  1853. * by performing JSONP style requests.
  1854. *
  1855. * \@stable
  1856. */
  1857. var JsonpClientBackend = /** @class */ (function () {
  1858. function JsonpClientBackend(callbackMap, document) {
  1859. this.callbackMap = callbackMap;
  1860. this.document = document;
  1861. }
  1862. /**
  1863. * Get the name of the next callback method, by incrementing the global `nextRequestId`.
  1864. * @return {?}
  1865. */
  1866. JsonpClientBackend.prototype.nextCallback = /**
  1867. * Get the name of the next callback method, by incrementing the global `nextRequestId`.
  1868. * @return {?}
  1869. */
  1870. function () { return "ng_jsonp_callback_" + nextRequestId++; };
  1871. /**
  1872. * Process a JSONP request and return an event stream of the results.
  1873. */
  1874. /**
  1875. * Process a JSONP request and return an event stream of the results.
  1876. * @param {?} req
  1877. * @return {?}
  1878. */
  1879. JsonpClientBackend.prototype.handle = /**
  1880. * Process a JSONP request and return an event stream of the results.
  1881. * @param {?} req
  1882. * @return {?}
  1883. */
  1884. function (req) {
  1885. var _this = this;
  1886. // Firstly, check both the method and response type. If either doesn't match
  1887. // then the request was improperly routed here and cannot be handled.
  1888. if (req.method !== 'JSONP') {
  1889. throw new Error(JSONP_ERR_WRONG_METHOD);
  1890. }
  1891. else if (req.responseType !== 'json') {
  1892. throw new Error(JSONP_ERR_WRONG_RESPONSE_TYPE);
  1893. }
  1894. // Everything else happens inside the Observable boundary.
  1895. return new rxjs_Observable.Observable(function (observer) {
  1896. // The first step to make a request is to generate the callback name, and replace the
  1897. // callback placeholder in the URL with the name. Care has to be taken here to ensure
  1898. // a trailing &, if matched, gets inserted back into the URL in the correct place.
  1899. var /** @type {?} */ callback = _this.nextCallback();
  1900. var /** @type {?} */ url = req.urlWithParams.replace(/=JSONP_CALLBACK(&|$)/, "=" + callback + "$1");
  1901. // Construct the <script> tag and point it at the URL.
  1902. var /** @type {?} */ node = _this.document.createElement('script');
  1903. node.src = url;
  1904. // A JSONP request requires waiting for multiple callbacks. These variables
  1905. // are closed over and track state across those callbacks.
  1906. // The response object, if one has been received, or null otherwise.
  1907. var /** @type {?} */ body = null;
  1908. // Whether the response callback has been called.
  1909. var /** @type {?} */ finished = false;
  1910. // Whether the request has been cancelled (and thus any other callbacks)
  1911. // should be ignored.
  1912. var /** @type {?} */ cancelled = false;
  1913. // Set the response callback in this.callbackMap (which will be the window
  1914. // object in the browser. The script being loaded via the <script> tag will
  1915. // eventually call this callback.
  1916. // Set the response callback in this.callbackMap (which will be the window
  1917. // object in the browser. The script being loaded via the <script> tag will
  1918. // eventually call this callback.
  1919. _this.callbackMap[callback] = function (data) {
  1920. // Data has been received from the JSONP script. Firstly, delete this callback.
  1921. delete _this.callbackMap[callback];
  1922. // Next, make sure the request wasn't cancelled in the meantime.
  1923. if (cancelled) {
  1924. return;
  1925. }
  1926. // Set state to indicate data was received.
  1927. body = data;
  1928. finished = true;
  1929. };
  1930. // cleanup() is a utility closure that removes the <script> from the page and
  1931. // the response callback from the window. This logic is used in both the
  1932. // success, error, and cancellation paths, so it's extracted out for convenience.
  1933. var /** @type {?} */ cleanup = function () {
  1934. // Remove the <script> tag if it's still on the page.
  1935. if (node.parentNode) {
  1936. node.parentNode.removeChild(node);
  1937. }
  1938. // Remove the response callback from the callbackMap (window object in the
  1939. // browser).
  1940. delete _this.callbackMap[callback];
  1941. };
  1942. // onLoad() is the success callback which runs after the response callback
  1943. // if the JSONP script loads successfully. The event itself is unimportant.
  1944. // If something went wrong, onLoad() may run without the response callback
  1945. // having been invoked.
  1946. var /** @type {?} */ onLoad = function (event) {
  1947. // Do nothing if the request has been cancelled.
  1948. if (cancelled) {
  1949. return;
  1950. }
  1951. // Cleanup the page.
  1952. cleanup();
  1953. // Check whether the response callback has run.
  1954. if (!finished) {
  1955. // It hasn't, something went wrong with the request. Return an error via
  1956. // the Observable error path. All JSONP errors have status 0.
  1957. observer.error(new HttpErrorResponse({
  1958. url: url,
  1959. status: 0,
  1960. statusText: 'JSONP Error',
  1961. error: new Error(JSONP_ERR_NO_CALLBACK),
  1962. }));
  1963. return;
  1964. }
  1965. // Success. body either contains the response body or null if none was
  1966. // returned.
  1967. observer.next(new HttpResponse({
  1968. body: body,
  1969. status: 200,
  1970. statusText: 'OK', url: url,
  1971. }));
  1972. // Complete the stream, the response is over.
  1973. observer.complete();
  1974. };
  1975. // onError() is the error callback, which runs if the script returned generates
  1976. // a Javascript error. It emits the error via the Observable error channel as
  1977. // a HttpErrorResponse.
  1978. var /** @type {?} */ onError = function (error) {
  1979. // If the request was already cancelled, no need to emit anything.
  1980. if (cancelled) {
  1981. return;
  1982. }
  1983. cleanup();
  1984. // Wrap the error in a HttpErrorResponse.
  1985. observer.error(new HttpErrorResponse({
  1986. error: error,
  1987. status: 0,
  1988. statusText: 'JSONP Error', url: url,
  1989. }));
  1990. };
  1991. // Subscribe to both the success (load) and error events on the <script> tag,
  1992. // and add it to the page.
  1993. node.addEventListener('load', onLoad);
  1994. node.addEventListener('error', onError);
  1995. _this.document.body.appendChild(node);
  1996. // The request has now been successfully sent.
  1997. observer.next({ type: HttpEventType.Sent });
  1998. // Cancellation handler.
  1999. return function () {
  2000. // Track the cancellation so event listeners won't do anything even if already scheduled.
  2001. cancelled = true;
  2002. // Remove the event listeners so they won't run if the events later fire.
  2003. node.removeEventListener('load', onLoad);
  2004. node.removeEventListener('error', onError);
  2005. // And finally, clean up the page.
  2006. cleanup();
  2007. };
  2008. });
  2009. };
  2010. JsonpClientBackend.decorators = [
  2011. { type: _angular_core.Injectable },
  2012. ];
  2013. /** @nocollapse */
  2014. JsonpClientBackend.ctorParameters = function () { return [
  2015. { type: JsonpCallbackContext, },
  2016. { type: undefined, decorators: [{ type: _angular_core.Inject, args: [_angular_common.DOCUMENT,] },] },
  2017. ]; };
  2018. return JsonpClientBackend;
  2019. }());
  2020. /**
  2021. * An `HttpInterceptor` which identifies requests with the method JSONP and
  2022. * shifts them to the `JsonpClientBackend`.
  2023. *
  2024. * \@stable
  2025. */
  2026. var JsonpInterceptor = /** @class */ (function () {
  2027. function JsonpInterceptor(jsonp) {
  2028. this.jsonp = jsonp;
  2029. }
  2030. /**
  2031. * @param {?} req
  2032. * @param {?} next
  2033. * @return {?}
  2034. */
  2035. JsonpInterceptor.prototype.intercept = /**
  2036. * @param {?} req
  2037. * @param {?} next
  2038. * @return {?}
  2039. */
  2040. function (req, next) {
  2041. if (req.method === 'JSONP') {
  2042. return this.jsonp.handle(/** @type {?} */ (req));
  2043. }
  2044. // Fall through for normal HTTP requests.
  2045. return next.handle(req);
  2046. };
  2047. JsonpInterceptor.decorators = [
  2048. { type: _angular_core.Injectable },
  2049. ];
  2050. /** @nocollapse */
  2051. JsonpInterceptor.ctorParameters = function () { return [
  2052. { type: JsonpClientBackend, },
  2053. ]; };
  2054. return JsonpInterceptor;
  2055. }());
  2056. /**
  2057. * @fileoverview added by tsickle
  2058. * @suppress {checkTypes} checked by tsc
  2059. */
  2060. /**
  2061. * @license
  2062. * Copyright Google Inc. All Rights Reserved.
  2063. *
  2064. * Use of this source code is governed by an MIT-style license that can be
  2065. * found in the LICENSE file at https://angular.io/license
  2066. */
  2067. var XSSI_PREFIX = /^\)\]\}',?\n/;
  2068. /**
  2069. * Determine an appropriate URL for the response, by checking either
  2070. * XMLHttpRequest.responseURL or the X-Request-URL header.
  2071. * @param {?} xhr
  2072. * @return {?}
  2073. */
  2074. function getResponseUrl(xhr) {
  2075. if ('responseURL' in xhr && xhr.responseURL) {
  2076. return xhr.responseURL;
  2077. }
  2078. if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
  2079. return xhr.getResponseHeader('X-Request-URL');
  2080. }
  2081. return null;
  2082. }
  2083. /**
  2084. * A wrapper around the `XMLHttpRequest` constructor.
  2085. *
  2086. * \@stable
  2087. * @abstract
  2088. */
  2089. var XhrFactory = /** @class */ (function () {
  2090. function XhrFactory() {
  2091. }
  2092. return XhrFactory;
  2093. }());
  2094. /**
  2095. * A factory for \@{link HttpXhrBackend} that uses the `XMLHttpRequest` browser API.
  2096. *
  2097. * \@stable
  2098. */
  2099. var BrowserXhr = /** @class */ (function () {
  2100. function BrowserXhr() {
  2101. }
  2102. /**
  2103. * @return {?}
  2104. */
  2105. BrowserXhr.prototype.build = /**
  2106. * @return {?}
  2107. */
  2108. function () { return /** @type {?} */ ((new XMLHttpRequest())); };
  2109. BrowserXhr.decorators = [
  2110. { type: _angular_core.Injectable },
  2111. ];
  2112. /** @nocollapse */
  2113. BrowserXhr.ctorParameters = function () { return []; };
  2114. return BrowserXhr;
  2115. }());
  2116. /**
  2117. * An `HttpBackend` which uses the XMLHttpRequest API to send
  2118. * requests to a backend server.
  2119. *
  2120. * \@stable
  2121. */
  2122. var HttpXhrBackend = /** @class */ (function () {
  2123. function HttpXhrBackend(xhrFactory) {
  2124. this.xhrFactory = xhrFactory;
  2125. }
  2126. /**
  2127. * Process a request and return a stream of response events.
  2128. */
  2129. /**
  2130. * Process a request and return a stream of response events.
  2131. * @param {?} req
  2132. * @return {?}
  2133. */
  2134. HttpXhrBackend.prototype.handle = /**
  2135. * Process a request and return a stream of response events.
  2136. * @param {?} req
  2137. * @return {?}
  2138. */
  2139. function (req) {
  2140. var _this = this;
  2141. // Quick check to give a better error message when a user attempts to use
  2142. // HttpClient.jsonp() without installing the JsonpClientModule
  2143. if (req.method === 'JSONP') {
  2144. throw new Error("Attempted to construct Jsonp request without JsonpClientModule installed.");
  2145. }
  2146. // Everything happens on Observable subscription.
  2147. return new rxjs_Observable.Observable(function (observer) {
  2148. // Start by setting up the XHR object with request method, URL, and withCredentials flag.
  2149. var /** @type {?} */ xhr = _this.xhrFactory.build();
  2150. xhr.open(req.method, req.urlWithParams);
  2151. if (!!req.withCredentials) {
  2152. xhr.withCredentials = true;
  2153. }
  2154. // Add all the requested headers.
  2155. req.headers.forEach(function (name, values) { return xhr.setRequestHeader(name, values.join(',')); });
  2156. // Add an Accept header if one isn't present already.
  2157. if (!req.headers.has('Accept')) {
  2158. xhr.setRequestHeader('Accept', 'application/json, text/plain, */*');
  2159. }
  2160. // Auto-detect the Content-Type header if one isn't present already.
  2161. if (!req.headers.has('Content-Type')) {
  2162. var /** @type {?} */ detectedType = req.detectContentTypeHeader();
  2163. // Sometimes Content-Type detection fails.
  2164. if (detectedType !== null) {
  2165. xhr.setRequestHeader('Content-Type', detectedType);
  2166. }
  2167. }
  2168. // Set the responseType if one was requested.
  2169. if (req.responseType) {
  2170. var /** @type {?} */ responseType = req.responseType.toLowerCase();
  2171. // JSON responses need to be processed as text. This is because if the server
  2172. // returns an XSSI-prefixed JSON response, the browser will fail to parse it,
  2173. // xhr.response will be null, and xhr.responseText cannot be accessed to
  2174. // retrieve the prefixed JSON data in order to strip the prefix. Thus, all JSON
  2175. // is parsed by first requesting text and then applying JSON.parse.
  2176. xhr.responseType = /** @type {?} */ (((responseType !== 'json') ? responseType : 'text'));
  2177. }
  2178. // Serialize the request body if one is present. If not, this will be set to null.
  2179. var /** @type {?} */ reqBody = req.serializeBody();
  2180. // If progress events are enabled, response headers will be delivered
  2181. // in two events - the HttpHeaderResponse event and the full HttpResponse
  2182. // event. However, since response headers don't change in between these
  2183. // two events, it doesn't make sense to parse them twice. So headerResponse
  2184. // caches the data extracted from the response whenever it's first parsed,
  2185. // to ensure parsing isn't duplicated.
  2186. var /** @type {?} */ headerResponse = null;
  2187. // partialFromXhr extracts the HttpHeaderResponse from the current XMLHttpRequest
  2188. // state, and memoizes it into headerResponse.
  2189. var /** @type {?} */ partialFromXhr = function () {
  2190. if (headerResponse !== null) {
  2191. return headerResponse;
  2192. }
  2193. // Read status and normalize an IE9 bug (http://bugs.jquery.com/ticket/1450).
  2194. var /** @type {?} */ status = xhr.status === 1223 ? 204 : xhr.status;
  2195. var /** @type {?} */ statusText = xhr.statusText || 'OK';
  2196. // Parse headers from XMLHttpRequest - this step is lazy.
  2197. var /** @type {?} */ headers = new HttpHeaders(xhr.getAllResponseHeaders());
  2198. // Read the response URL from the XMLHttpResponse instance and fall back on the
  2199. // request URL.
  2200. var /** @type {?} */ url = getResponseUrl(xhr) || req.url;
  2201. // Construct the HttpHeaderResponse and memoize it.
  2202. headerResponse = new HttpHeaderResponse({ headers: headers, status: status, statusText: statusText, url: url });
  2203. return headerResponse;
  2204. };
  2205. // Next, a few closures are defined for the various events which XMLHttpRequest can
  2206. // emit. This allows them to be unregistered as event listeners later.
  2207. // First up is the load event, which represents a response being fully available.
  2208. var /** @type {?} */ onLoad = function () {
  2209. // Read response state from the memoized partial data.
  2210. var _a = partialFromXhr(), headers = _a.headers, status = _a.status, statusText = _a.statusText, url = _a.url;
  2211. // The body will be read out if present.
  2212. var /** @type {?} */ body = null;
  2213. if (status !== 204) {
  2214. // Use XMLHttpRequest.response if set, responseText otherwise.
  2215. body = (typeof xhr.response === 'undefined') ? xhr.responseText : xhr.response;
  2216. }
  2217. // Normalize another potential bug (this one comes from CORS).
  2218. if (status === 0) {
  2219. status = !!body ? 200 : 0;
  2220. }
  2221. // ok determines whether the response will be transmitted on the event or
  2222. // error channel. Unsuccessful status codes (not 2xx) will always be errors,
  2223. // but a successful status code can still result in an error if the user
  2224. // asked for JSON data and the body cannot be parsed as such.
  2225. var /** @type {?} */ ok = status >= 200 && status < 300;
  2226. // Check whether the body needs to be parsed as JSON (in many cases the browser
  2227. // will have done that already).
  2228. if (req.responseType === 'json' && typeof body === 'string') {
  2229. // Save the original body, before attempting XSSI prefix stripping.
  2230. var /** @type {?} */ originalBody = body;
  2231. body = body.replace(XSSI_PREFIX, '');
  2232. try {
  2233. // Attempt the parse. If it fails, a parse error should be delivered to the user.
  2234. body = body !== '' ? JSON.parse(body) : null;
  2235. }
  2236. catch (/** @type {?} */ error) {
  2237. // Since the JSON.parse failed, it's reasonable to assume this might not have been a
  2238. // JSON response. Restore the original body (including any XSSI prefix) to deliver
  2239. // a better error response.
  2240. body = originalBody;
  2241. // If this was an error request to begin with, leave it as a string, it probably
  2242. // just isn't JSON. Otherwise, deliver the parsing error to the user.
  2243. if (ok) {
  2244. // Even though the response status was 2xx, this is still an error.
  2245. ok = false;
  2246. // The parse error contains the text of the body that failed to parse.
  2247. body = /** @type {?} */ ({ error: error, text: body });
  2248. }
  2249. }
  2250. }
  2251. if (ok) {
  2252. // A successful response is delivered on the event stream.
  2253. observer.next(new HttpResponse({
  2254. body: body,
  2255. headers: headers,
  2256. status: status,
  2257. statusText: statusText,
  2258. url: url || undefined,
  2259. }));
  2260. // The full body has been received and delivered, no further events
  2261. // are possible. This request is complete.
  2262. observer.complete();
  2263. }
  2264. else {
  2265. // An unsuccessful request is delivered on the error channel.
  2266. observer.error(new HttpErrorResponse({
  2267. // The error in this case is the response body (error from the server).
  2268. error: body,
  2269. headers: headers,
  2270. status: status,
  2271. statusText: statusText,
  2272. url: url || undefined,
  2273. }));
  2274. }
  2275. };
  2276. // The onError callback is called when something goes wrong at the network level.
  2277. // Connection timeout, DNS error, offline, etc. These are actual errors, and are
  2278. // transmitted on the error channel.
  2279. var /** @type {?} */ onError = function (error) {
  2280. var /** @type {?} */ res = new HttpErrorResponse({
  2281. error: error,
  2282. status: xhr.status || 0,
  2283. statusText: xhr.statusText || 'Unknown Error',
  2284. });
  2285. observer.error(res);
  2286. };
  2287. // The sentHeaders flag tracks whether the HttpResponseHeaders event
  2288. // has been sent on the stream. This is necessary to track if progress
  2289. // is enabled since the event will be sent on only the first download
  2290. // progerss event.
  2291. var /** @type {?} */ sentHeaders = false;
  2292. // The download progress event handler, which is only registered if
  2293. // progress events are enabled.
  2294. var /** @type {?} */ onDownProgress = function (event) {
  2295. // Send the HttpResponseHeaders event if it hasn't been sent already.
  2296. if (!sentHeaders) {
  2297. observer.next(partialFromXhr());
  2298. sentHeaders = true;
  2299. }
  2300. // Start building the download progress event to deliver on the response
  2301. // event stream.
  2302. var /** @type {?} */ progressEvent = {
  2303. type: HttpEventType.DownloadProgress,
  2304. loaded: event.loaded,
  2305. };
  2306. // Set the total number of bytes in the event if it's available.
  2307. if (event.lengthComputable) {
  2308. progressEvent.total = event.total;
  2309. }
  2310. // If the request was for text content and a partial response is
  2311. // available on XMLHttpRequest, include it in the progress event
  2312. // to allow for streaming reads.
  2313. if (req.responseType === 'text' && !!xhr.responseText) {
  2314. progressEvent.partialText = xhr.responseText;
  2315. }
  2316. // Finally, fire the event.
  2317. observer.next(progressEvent);
  2318. };
  2319. // The upload progress event handler, which is only registered if
  2320. // progress events are enabled.
  2321. var /** @type {?} */ onUpProgress = function (event) {
  2322. // Upload progress events are simpler. Begin building the progress
  2323. // event.
  2324. var /** @type {?} */ progress = {
  2325. type: HttpEventType.UploadProgress,
  2326. loaded: event.loaded,
  2327. };
  2328. // If the total number of bytes being uploaded is available, include
  2329. // it.
  2330. if (event.lengthComputable) {
  2331. progress.total = event.total;
  2332. }
  2333. // Send the event.
  2334. observer.next(progress);
  2335. };
  2336. // By default, register for load and error events.
  2337. xhr.addEventListener('load', onLoad);
  2338. xhr.addEventListener('error', onError);
  2339. // Progress events are only enabled if requested.
  2340. if (req.reportProgress) {
  2341. // Download progress is always enabled if requested.
  2342. xhr.addEventListener('progress', onDownProgress);
  2343. // Upload progress depends on whether there is a body to upload.
  2344. if (reqBody !== null && xhr.upload) {
  2345. xhr.upload.addEventListener('progress', onUpProgress);
  2346. }
  2347. }
  2348. // Fire the request, and notify the event stream that it was fired.
  2349. xhr.send(reqBody);
  2350. observer.next({ type: HttpEventType.Sent });
  2351. // This is the return from the Observable function, which is the
  2352. // request cancellation handler.
  2353. return function () {
  2354. // On a cancellation, remove all registered event listeners.
  2355. xhr.removeEventListener('error', onError);
  2356. xhr.removeEventListener('load', onLoad);
  2357. if (req.reportProgress) {
  2358. xhr.removeEventListener('progress', onDownProgress);
  2359. if (reqBody !== null && xhr.upload) {
  2360. xhr.upload.removeEventListener('progress', onUpProgress);
  2361. }
  2362. }
  2363. // Finally, abort the in-flight request.
  2364. xhr.abort();
  2365. };
  2366. });
  2367. };
  2368. HttpXhrBackend.decorators = [
  2369. { type: _angular_core.Injectable },
  2370. ];
  2371. /** @nocollapse */
  2372. HttpXhrBackend.ctorParameters = function () { return [
  2373. { type: XhrFactory, },
  2374. ]; };
  2375. return HttpXhrBackend;
  2376. }());
  2377. /**
  2378. * @fileoverview added by tsickle
  2379. * @suppress {checkTypes} checked by tsc
  2380. */
  2381. /**
  2382. * @license
  2383. * Copyright Google Inc. All Rights Reserved.
  2384. *
  2385. * Use of this source code is governed by an MIT-style license that can be
  2386. * found in the LICENSE file at https://angular.io/license
  2387. */
  2388. var XSRF_COOKIE_NAME = new _angular_core.InjectionToken('XSRF_COOKIE_NAME');
  2389. var XSRF_HEADER_NAME = new _angular_core.InjectionToken('XSRF_HEADER_NAME');
  2390. /**
  2391. * Retrieves the current XSRF token to use with the next outgoing request.
  2392. *
  2393. * \@stable
  2394. * @abstract
  2395. */
  2396. var HttpXsrfTokenExtractor = /** @class */ (function () {
  2397. function HttpXsrfTokenExtractor() {
  2398. }
  2399. return HttpXsrfTokenExtractor;
  2400. }());
  2401. /**
  2402. * `HttpXsrfTokenExtractor` which retrieves the token from a cookie.
  2403. */
  2404. var HttpXsrfCookieExtractor = /** @class */ (function () {
  2405. function HttpXsrfCookieExtractor(doc, platform, cookieName) {
  2406. this.doc = doc;
  2407. this.platform = platform;
  2408. this.cookieName = cookieName;
  2409. this.lastCookieString = '';
  2410. this.lastToken = null;
  2411. /**
  2412. * \@internal for testing
  2413. */
  2414. this.parseCount = 0;
  2415. }
  2416. /**
  2417. * @return {?}
  2418. */
  2419. HttpXsrfCookieExtractor.prototype.getToken = /**
  2420. * @return {?}
  2421. */
  2422. function () {
  2423. if (this.platform === 'server') {
  2424. return null;
  2425. }
  2426. var /** @type {?} */ cookieString = this.doc.cookie || '';
  2427. if (cookieString !== this.lastCookieString) {
  2428. this.parseCount++;
  2429. this.lastToken = _angular_common.ɵparseCookieValue(cookieString, this.cookieName);
  2430. this.lastCookieString = cookieString;
  2431. }
  2432. return this.lastToken;
  2433. };
  2434. HttpXsrfCookieExtractor.decorators = [
  2435. { type: _angular_core.Injectable },
  2436. ];
  2437. /** @nocollapse */
  2438. HttpXsrfCookieExtractor.ctorParameters = function () { return [
  2439. { type: undefined, decorators: [{ type: _angular_core.Inject, args: [_angular_common.DOCUMENT,] },] },
  2440. { type: undefined, decorators: [{ type: _angular_core.Inject, args: [_angular_core.PLATFORM_ID,] },] },
  2441. { type: undefined, decorators: [{ type: _angular_core.Inject, args: [XSRF_COOKIE_NAME,] },] },
  2442. ]; };
  2443. return HttpXsrfCookieExtractor;
  2444. }());
  2445. /**
  2446. * `HttpInterceptor` which adds an XSRF token to eligible outgoing requests.
  2447. */
  2448. var HttpXsrfInterceptor = /** @class */ (function () {
  2449. function HttpXsrfInterceptor(tokenService, headerName) {
  2450. this.tokenService = tokenService;
  2451. this.headerName = headerName;
  2452. }
  2453. /**
  2454. * @param {?} req
  2455. * @param {?} next
  2456. * @return {?}
  2457. */
  2458. HttpXsrfInterceptor.prototype.intercept = /**
  2459. * @param {?} req
  2460. * @param {?} next
  2461. * @return {?}
  2462. */
  2463. function (req, next) {
  2464. var /** @type {?} */ lcUrl = req.url.toLowerCase();
  2465. // Skip both non-mutating requests and absolute URLs.
  2466. // Non-mutating requests don't require a token, and absolute URLs require special handling
  2467. // anyway as the cookie set
  2468. // on our origin is not the same as the token expected by another origin.
  2469. if (req.method === 'GET' || req.method === 'HEAD' || lcUrl.startsWith('http://') ||
  2470. lcUrl.startsWith('https://')) {
  2471. return next.handle(req);
  2472. }
  2473. var /** @type {?} */ token = this.tokenService.getToken();
  2474. // Be careful not to overwrite an existing header of the same name.
  2475. if (token !== null && !req.headers.has(this.headerName)) {
  2476. req = req.clone({ headers: req.headers.set(this.headerName, token) });
  2477. }
  2478. return next.handle(req);
  2479. };
  2480. HttpXsrfInterceptor.decorators = [
  2481. { type: _angular_core.Injectable },
  2482. ];
  2483. /** @nocollapse */
  2484. HttpXsrfInterceptor.ctorParameters = function () { return [
  2485. { type: HttpXsrfTokenExtractor, },
  2486. { type: undefined, decorators: [{ type: _angular_core.Inject, args: [XSRF_HEADER_NAME,] },] },
  2487. ]; };
  2488. return HttpXsrfInterceptor;
  2489. }());
  2490. /**
  2491. * @fileoverview added by tsickle
  2492. * @suppress {checkTypes} checked by tsc
  2493. */
  2494. /**
  2495. * @license
  2496. * Copyright Google Inc. All Rights Reserved.
  2497. *
  2498. * Use of this source code is governed by an MIT-style license that can be
  2499. * found in the LICENSE file at https://angular.io/license
  2500. */
  2501. /**
  2502. * An `HttpHandler` that applies a bunch of `HttpInterceptor`s
  2503. * to a request before passing it to the given `HttpBackend`.
  2504. *
  2505. * The interceptors are loaded lazily from the injector, to allow
  2506. * interceptors to themselves inject classes depending indirectly
  2507. * on `HttpInterceptingHandler` itself.
  2508. */
  2509. var HttpInterceptingHandler = /** @class */ (function () {
  2510. function HttpInterceptingHandler(backend, injector) {
  2511. this.backend = backend;
  2512. this.injector = injector;
  2513. this.chain = null;
  2514. }
  2515. /**
  2516. * @param {?} req
  2517. * @return {?}
  2518. */
  2519. HttpInterceptingHandler.prototype.handle = /**
  2520. * @param {?} req
  2521. * @return {?}
  2522. */
  2523. function (req) {
  2524. if (this.chain === null) {
  2525. var /** @type {?} */ interceptors = this.injector.get(HTTP_INTERCEPTORS, []);
  2526. this.chain = interceptors.reduceRight(function (next, interceptor) { return new HttpInterceptorHandler(next, interceptor); }, this.backend);
  2527. }
  2528. return this.chain.handle(req);
  2529. };
  2530. HttpInterceptingHandler.decorators = [
  2531. { type: _angular_core.Injectable },
  2532. ];
  2533. /** @nocollapse */
  2534. HttpInterceptingHandler.ctorParameters = function () { return [
  2535. { type: HttpBackend, },
  2536. { type: _angular_core.Injector, },
  2537. ]; };
  2538. return HttpInterceptingHandler;
  2539. }());
  2540. /**
  2541. * Constructs an `HttpHandler` that applies a bunch of `HttpInterceptor`s
  2542. * to a request before passing it to the given `HttpBackend`.
  2543. *
  2544. * Meant to be used as a factory function within `HttpClientModule`.
  2545. *
  2546. * \@stable
  2547. * @param {?} backend
  2548. * @param {?=} interceptors
  2549. * @return {?}
  2550. */
  2551. function interceptingHandler(backend, interceptors) {
  2552. if (interceptors === void 0) { interceptors = []; }
  2553. if (!interceptors) {
  2554. return backend;
  2555. }
  2556. return interceptors.reduceRight(function (next, interceptor) { return new HttpInterceptorHandler(next, interceptor); }, backend);
  2557. }
  2558. /**
  2559. * Factory function that determines where to store JSONP callbacks.
  2560. *
  2561. * Ordinarily JSONP callbacks are stored on the `window` object, but this may not exist
  2562. * in test environments. In that case, callbacks are stored on an anonymous object instead.
  2563. *
  2564. * \@stable
  2565. * @return {?}
  2566. */
  2567. function jsonpCallbackContext() {
  2568. if (typeof window === 'object') {
  2569. return window;
  2570. }
  2571. return {};
  2572. }
  2573. /**
  2574. * `NgModule` which adds XSRF protection support to outgoing requests.
  2575. *
  2576. * Provided the server supports a cookie-based XSRF protection system, this
  2577. * module can be used directly to configure XSRF protection with the correct
  2578. * cookie and header names.
  2579. *
  2580. * If no such names are provided, the default is to use `X-XSRF-TOKEN` for
  2581. * the header name and `XSRF-TOKEN` for the cookie name.
  2582. *
  2583. * \@stable
  2584. */
  2585. var HttpClientXsrfModule = /** @class */ (function () {
  2586. function HttpClientXsrfModule() {
  2587. }
  2588. /**
  2589. * Disable the default XSRF protection.
  2590. */
  2591. /**
  2592. * Disable the default XSRF protection.
  2593. * @return {?}
  2594. */
  2595. HttpClientXsrfModule.disable = /**
  2596. * Disable the default XSRF protection.
  2597. * @return {?}
  2598. */
  2599. function () {
  2600. return {
  2601. ngModule: HttpClientXsrfModule,
  2602. providers: [
  2603. { provide: HttpXsrfInterceptor, useClass: NoopInterceptor },
  2604. ],
  2605. };
  2606. };
  2607. /**
  2608. * Configure XSRF protection to use the given cookie name or header name,
  2609. * or the default names (as described above) if not provided.
  2610. */
  2611. /**
  2612. * Configure XSRF protection to use the given cookie name or header name,
  2613. * or the default names (as described above) if not provided.
  2614. * @param {?=} options
  2615. * @return {?}
  2616. */
  2617. HttpClientXsrfModule.withOptions = /**
  2618. * Configure XSRF protection to use the given cookie name or header name,
  2619. * or the default names (as described above) if not provided.
  2620. * @param {?=} options
  2621. * @return {?}
  2622. */
  2623. function (options) {
  2624. if (options === void 0) { options = {}; }
  2625. return {
  2626. ngModule: HttpClientXsrfModule,
  2627. providers: [
  2628. options.cookieName ? { provide: XSRF_COOKIE_NAME, useValue: options.cookieName } : [],
  2629. options.headerName ? { provide: XSRF_HEADER_NAME, useValue: options.headerName } : [],
  2630. ],
  2631. };
  2632. };
  2633. HttpClientXsrfModule.decorators = [
  2634. { type: _angular_core.NgModule, args: [{
  2635. providers: [
  2636. HttpXsrfInterceptor,
  2637. { provide: HTTP_INTERCEPTORS, useExisting: HttpXsrfInterceptor, multi: true },
  2638. { provide: HttpXsrfTokenExtractor, useClass: HttpXsrfCookieExtractor },
  2639. { provide: XSRF_COOKIE_NAME, useValue: 'XSRF-TOKEN' },
  2640. { provide: XSRF_HEADER_NAME, useValue: 'X-XSRF-TOKEN' },
  2641. ],
  2642. },] },
  2643. ];
  2644. /** @nocollapse */
  2645. HttpClientXsrfModule.ctorParameters = function () { return []; };
  2646. return HttpClientXsrfModule;
  2647. }());
  2648. /**
  2649. * `NgModule` which provides the `HttpClient` and associated services.
  2650. *
  2651. * Interceptors can be added to the chain behind `HttpClient` by binding them
  2652. * to the multiprovider for `HTTP_INTERCEPTORS`.
  2653. *
  2654. * \@stable
  2655. */
  2656. var HttpClientModule = /** @class */ (function () {
  2657. function HttpClientModule() {
  2658. }
  2659. HttpClientModule.decorators = [
  2660. { type: _angular_core.NgModule, args: [{
  2661. imports: [
  2662. HttpClientXsrfModule.withOptions({
  2663. cookieName: 'XSRF-TOKEN',
  2664. headerName: 'X-XSRF-TOKEN',
  2665. }),
  2666. ],
  2667. providers: [
  2668. HttpClient,
  2669. { provide: HttpHandler, useClass: HttpInterceptingHandler },
  2670. HttpXhrBackend,
  2671. { provide: HttpBackend, useExisting: HttpXhrBackend },
  2672. BrowserXhr,
  2673. { provide: XhrFactory, useExisting: BrowserXhr },
  2674. ],
  2675. },] },
  2676. ];
  2677. /** @nocollapse */
  2678. HttpClientModule.ctorParameters = function () { return []; };
  2679. return HttpClientModule;
  2680. }());
  2681. /**
  2682. * `NgModule` which enables JSONP support in `HttpClient`.
  2683. *
  2684. * Without this module, Jsonp requests will reach the backend
  2685. * with method JSONP, where they'll be rejected.
  2686. *
  2687. * \@stable
  2688. */
  2689. var HttpClientJsonpModule = /** @class */ (function () {
  2690. function HttpClientJsonpModule() {
  2691. }
  2692. HttpClientJsonpModule.decorators = [
  2693. { type: _angular_core.NgModule, args: [{
  2694. providers: [
  2695. JsonpClientBackend,
  2696. { provide: JsonpCallbackContext, useFactory: jsonpCallbackContext },
  2697. { provide: HTTP_INTERCEPTORS, useClass: JsonpInterceptor, multi: true },
  2698. ],
  2699. },] },
  2700. ];
  2701. /** @nocollapse */
  2702. HttpClientJsonpModule.ctorParameters = function () { return []; };
  2703. return HttpClientJsonpModule;
  2704. }());
  2705. exports.HttpBackend = HttpBackend;
  2706. exports.HttpHandler = HttpHandler;
  2707. exports.HttpClient = HttpClient;
  2708. exports.HttpHeaders = HttpHeaders;
  2709. exports.HTTP_INTERCEPTORS = HTTP_INTERCEPTORS;
  2710. exports.JsonpClientBackend = JsonpClientBackend;
  2711. exports.JsonpInterceptor = JsonpInterceptor;
  2712. exports.HttpClientJsonpModule = HttpClientJsonpModule;
  2713. exports.HttpClientModule = HttpClientModule;
  2714. exports.HttpClientXsrfModule = HttpClientXsrfModule;
  2715. exports.ɵinterceptingHandler = interceptingHandler;
  2716. exports.HttpParams = HttpParams;
  2717. exports.HttpUrlEncodingCodec = HttpUrlEncodingCodec;
  2718. exports.HttpRequest = HttpRequest;
  2719. exports.HttpErrorResponse = HttpErrorResponse;
  2720. exports.HttpEventType = HttpEventType;
  2721. exports.HttpHeaderResponse = HttpHeaderResponse;
  2722. exports.HttpResponse = HttpResponse;
  2723. exports.HttpResponseBase = HttpResponseBase;
  2724. exports.HttpXhrBackend = HttpXhrBackend;
  2725. exports.XhrFactory = XhrFactory;
  2726. exports.HttpXsrfTokenExtractor = HttpXsrfTokenExtractor;
  2727. exports.ɵa = NoopInterceptor;
  2728. exports.ɵb = JsonpCallbackContext;
  2729. exports.ɵc = HttpInterceptingHandler;
  2730. exports.ɵd = jsonpCallbackContext;
  2731. exports.ɵe = BrowserXhr;
  2732. exports.ɵh = HttpXsrfCookieExtractor;
  2733. exports.ɵi = HttpXsrfInterceptor;
  2734. exports.ɵf = XSRF_COOKIE_NAME;
  2735. exports.ɵg = XSRF_HEADER_NAME;
  2736. Object.defineProperty(exports, '__esModule', { value: true });
  2737. })));
  2738. //# sourceMappingURL=common-http.umd.js.map