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