12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  1. /**
  2. * @license Angular v5.2.11
  3. * (c) 2010-2018 Google, Inc. https://angular.io/
  4. * License: MIT
  5. */
  6. import { Injectable, NgModule, Version } from '@angular/core';
  7. import { Observable } from 'rxjs/Observable';
  8. import { ɵgetDOM } from '@angular/platform-browser';
  9. /**
  10. * @fileoverview added by tsickle
  11. * @suppress {checkTypes} checked by tsc
  12. */
  13. /**
  14. * @license
  15. * Copyright Google Inc. All Rights Reserved.
  16. *
  17. * Use of this source code is governed by an MIT-style license that can be
  18. * found in the LICENSE file at https://angular.io/license
  19. */
  20. /**
  21. * A backend for http that uses the `XMLHttpRequest` browser API.
  22. *
  23. * Take care not to evaluate this in non-browser contexts.
  24. *
  25. * @deprecated use \@angular/common/http instead
  26. */
  27. class BrowserXhr {
  28. constructor() { }
  29. /**
  30. * @return {?}
  31. */
  32. build() { return /** @type {?} */ ((new XMLHttpRequest())); }
  33. }
  34. BrowserXhr.decorators = [
  35. { type: Injectable },
  36. ];
  37. /** @nocollapse */
  38. BrowserXhr.ctorParameters = () => [];
  39. /**
  40. * @fileoverview added by tsickle
  41. * @suppress {checkTypes} checked by tsc
  42. */
  43. /**
  44. * @license
  45. * Copyright Google Inc. All Rights Reserved.
  46. *
  47. * Use of this source code is governed by an MIT-style license that can be
  48. * found in the LICENSE file at https://angular.io/license
  49. */
  50. /** @enum {number} */
  51. const RequestMethod = {
  52. Get: 0,
  53. Post: 1,
  54. Put: 2,
  55. Delete: 3,
  56. Options: 4,
  57. Head: 5,
  58. Patch: 6,
  59. };
  60. RequestMethod[RequestMethod.Get] = "Get";
  61. RequestMethod[RequestMethod.Post] = "Post";
  62. RequestMethod[RequestMethod.Put] = "Put";
  63. RequestMethod[RequestMethod.Delete] = "Delete";
  64. RequestMethod[RequestMethod.Options] = "Options";
  65. RequestMethod[RequestMethod.Head] = "Head";
  66. RequestMethod[RequestMethod.Patch] = "Patch";
  67. /** @enum {number} */
  68. const ReadyState = {
  69. Unsent: 0,
  70. Open: 1,
  71. HeadersReceived: 2,
  72. Loading: 3,
  73. Done: 4,
  74. Cancelled: 5,
  75. };
  76. ReadyState[ReadyState.Unsent] = "Unsent";
  77. ReadyState[ReadyState.Open] = "Open";
  78. ReadyState[ReadyState.HeadersReceived] = "HeadersReceived";
  79. ReadyState[ReadyState.Loading] = "Loading";
  80. ReadyState[ReadyState.Done] = "Done";
  81. ReadyState[ReadyState.Cancelled] = "Cancelled";
  82. /** @enum {number} */
  83. const ResponseType = {
  84. Basic: 0,
  85. Cors: 1,
  86. Default: 2,
  87. Error: 3,
  88. Opaque: 4,
  89. };
  90. ResponseType[ResponseType.Basic] = "Basic";
  91. ResponseType[ResponseType.Cors] = "Cors";
  92. ResponseType[ResponseType.Default] = "Default";
  93. ResponseType[ResponseType.Error] = "Error";
  94. ResponseType[ResponseType.Opaque] = "Opaque";
  95. /** @enum {number} */
  96. const ContentType = {
  97. NONE: 0,
  98. JSON: 1,
  99. FORM: 2,
  100. FORM_DATA: 3,
  101. TEXT: 4,
  102. BLOB: 5,
  103. ARRAY_BUFFER: 6,
  104. };
  105. ContentType[ContentType.NONE] = "NONE";
  106. ContentType[ContentType.JSON] = "JSON";
  107. ContentType[ContentType.FORM] = "FORM";
  108. ContentType[ContentType.FORM_DATA] = "FORM_DATA";
  109. ContentType[ContentType.TEXT] = "TEXT";
  110. ContentType[ContentType.BLOB] = "BLOB";
  111. ContentType[ContentType.ARRAY_BUFFER] = "ARRAY_BUFFER";
  112. /** @enum {number} */
  113. const ResponseContentType = {
  114. Text: 0,
  115. Json: 1,
  116. ArrayBuffer: 2,
  117. Blob: 3,
  118. };
  119. ResponseContentType[ResponseContentType.Text] = "Text";
  120. ResponseContentType[ResponseContentType.Json] = "Json";
  121. ResponseContentType[ResponseContentType.ArrayBuffer] = "ArrayBuffer";
  122. ResponseContentType[ResponseContentType.Blob] = "Blob";
  123. /**
  124. * @fileoverview added by tsickle
  125. * @suppress {checkTypes} checked by tsc
  126. */
  127. /**
  128. * @license
  129. * Copyright Google Inc. All Rights Reserved.
  130. *
  131. * Use of this source code is governed by an MIT-style license that can be
  132. * found in the LICENSE file at https://angular.io/license
  133. */
  134. /**
  135. * Polyfill for [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers), as
  136. * specified in the [Fetch Spec](https://fetch.spec.whatwg.org/#headers-class).
  137. *
  138. * The only known difference between this `Headers` implementation and the spec is the
  139. * lack of an `entries` method.
  140. *
  141. * ### Example
  142. *
  143. * ```
  144. * import {Headers} from '\@angular/http';
  145. *
  146. * var firstHeaders = new Headers();
  147. * firstHeaders.append('Content-Type', 'image/jpeg');
  148. * console.log(firstHeaders.get('Content-Type')) //'image/jpeg'
  149. *
  150. * // Create headers from Plain Old JavaScript Object
  151. * var secondHeaders = new Headers({
  152. * 'X-My-Custom-Header': 'Angular'
  153. * });
  154. * console.log(secondHeaders.get('X-My-Custom-Header')); //'Angular'
  155. *
  156. * var thirdHeaders = new Headers(secondHeaders);
  157. * console.log(thirdHeaders.get('X-My-Custom-Header')); //'Angular'
  158. * ```
  159. *
  160. * @deprecated use \@angular/common/http instead
  161. */
  162. class Headers {
  163. /**
  164. * @param {?=} headers
  165. */
  166. constructor(headers) {
  167. /**
  168. * \@internal header names are lower case
  169. */
  170. this._headers = new Map();
  171. /**
  172. * \@internal map lower case names to actual names
  173. */
  174. this._normalizedNames = new Map();
  175. if (!headers) {
  176. return;
  177. }
  178. if (headers instanceof Headers) {
  179. headers.forEach((values, name) => {
  180. values.forEach(value => this.append(name, value));
  181. });
  182. return;
  183. }
  184. Object.keys(headers).forEach((name) => {
  185. const /** @type {?} */ values = Array.isArray(headers[name]) ? headers[name] : [headers[name]];
  186. this.delete(name);
  187. values.forEach(value => this.append(name, value));
  188. });
  189. }
  190. /**
  191. * Returns a new Headers instance from the given DOMString of Response Headers
  192. * @param {?} headersString
  193. * @return {?}
  194. */
  195. static fromResponseHeaderString(headersString) {
  196. const /** @type {?} */ headers = new Headers();
  197. headersString.split('\n').forEach(line => {
  198. const /** @type {?} */ index = line.indexOf(':');
  199. if (index > 0) {
  200. const /** @type {?} */ name = line.slice(0, index);
  201. const /** @type {?} */ value = line.slice(index + 1).trim();
  202. headers.set(name, value);
  203. }
  204. });
  205. return headers;
  206. }
  207. /**
  208. * Appends a header to existing list of header values for a given header name.
  209. * @param {?} name
  210. * @param {?} value
  211. * @return {?}
  212. */
  213. append(name, value) {
  214. const /** @type {?} */ values = this.getAll(name);
  215. if (values === null) {
  216. this.set(name, value);
  217. }
  218. else {
  219. values.push(value);
  220. }
  221. }
  222. /**
  223. * Deletes all header values for the given name.
  224. * @param {?} name
  225. * @return {?}
  226. */
  227. delete(name) {
  228. const /** @type {?} */ lcName = name.toLowerCase();
  229. this._normalizedNames.delete(lcName);
  230. this._headers.delete(lcName);
  231. }
  232. /**
  233. * @param {?} fn
  234. * @return {?}
  235. */
  236. forEach(fn) {
  237. this._headers.forEach((values, lcName) => fn(values, this._normalizedNames.get(lcName), this._headers));
  238. }
  239. /**
  240. * Returns first header that matches given name.
  241. * @param {?} name
  242. * @return {?}
  243. */
  244. get(name) {
  245. const /** @type {?} */ values = this.getAll(name);
  246. if (values === null) {
  247. return null;
  248. }
  249. return values.length > 0 ? values[0] : null;
  250. }
  251. /**
  252. * Checks for existence of header by given name.
  253. * @param {?} name
  254. * @return {?}
  255. */
  256. has(name) { return this._headers.has(name.toLowerCase()); }
  257. /**
  258. * Returns the names of the headers
  259. * @return {?}
  260. */
  261. keys() { return Array.from(this._normalizedNames.values()); }
  262. /**
  263. * Sets or overrides header value for given name.
  264. * @param {?} name
  265. * @param {?} value
  266. * @return {?}
  267. */
  268. set(name, value) {
  269. if (Array.isArray(value)) {
  270. if (value.length) {
  271. this._headers.set(name.toLowerCase(), [value.join(',')]);
  272. }
  273. }
  274. else {
  275. this._headers.set(name.toLowerCase(), [value]);
  276. }
  277. this.mayBeSetNormalizedName(name);
  278. }
  279. /**
  280. * Returns values of all headers.
  281. * @return {?}
  282. */
  283. values() { return Array.from(this._headers.values()); }
  284. /**
  285. * Returns string of all headers.
  286. * @return {?}
  287. */
  288. toJSON() {
  289. const /** @type {?} */ serialized = {};
  290. this._headers.forEach((values, name) => {
  291. const /** @type {?} */ split = [];
  292. values.forEach(v => split.push(...v.split(',')));
  293. serialized[/** @type {?} */ ((this._normalizedNames.get(name)))] = split;
  294. });
  295. return serialized;
  296. }
  297. /**
  298. * Returns list of header values for a given name.
  299. * @param {?} name
  300. * @return {?}
  301. */
  302. getAll(name) {
  303. return this.has(name) ? this._headers.get(name.toLowerCase()) || null : null;
  304. }
  305. /**
  306. * This method is not implemented.
  307. * @return {?}
  308. */
  309. entries() { throw new Error('"entries" method is not implemented on Headers class'); }
  310. /**
  311. * @param {?} name
  312. * @return {?}
  313. */
  314. mayBeSetNormalizedName(name) {
  315. const /** @type {?} */ lcName = name.toLowerCase();
  316. if (!this._normalizedNames.has(lcName)) {
  317. this._normalizedNames.set(lcName, name);
  318. }
  319. }
  320. }
  321. /**
  322. * @fileoverview added by tsickle
  323. * @suppress {checkTypes} checked by tsc
  324. */
  325. /**
  326. * @license
  327. * Copyright Google Inc. All Rights Reserved.
  328. *
  329. * Use of this source code is governed by an MIT-style license that can be
  330. * found in the LICENSE file at https://angular.io/license
  331. */
  332. /**
  333. * Creates a response options object to be optionally provided when instantiating a
  334. * {\@link Response}.
  335. *
  336. * This class is based on the `ResponseInit` description in the [Fetch
  337. * Spec](https://fetch.spec.whatwg.org/#responseinit).
  338. *
  339. * All values are null by default. Typical defaults can be found in the
  340. * {\@link BaseResponseOptions} class, which sub-classes `ResponseOptions`.
  341. *
  342. * This class may be used in tests to build {\@link Response Responses} for
  343. * mock responses (see {\@link MockBackend}).
  344. *
  345. * ### Example ([live demo](http://plnkr.co/edit/P9Jkk8e8cz6NVzbcxEsD?p=preview))
  346. *
  347. * ```typescript
  348. * import {ResponseOptions, Response} from '\@angular/http';
  349. *
  350. * var options = new ResponseOptions({
  351. * body: '{"name":"Jeff"}'
  352. * });
  353. * var res = new Response(options);
  354. *
  355. * console.log('res.json():', res.json()); // Object {name: "Jeff"}
  356. * ```
  357. *
  358. * @deprecated use \@angular/common/http instead
  359. */
  360. class ResponseOptions {
  361. /**
  362. * @param {?=} opts
  363. */
  364. constructor(opts = {}) {
  365. const { body, status, headers, statusText, type, url } = opts;
  366. this.body = body != null ? body : null;
  367. this.status = status != null ? status : null;
  368. this.headers = headers != null ? headers : null;
  369. this.statusText = statusText != null ? statusText : null;
  370. this.type = type != null ? type : null;
  371. this.url = url != null ? url : null;
  372. }
  373. /**
  374. * Creates a copy of the `ResponseOptions` instance, using the optional input as values to
  375. * override
  376. * existing values. This method will not change the values of the instance on which it is being
  377. * called.
  378. *
  379. * This may be useful when sharing a base `ResponseOptions` object inside tests,
  380. * where certain properties may change from test to test.
  381. *
  382. * ### Example ([live demo](http://plnkr.co/edit/1lXquqFfgduTFBWjNoRE?p=preview))
  383. *
  384. * ```typescript
  385. * import {ResponseOptions, Response} from '\@angular/http';
  386. *
  387. * var options = new ResponseOptions({
  388. * body: {name: 'Jeff'}
  389. * });
  390. * var res = new Response(options.merge({
  391. * url: 'https://google.com'
  392. * }));
  393. * console.log('options.url:', options.url); // null
  394. * console.log('res.json():', res.json()); // Object {name: "Jeff"}
  395. * console.log('res.url:', res.url); // https://google.com
  396. * ```
  397. * @param {?=} options
  398. * @return {?}
  399. */
  400. merge(options) {
  401. return new ResponseOptions({
  402. body: options && options.body != null ? options.body : this.body,
  403. status: options && options.status != null ? options.status : this.status,
  404. headers: options && options.headers != null ? options.headers : this.headers,
  405. statusText: options && options.statusText != null ? options.statusText : this.statusText,
  406. type: options && options.type != null ? options.type : this.type,
  407. url: options && options.url != null ? options.url : this.url,
  408. });
  409. }
  410. }
  411. /**
  412. * Subclass of {\@link ResponseOptions}, with default values.
  413. *
  414. * Default values:
  415. * * status: 200
  416. * * headers: empty {\@link Headers} object
  417. *
  418. * This class could be extended and bound to the {\@link ResponseOptions} class
  419. * when configuring an {\@link Injector}, in order to override the default options
  420. * used by {\@link Http} to create {\@link Response Responses}.
  421. *
  422. * ### Example ([live demo](http://plnkr.co/edit/qv8DLT?p=preview))
  423. *
  424. * ```typescript
  425. * import {provide} from '\@angular/core';
  426. * import {bootstrap} from '\@angular/platform-browser/browser';
  427. * import {HTTP_PROVIDERS, Headers, Http, BaseResponseOptions, ResponseOptions} from
  428. * '\@angular/http';
  429. * import {App} from './myapp';
  430. *
  431. * class MyOptions extends BaseResponseOptions {
  432. * headers:Headers = new Headers({network: 'github'});
  433. * }
  434. *
  435. * bootstrap(App, [HTTP_PROVIDERS, {provide: ResponseOptions, useClass: MyOptions}]);
  436. * ```
  437. *
  438. * The options could also be extended when manually creating a {\@link Response}
  439. * object.
  440. *
  441. * ### Example ([live demo](http://plnkr.co/edit/VngosOWiaExEtbstDoix?p=preview))
  442. *
  443. * ```
  444. * import {BaseResponseOptions, Response} from '\@angular/http';
  445. *
  446. * var options = new BaseResponseOptions();
  447. * var res = new Response(options.merge({
  448. * body: 'Angular',
  449. * headers: new Headers({framework: 'angular'})
  450. * }));
  451. * console.log('res.headers.get("framework"):', res.headers.get('framework')); // angular
  452. * console.log('res.text():', res.text()); // Angular;
  453. * ```
  454. *
  455. * @deprecated use \@angular/common/http instead
  456. */
  457. class BaseResponseOptions extends ResponseOptions {
  458. constructor() {
  459. super({ status: 200, statusText: 'Ok', type: ResponseType.Default, headers: new Headers() });
  460. }
  461. }
  462. BaseResponseOptions.decorators = [
  463. { type: Injectable },
  464. ];
  465. /** @nocollapse */
  466. BaseResponseOptions.ctorParameters = () => [];
  467. /**
  468. * @fileoverview added by tsickle
  469. * @suppress {checkTypes} checked by tsc
  470. */
  471. /**
  472. * @license
  473. * Copyright Google Inc. All Rights Reserved.
  474. *
  475. * Use of this source code is governed by an MIT-style license that can be
  476. * found in the LICENSE file at https://angular.io/license
  477. */
  478. /**
  479. * Abstract class from which real backends are derived.
  480. *
  481. * The primary purpose of a `ConnectionBackend` is to create new connections to fulfill a given
  482. * {\@link Request}.
  483. *
  484. * @deprecated use \@angular/common/http instead
  485. * @abstract
  486. */
  487. class ConnectionBackend {
  488. }
  489. /**
  490. * Abstract class from which real connections are derived.
  491. *
  492. * @deprecated use \@angular/common/http instead
  493. * @abstract
  494. */
  495. class Connection {
  496. }
  497. /**
  498. * An XSRFStrategy configures XSRF protection (e.g. via headers) on an HTTP request.
  499. *
  500. * @deprecated use \@angular/common/http instead
  501. * @abstract
  502. */
  503. class XSRFStrategy {
  504. }
  505. /**
  506. * Interface for options to construct a RequestOptions, based on
  507. * [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
  508. *
  509. * @deprecated use \@angular/common/http instead
  510. * @record
  511. */
  512. /**
  513. * Required structure when constructing new Request();
  514. * @record
  515. */
  516. /**
  517. * Interface for options to construct a Response, based on
  518. * [ResponseInit](https://fetch.spec.whatwg.org/#responseinit) from the Fetch spec.
  519. *
  520. * @deprecated use \@angular/common/http instead
  521. * @record
  522. */
  523. /**
  524. * @fileoverview added by tsickle
  525. * @suppress {checkTypes} checked by tsc
  526. */
  527. /**
  528. * @license
  529. * Copyright Google Inc. All Rights Reserved.
  530. *
  531. * Use of this source code is governed by an MIT-style license that can be
  532. * found in the LICENSE file at https://angular.io/license
  533. */
  534. /**
  535. * @param {?} method
  536. * @return {?}
  537. */
  538. function normalizeMethodName(method) {
  539. if (typeof method !== 'string')
  540. return method;
  541. switch (method.toUpperCase()) {
  542. case 'GET':
  543. return RequestMethod.Get;
  544. case 'POST':
  545. return RequestMethod.Post;
  546. case 'PUT':
  547. return RequestMethod.Put;
  548. case 'DELETE':
  549. return RequestMethod.Delete;
  550. case 'OPTIONS':
  551. return RequestMethod.Options;
  552. case 'HEAD':
  553. return RequestMethod.Head;
  554. case 'PATCH':
  555. return RequestMethod.Patch;
  556. }
  557. throw new Error(`Invalid request method. The method "${method}" is not supported.`);
  558. }
  559. const isSuccess = (status) => (status >= 200 && status < 300);
  560. /**
  561. * @param {?} xhr
  562. * @return {?}
  563. */
  564. function getResponseURL(xhr) {
  565. if ('responseURL' in xhr) {
  566. return xhr.responseURL;
  567. }
  568. if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
  569. return xhr.getResponseHeader('X-Request-URL');
  570. }
  571. return null;
  572. }
  573. /**
  574. * @param {?} input
  575. * @return {?}
  576. */
  577. /**
  578. * @param {?} input
  579. * @return {?}
  580. */
  581. function stringToArrayBuffer(input) {
  582. const /** @type {?} */ view = new Uint16Array(input.length);
  583. for (let /** @type {?} */ i = 0, /** @type {?} */ strLen = input.length; i < strLen; i++) {
  584. view[i] = input.charCodeAt(i);
  585. }
  586. return view.buffer;
  587. }
  588. /**
  589. * @fileoverview added by tsickle
  590. * @suppress {checkTypes} checked by tsc
  591. */
  592. /**
  593. * @license
  594. * Copyright Google Inc. All Rights Reserved.
  595. *
  596. * Use of this source code is governed by an MIT-style license that can be
  597. * found in the LICENSE file at https://angular.io/license
  598. */
  599. /**
  600. * @param {?=} rawParams
  601. * @return {?}
  602. */
  603. function paramParser(rawParams = '') {
  604. const /** @type {?} */ map = new Map();
  605. if (rawParams.length > 0) {
  606. const /** @type {?} */ params = rawParams.split('&');
  607. params.forEach((param) => {
  608. const /** @type {?} */ eqIdx = param.indexOf('=');
  609. const [key, val] = eqIdx == -1 ? [param, ''] : [param.slice(0, eqIdx), param.slice(eqIdx + 1)];
  610. const /** @type {?} */ list = map.get(key) || [];
  611. list.push(val);
  612. map.set(key, list);
  613. });
  614. }
  615. return map;
  616. }
  617. /**
  618. * @deprecated use \@angular/common/http instead
  619. *
  620. */
  621. class QueryEncoder {
  622. /**
  623. * @param {?} k
  624. * @return {?}
  625. */
  626. encodeKey(k) { return standardEncoding(k); }
  627. /**
  628. * @param {?} v
  629. * @return {?}
  630. */
  631. encodeValue(v) { return standardEncoding(v); }
  632. }
  633. /**
  634. * @param {?} v
  635. * @return {?}
  636. */
  637. function standardEncoding(v) {
  638. return encodeURIComponent(v)
  639. .replace(/%40/gi, '@')
  640. .replace(/%3A/gi, ':')
  641. .replace(/%24/gi, '$')
  642. .replace(/%2C/gi, ',')
  643. .replace(/%3B/gi, ';')
  644. .replace(/%2B/gi, '+')
  645. .replace(/%3D/gi, '=')
  646. .replace(/%3F/gi, '?')
  647. .replace(/%2F/gi, '/');
  648. }
  649. /**
  650. * Map-like representation of url search parameters, based on
  651. * [URLSearchParams](https://url.spec.whatwg.org/#urlsearchparams) in the url living standard,
  652. * with several extensions for merging URLSearchParams objects:
  653. * - setAll()
  654. * - appendAll()
  655. * - replaceAll()
  656. *
  657. * This class accepts an optional second parameter of ${\@link QueryEncoder},
  658. * which is used to serialize parameters before making a request. By default,
  659. * `QueryEncoder` encodes keys and values of parameters using `encodeURIComponent`,
  660. * and then un-encodes certain characters that are allowed to be part of the query
  661. * according to IETF RFC 3986: https://tools.ietf.org/html/rfc3986.
  662. *
  663. * These are the characters that are not encoded: `! $ \' ( ) * + , ; A 9 - . _ ~ ? /`
  664. *
  665. * If the set of allowed query characters is not acceptable for a particular backend,
  666. * `QueryEncoder` can be subclassed and provided as the 2nd argument to URLSearchParams.
  667. *
  668. * ```
  669. * import {URLSearchParams, QueryEncoder} from '\@angular/http';
  670. * class MyQueryEncoder extends QueryEncoder {
  671. * encodeKey(k: string): string {
  672. * return myEncodingFunction(k);
  673. * }
  674. *
  675. * encodeValue(v: string): string {
  676. * return myEncodingFunction(v);
  677. * }
  678. * }
  679. *
  680. * let params = new URLSearchParams('', new MyQueryEncoder());
  681. * ```
  682. * @deprecated use \@angular/common/http instead
  683. */
  684. class URLSearchParams {
  685. /**
  686. * @param {?=} rawParams
  687. * @param {?=} queryEncoder
  688. */
  689. constructor(rawParams = '', queryEncoder = new QueryEncoder()) {
  690. this.rawParams = rawParams;
  691. this.queryEncoder = queryEncoder;
  692. this.paramsMap = paramParser(rawParams);
  693. }
  694. /**
  695. * @return {?}
  696. */
  697. clone() {
  698. const /** @type {?} */ clone = new URLSearchParams('', this.queryEncoder);
  699. clone.appendAll(this);
  700. return clone;
  701. }
  702. /**
  703. * @param {?} param
  704. * @return {?}
  705. */
  706. has(param) { return this.paramsMap.has(param); }
  707. /**
  708. * @param {?} param
  709. * @return {?}
  710. */
  711. get(param) {
  712. const /** @type {?} */ storedParam = this.paramsMap.get(param);
  713. return Array.isArray(storedParam) ? storedParam[0] : null;
  714. }
  715. /**
  716. * @param {?} param
  717. * @return {?}
  718. */
  719. getAll(param) { return this.paramsMap.get(param) || []; }
  720. /**
  721. * @param {?} param
  722. * @param {?} val
  723. * @return {?}
  724. */
  725. set(param, val) {
  726. if (val === void 0 || val === null) {
  727. this.delete(param);
  728. return;
  729. }
  730. const /** @type {?} */ list = this.paramsMap.get(param) || [];
  731. list.length = 0;
  732. list.push(val);
  733. this.paramsMap.set(param, list);
  734. }
  735. /**
  736. * @param {?} searchParams
  737. * @return {?}
  738. */
  739. setAll(searchParams) {
  740. searchParams.paramsMap.forEach((value, param) => {
  741. const /** @type {?} */ list = this.paramsMap.get(param) || [];
  742. list.length = 0;
  743. list.push(value[0]);
  744. this.paramsMap.set(param, list);
  745. });
  746. }
  747. /**
  748. * @param {?} param
  749. * @param {?} val
  750. * @return {?}
  751. */
  752. append(param, val) {
  753. if (val === void 0 || val === null)
  754. return;
  755. const /** @type {?} */ list = this.paramsMap.get(param) || [];
  756. list.push(val);
  757. this.paramsMap.set(param, list);
  758. }
  759. /**
  760. * @param {?} searchParams
  761. * @return {?}
  762. */
  763. appendAll(searchParams) {
  764. searchParams.paramsMap.forEach((value, param) => {
  765. const /** @type {?} */ list = this.paramsMap.get(param) || [];
  766. for (let /** @type {?} */ i = 0; i < value.length; ++i) {
  767. list.push(value[i]);
  768. }
  769. this.paramsMap.set(param, list);
  770. });
  771. }
  772. /**
  773. * @param {?} searchParams
  774. * @return {?}
  775. */
  776. replaceAll(searchParams) {
  777. searchParams.paramsMap.forEach((value, param) => {
  778. const /** @type {?} */ list = this.paramsMap.get(param) || [];
  779. list.length = 0;
  780. for (let /** @type {?} */ i = 0; i < value.length; ++i) {
  781. list.push(value[i]);
  782. }
  783. this.paramsMap.set(param, list);
  784. });
  785. }
  786. /**
  787. * @return {?}
  788. */
  789. toString() {
  790. const /** @type {?} */ paramsList = [];
  791. this.paramsMap.forEach((values, k) => {
  792. values.forEach(v => paramsList.push(this.queryEncoder.encodeKey(k) + '=' + this.queryEncoder.encodeValue(v)));
  793. });
  794. return paramsList.join('&');
  795. }
  796. /**
  797. * @param {?} param
  798. * @return {?}
  799. */
  800. delete(param) { this.paramsMap.delete(param); }
  801. }
  802. /**
  803. * @fileoverview added by tsickle
  804. * @suppress {checkTypes} checked by tsc
  805. */
  806. /**
  807. * @license
  808. * Copyright Google Inc. All Rights Reserved.
  809. *
  810. * Use of this source code is governed by an MIT-style license that can be
  811. * found in the LICENSE file at https://angular.io/license
  812. */
  813. /**
  814. * HTTP request body used by both {\@link Request} and {\@link Response}
  815. * https://fetch.spec.whatwg.org/#body
  816. * @abstract
  817. */
  818. class Body {
  819. /**
  820. * Attempts to return body as parsed `JSON` object, or raises an exception.
  821. * @return {?}
  822. */
  823. json() {
  824. if (typeof this._body === 'string') {
  825. return JSON.parse(/** @type {?} */ (this._body));
  826. }
  827. if (this._body instanceof ArrayBuffer) {
  828. return JSON.parse(this.text());
  829. }
  830. return this._body;
  831. }
  832. /**
  833. * Returns the body as a string, presuming `toString()` can be called on the response body.
  834. *
  835. * When decoding an `ArrayBuffer`, the optional `encodingHint` parameter determines how the
  836. * bytes in the buffer will be interpreted. Valid values are:
  837. *
  838. * - `legacy` - incorrectly interpret the bytes as UTF-16 (technically, UCS-2). Only characters
  839. * in the Basic Multilingual Plane are supported, surrogate pairs are not handled correctly.
  840. * In addition, the endianness of the 16-bit octet pairs in the `ArrayBuffer` is not taken
  841. * into consideration. This is the default behavior to avoid breaking apps, but should be
  842. * considered deprecated.
  843. *
  844. * - `iso-8859` - interpret the bytes as ISO-8859 (which can be used for ASCII encoded text).
  845. * @param {?=} encodingHint
  846. * @return {?}
  847. */
  848. text(encodingHint = 'legacy') {
  849. if (this._body instanceof URLSearchParams) {
  850. return this._body.toString();
  851. }
  852. if (this._body instanceof ArrayBuffer) {
  853. switch (encodingHint) {
  854. case 'legacy':
  855. return String.fromCharCode.apply(null, new Uint16Array(/** @type {?} */ (this._body)));
  856. case 'iso-8859':
  857. return String.fromCharCode.apply(null, new Uint8Array(/** @type {?} */ (this._body)));
  858. default:
  859. throw new Error(`Invalid value for encodingHint: ${encodingHint}`);
  860. }
  861. }
  862. if (this._body == null) {
  863. return '';
  864. }
  865. if (typeof this._body === 'object') {
  866. return JSON.stringify(this._body, null, 2);
  867. }
  868. return this._body.toString();
  869. }
  870. /**
  871. * Return the body as an ArrayBuffer
  872. * @return {?}
  873. */
  874. arrayBuffer() {
  875. if (this._body instanceof ArrayBuffer) {
  876. return /** @type {?} */ (this._body);
  877. }
  878. return stringToArrayBuffer(this.text());
  879. }
  880. /**
  881. * Returns the request's body as a Blob, assuming that body exists.
  882. * @return {?}
  883. */
  884. blob() {
  885. if (this._body instanceof Blob) {
  886. return /** @type {?} */ (this._body);
  887. }
  888. if (this._body instanceof ArrayBuffer) {
  889. return new Blob([this._body]);
  890. }
  891. throw new Error('The request body isn\'t either a blob or an array buffer');
  892. }
  893. }
  894. /**
  895. * @fileoverview added by tsickle
  896. * @suppress {checkTypes} checked by tsc
  897. */
  898. /**
  899. * @license
  900. * Copyright Google Inc. All Rights Reserved.
  901. *
  902. * Use of this source code is governed by an MIT-style license that can be
  903. * found in the LICENSE file at https://angular.io/license
  904. */
  905. /**
  906. * Creates `Response` instances from provided values.
  907. *
  908. * Though this object isn't
  909. * usually instantiated by end-users, it is the primary object interacted with when it comes time to
  910. * add data to a view.
  911. *
  912. * ### Example
  913. *
  914. * ```
  915. * http.request('my-friends.txt').subscribe(response => this.friends = response.text());
  916. * ```
  917. *
  918. * The Response's interface is inspired by the Response constructor defined in the [Fetch
  919. * Spec](https://fetch.spec.whatwg.org/#response-class), but is considered a static value whose body
  920. * can be accessed many times. There are other differences in the implementation, but this is the
  921. * most significant.
  922. *
  923. * @deprecated use \@angular/common/http instead
  924. */
  925. class Response extends Body {
  926. /**
  927. * @param {?} responseOptions
  928. */
  929. constructor(responseOptions) {
  930. super();
  931. this._body = responseOptions.body;
  932. this.status = /** @type {?} */ ((responseOptions.status));
  933. this.ok = (this.status >= 200 && this.status <= 299);
  934. this.statusText = responseOptions.statusText;
  935. this.headers = responseOptions.headers;
  936. this.type = /** @type {?} */ ((responseOptions.type));
  937. this.url = /** @type {?} */ ((responseOptions.url));
  938. }
  939. /**
  940. * @return {?}
  941. */
  942. toString() {
  943. return `Response with status: ${this.status} ${this.statusText} for URL: ${this.url}`;
  944. }
  945. }
  946. /**
  947. * @fileoverview added by tsickle
  948. * @suppress {checkTypes} checked by tsc
  949. */
  950. /**
  951. * @license
  952. * Copyright Google Inc. All Rights Reserved.
  953. *
  954. * Use of this source code is governed by an MIT-style license that can be
  955. * found in the LICENSE file at https://angular.io/license
  956. */
  957. let _nextRequestId = 0;
  958. const JSONP_HOME = '__ng_jsonp__';
  959. let _jsonpConnections = null;
  960. /**
  961. * @return {?}
  962. */
  963. function _getJsonpConnections() {
  964. const /** @type {?} */ w = typeof window == 'object' ? window : {};
  965. if (_jsonpConnections === null) {
  966. _jsonpConnections = w[JSONP_HOME] = {};
  967. }
  968. return _jsonpConnections;
  969. }
  970. class BrowserJsonp {
  971. /**
  972. * @param {?} url
  973. * @return {?}
  974. */
  975. build(url) {
  976. const /** @type {?} */ node = document.createElement('script');
  977. node.src = url;
  978. return node;
  979. }
  980. /**
  981. * @return {?}
  982. */
  983. nextRequestID() { return `__req${_nextRequestId++}`; }
  984. /**
  985. * @param {?} id
  986. * @return {?}
  987. */
  988. requestCallback(id) { return `${JSONP_HOME}.${id}.finished`; }
  989. /**
  990. * @param {?} id
  991. * @param {?} connection
  992. * @return {?}
  993. */
  994. exposeConnection(id, connection) {
  995. const /** @type {?} */ connections = _getJsonpConnections();
  996. connections[id] = connection;
  997. }
  998. /**
  999. * @param {?} id
  1000. * @return {?}
  1001. */
  1002. removeConnection(id) {
  1003. const /** @type {?} */ connections = _getJsonpConnections();
  1004. connections[id] = null;
  1005. }
  1006. /**
  1007. * @param {?} node
  1008. * @return {?}
  1009. */
  1010. send(node) { document.body.appendChild(/** @type {?} */ ((node))); }
  1011. /**
  1012. * @param {?} node
  1013. * @return {?}
  1014. */
  1015. cleanup(node) {
  1016. if (node.parentNode) {
  1017. node.parentNode.removeChild(/** @type {?} */ ((node)));
  1018. }
  1019. }
  1020. }
  1021. BrowserJsonp.decorators = [
  1022. { type: Injectable },
  1023. ];
  1024. /** @nocollapse */
  1025. BrowserJsonp.ctorParameters = () => [];
  1026. /**
  1027. * @fileoverview added by tsickle
  1028. * @suppress {checkTypes} checked by tsc
  1029. */
  1030. /**
  1031. * @license
  1032. * Copyright Google Inc. All Rights Reserved.
  1033. *
  1034. * Use of this source code is governed by an MIT-style license that can be
  1035. * found in the LICENSE file at https://angular.io/license
  1036. */
  1037. const JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
  1038. const JSONP_ERR_WRONG_METHOD = 'JSONP requests must use GET request method.';
  1039. /**
  1040. * Base class for an in-flight JSONP request.
  1041. *
  1042. * @deprecated use \@angular/common/http instead
  1043. */
  1044. class JSONPConnection {
  1045. /**
  1046. * \@internal
  1047. * @param {?} req
  1048. * @param {?} _dom
  1049. * @param {?=} baseResponseOptions
  1050. */
  1051. constructor(req, _dom, baseResponseOptions) {
  1052. this._dom = _dom;
  1053. this.baseResponseOptions = baseResponseOptions;
  1054. this._finished = false;
  1055. if (req.method !== RequestMethod.Get) {
  1056. throw new TypeError(JSONP_ERR_WRONG_METHOD);
  1057. }
  1058. this.request = req;
  1059. this.response = new Observable((responseObserver) => {
  1060. this.readyState = ReadyState.Loading;
  1061. const /** @type {?} */ id = this._id = _dom.nextRequestID();
  1062. _dom.exposeConnection(id, this);
  1063. // Workaround Dart
  1064. // url = url.replace(/=JSONP_CALLBACK(&|$)/, `generated method`);
  1065. const /** @type {?} */ callback = _dom.requestCallback(this._id);
  1066. let /** @type {?} */ url = req.url;
  1067. if (url.indexOf('=JSONP_CALLBACK&') > -1) {
  1068. url = url.replace('=JSONP_CALLBACK&', `=${callback}&`);
  1069. }
  1070. else if (url.lastIndexOf('=JSONP_CALLBACK') === url.length - '=JSONP_CALLBACK'.length) {
  1071. url = url.substring(0, url.length - '=JSONP_CALLBACK'.length) + `=${callback}`;
  1072. }
  1073. const /** @type {?} */ script = this._script = _dom.build(url);
  1074. const /** @type {?} */ onLoad = (event) => {
  1075. if (this.readyState === ReadyState.Cancelled)
  1076. return;
  1077. this.readyState = ReadyState.Done;
  1078. _dom.cleanup(script);
  1079. if (!this._finished) {
  1080. let /** @type {?} */ responseOptions = new ResponseOptions({ body: JSONP_ERR_NO_CALLBACK, type: ResponseType.Error, url });
  1081. if (baseResponseOptions) {
  1082. responseOptions = baseResponseOptions.merge(responseOptions);
  1083. }
  1084. responseObserver.error(new Response(responseOptions));
  1085. return;
  1086. }
  1087. let /** @type {?} */ responseOptions = new ResponseOptions({ body: this._responseData, url });
  1088. if (this.baseResponseOptions) {
  1089. responseOptions = this.baseResponseOptions.merge(responseOptions);
  1090. }
  1091. responseObserver.next(new Response(responseOptions));
  1092. responseObserver.complete();
  1093. };
  1094. const /** @type {?} */ onError = (error) => {
  1095. if (this.readyState === ReadyState.Cancelled)
  1096. return;
  1097. this.readyState = ReadyState.Done;
  1098. _dom.cleanup(script);
  1099. let /** @type {?} */ responseOptions = new ResponseOptions({ body: error.message, type: ResponseType.Error });
  1100. if (baseResponseOptions) {
  1101. responseOptions = baseResponseOptions.merge(responseOptions);
  1102. }
  1103. responseObserver.error(new Response(responseOptions));
  1104. };
  1105. script.addEventListener('load', onLoad);
  1106. script.addEventListener('error', onError);
  1107. _dom.send(script);
  1108. return () => {
  1109. this.readyState = ReadyState.Cancelled;
  1110. script.removeEventListener('load', onLoad);
  1111. script.removeEventListener('error', onError);
  1112. this._dom.cleanup(script);
  1113. };
  1114. });
  1115. }
  1116. /**
  1117. * Callback called when the JSONP request completes, to notify the application
  1118. * of the new data.
  1119. * @param {?=} data
  1120. * @return {?}
  1121. */
  1122. finished(data) {
  1123. // Don't leak connections
  1124. this._finished = true;
  1125. this._dom.removeConnection(this._id);
  1126. if (this.readyState === ReadyState.Cancelled)
  1127. return;
  1128. this._responseData = data;
  1129. }
  1130. }
  1131. /**
  1132. * A {\@link ConnectionBackend} that uses the JSONP strategy of making requests.
  1133. *
  1134. * @deprecated use \@angular/common/http instead
  1135. */
  1136. class JSONPBackend extends ConnectionBackend {
  1137. /**
  1138. * \@internal
  1139. * @param {?} _browserJSONP
  1140. * @param {?} _baseResponseOptions
  1141. */
  1142. constructor(_browserJSONP, _baseResponseOptions) {
  1143. super();
  1144. this._browserJSONP = _browserJSONP;
  1145. this._baseResponseOptions = _baseResponseOptions;
  1146. }
  1147. /**
  1148. * @param {?} request
  1149. * @return {?}
  1150. */
  1151. createConnection(request) {
  1152. return new JSONPConnection(request, this._browserJSONP, this._baseResponseOptions);
  1153. }
  1154. }
  1155. JSONPBackend.decorators = [
  1156. { type: Injectable },
  1157. ];
  1158. /** @nocollapse */
  1159. JSONPBackend.ctorParameters = () => [
  1160. { type: BrowserJsonp, },
  1161. { type: ResponseOptions, },
  1162. ];
  1163. /**
  1164. * @fileoverview added by tsickle
  1165. * @suppress {checkTypes} checked by tsc
  1166. */
  1167. /**
  1168. * @license
  1169. * Copyright Google Inc. All Rights Reserved.
  1170. *
  1171. * Use of this source code is governed by an MIT-style license that can be
  1172. * found in the LICENSE file at https://angular.io/license
  1173. */
  1174. const XSSI_PREFIX = /^\)\]\}',?\n/;
  1175. /**
  1176. * Creates connections using `XMLHttpRequest`. Given a fully-qualified
  1177. * request, an `XHRConnection` will immediately create an `XMLHttpRequest` object and send the
  1178. * request.
  1179. *
  1180. * This class would typically not be created or interacted with directly inside applications, though
  1181. * the {\@link MockConnection} may be interacted with in tests.
  1182. *
  1183. * @deprecated use \@angular/common/http instead
  1184. */
  1185. class XHRConnection {
  1186. /**
  1187. * @param {?} req
  1188. * @param {?} browserXHR
  1189. * @param {?=} baseResponseOptions
  1190. */
  1191. constructor(req, browserXHR, baseResponseOptions) {
  1192. this.request = req;
  1193. this.response = new Observable((responseObserver) => {
  1194. const /** @type {?} */ _xhr = browserXHR.build();
  1195. _xhr.open(RequestMethod[req.method].toUpperCase(), req.url);
  1196. if (req.withCredentials != null) {
  1197. _xhr.withCredentials = req.withCredentials;
  1198. }
  1199. // load event handler
  1200. const /** @type {?} */ onLoad = () => {
  1201. // normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
  1202. let /** @type {?} */ status = _xhr.status === 1223 ? 204 : _xhr.status;
  1203. let /** @type {?} */ body = null;
  1204. // HTTP 204 means no content
  1205. if (status !== 204) {
  1206. // responseText is the old-school way of retrieving response (supported by IE8 & 9)
  1207. // response/responseType properties were introduced in ResourceLoader Level2 spec
  1208. // (supported by IE10)
  1209. body = (typeof _xhr.response === 'undefined') ? _xhr.responseText : _xhr.response;
  1210. // Implicitly strip a potential XSSI prefix.
  1211. if (typeof body === 'string') {
  1212. body = body.replace(XSSI_PREFIX, '');
  1213. }
  1214. }
  1215. // fix status code when it is 0 (0 status is undocumented).
  1216. // Occurs when accessing file resources or on Android 4.1 stock browser
  1217. // while retrieving files from application cache.
  1218. if (status === 0) {
  1219. status = body ? 200 : 0;
  1220. }
  1221. const /** @type {?} */ headers = Headers.fromResponseHeaderString(_xhr.getAllResponseHeaders());
  1222. // IE 9 does not provide the way to get URL of response
  1223. const /** @type {?} */ url = getResponseURL(_xhr) || req.url;
  1224. const /** @type {?} */ statusText = _xhr.statusText || 'OK';
  1225. let /** @type {?} */ responseOptions = new ResponseOptions({ body, status, headers, statusText, url });
  1226. if (baseResponseOptions != null) {
  1227. responseOptions = baseResponseOptions.merge(responseOptions);
  1228. }
  1229. const /** @type {?} */ response = new Response(responseOptions);
  1230. response.ok = isSuccess(status);
  1231. if (response.ok) {
  1232. responseObserver.next(response);
  1233. // TODO(gdi2290): defer complete if array buffer until done
  1234. responseObserver.complete();
  1235. return;
  1236. }
  1237. responseObserver.error(response);
  1238. };
  1239. // error event handler
  1240. const /** @type {?} */ onError = (err) => {
  1241. let /** @type {?} */ responseOptions = new ResponseOptions({
  1242. body: err,
  1243. type: ResponseType.Error,
  1244. status: _xhr.status,
  1245. statusText: _xhr.statusText,
  1246. });
  1247. if (baseResponseOptions != null) {
  1248. responseOptions = baseResponseOptions.merge(responseOptions);
  1249. }
  1250. responseObserver.error(new Response(responseOptions));
  1251. };
  1252. this.setDetectedContentType(req, _xhr);
  1253. if (req.headers == null) {
  1254. req.headers = new Headers();
  1255. }
  1256. if (!req.headers.has('Accept')) {
  1257. req.headers.append('Accept', 'application/json, text/plain, */*');
  1258. }
  1259. req.headers.forEach((values, name) => _xhr.setRequestHeader(/** @type {?} */ ((name)), values.join(',')));
  1260. // Select the correct buffer type to store the response
  1261. if (req.responseType != null && _xhr.responseType != null) {
  1262. switch (req.responseType) {
  1263. case ResponseContentType.ArrayBuffer:
  1264. _xhr.responseType = 'arraybuffer';
  1265. break;
  1266. case ResponseContentType.Json:
  1267. _xhr.responseType = 'json';
  1268. break;
  1269. case ResponseContentType.Text:
  1270. _xhr.responseType = 'text';
  1271. break;
  1272. case ResponseContentType.Blob:
  1273. _xhr.responseType = 'blob';
  1274. break;
  1275. default:
  1276. throw new Error('The selected responseType is not supported');
  1277. }
  1278. }
  1279. _xhr.addEventListener('load', onLoad);
  1280. _xhr.addEventListener('error', onError);
  1281. _xhr.send(this.request.getBody());
  1282. return () => {
  1283. _xhr.removeEventListener('load', onLoad);
  1284. _xhr.removeEventListener('error', onError);
  1285. _xhr.abort();
  1286. };
  1287. });
  1288. }
  1289. /**
  1290. * @param {?} req
  1291. * @param {?} _xhr
  1292. * @return {?}
  1293. */
  1294. setDetectedContentType(req /** TODO Request */, _xhr /** XMLHttpRequest */) {
  1295. // Skip if a custom Content-Type header is provided
  1296. if (req.headers != null && req.headers.get('Content-Type') != null) {
  1297. return;
  1298. }
  1299. // Set the detected content type
  1300. switch (req.contentType) {
  1301. case ContentType.NONE:
  1302. break;
  1303. case ContentType.JSON:
  1304. _xhr.setRequestHeader('content-type', 'application/json');
  1305. break;
  1306. case ContentType.FORM:
  1307. _xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
  1308. break;
  1309. case ContentType.TEXT:
  1310. _xhr.setRequestHeader('content-type', 'text/plain');
  1311. break;
  1312. case ContentType.BLOB:
  1313. const /** @type {?} */ blob = req.blob();
  1314. if (blob.type) {
  1315. _xhr.setRequestHeader('content-type', blob.type);
  1316. }
  1317. break;
  1318. }
  1319. }
  1320. }
  1321. /**
  1322. * `XSRFConfiguration` sets up Cross Site Request Forgery (XSRF) protection for the application
  1323. * using a cookie. See https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)
  1324. * for more information on XSRF.
  1325. *
  1326. * Applications can configure custom cookie and header names by binding an instance of this class
  1327. * with different `cookieName` and `headerName` values. See the main HTTP documentation for more
  1328. * details.
  1329. *
  1330. * @deprecated use \@angular/common/http instead
  1331. */
  1332. class CookieXSRFStrategy {
  1333. /**
  1334. * @param {?=} _cookieName
  1335. * @param {?=} _headerName
  1336. */
  1337. constructor(_cookieName = 'XSRF-TOKEN', _headerName = 'X-XSRF-TOKEN') {
  1338. this._cookieName = _cookieName;
  1339. this._headerName = _headerName;
  1340. }
  1341. /**
  1342. * @param {?} req
  1343. * @return {?}
  1344. */
  1345. configureRequest(req) {
  1346. const /** @type {?} */ xsrfToken = ɵgetDOM().getCookie(this._cookieName);
  1347. if (xsrfToken) {
  1348. req.headers.set(this._headerName, xsrfToken);
  1349. }
  1350. }
  1351. }
  1352. /**
  1353. * Creates {\@link XHRConnection} instances.
  1354. *
  1355. * This class would typically not be used by end users, but could be
  1356. * overridden if a different backend implementation should be used,
  1357. * such as in a node backend.
  1358. *
  1359. * ### Example
  1360. *
  1361. * ```
  1362. * import {Http, MyNodeBackend, HTTP_PROVIDERS, BaseRequestOptions} from '\@angular/http';
  1363. * \@Component({
  1364. * viewProviders: [
  1365. * HTTP_PROVIDERS,
  1366. * {provide: Http, useFactory: (backend, options) => {
  1367. * return new Http(backend, options);
  1368. * }, deps: [MyNodeBackend, BaseRequestOptions]}]
  1369. * })
  1370. * class MyComponent {
  1371. * constructor(http:Http) {
  1372. * http.request('people.json').subscribe(res => this.people = res.json());
  1373. * }
  1374. * }
  1375. * ```
  1376. * @deprecated use \@angular/common/http instead
  1377. */
  1378. class XHRBackend {
  1379. /**
  1380. * @param {?} _browserXHR
  1381. * @param {?} _baseResponseOptions
  1382. * @param {?} _xsrfStrategy
  1383. */
  1384. constructor(_browserXHR, _baseResponseOptions, _xsrfStrategy) {
  1385. this._browserXHR = _browserXHR;
  1386. this._baseResponseOptions = _baseResponseOptions;
  1387. this._xsrfStrategy = _xsrfStrategy;
  1388. }
  1389. /**
  1390. * @param {?} request
  1391. * @return {?}
  1392. */
  1393. createConnection(request) {
  1394. this._xsrfStrategy.configureRequest(request);
  1395. return new XHRConnection(request, this._browserXHR, this._baseResponseOptions);
  1396. }
  1397. }
  1398. XHRBackend.decorators = [
  1399. { type: Injectable },
  1400. ];
  1401. /** @nocollapse */
  1402. XHRBackend.ctorParameters = () => [
  1403. { type: BrowserXhr, },
  1404. { type: ResponseOptions, },
  1405. { type: XSRFStrategy, },
  1406. ];
  1407. /**
  1408. * @fileoverview added by tsickle
  1409. * @suppress {checkTypes} checked by tsc
  1410. */
  1411. /**
  1412. * @license
  1413. * Copyright Google Inc. All Rights Reserved.
  1414. *
  1415. * Use of this source code is governed by an MIT-style license that can be
  1416. * found in the LICENSE file at https://angular.io/license
  1417. */
  1418. /**
  1419. * Creates a request options object to be optionally provided when instantiating a
  1420. * {\@link Request}.
  1421. *
  1422. * This class is based on the `RequestInit` description in the [Fetch
  1423. * Spec](https://fetch.spec.whatwg.org/#requestinit).
  1424. *
  1425. * All values are null by default. Typical defaults can be found in the {\@link BaseRequestOptions}
  1426. * class, which sub-classes `RequestOptions`.
  1427. *
  1428. * ```typescript
  1429. * import {RequestOptions, Request, RequestMethod} from '\@angular/http';
  1430. *
  1431. * const options = new RequestOptions({
  1432. * method: RequestMethod.Post,
  1433. * url: 'https://google.com'
  1434. * });
  1435. * const req = new Request(options);
  1436. * console.log('req.method:', RequestMethod[req.method]); // Post
  1437. * console.log('options.url:', options.url); // https://google.com
  1438. * ```
  1439. *
  1440. * @deprecated use \@angular/common/http instead
  1441. */
  1442. class RequestOptions {
  1443. /**
  1444. * @deprecated from 4.0.0. Use params instead.
  1445. * @return {?}
  1446. */
  1447. get search() { return this.params; }
  1448. /**
  1449. * @deprecated from 4.0.0. Use params instead.
  1450. * @param {?} params
  1451. * @return {?}
  1452. */
  1453. set search(params) { this.params = params; }
  1454. /**
  1455. * @param {?=} opts
  1456. */
  1457. constructor(opts = {}) {
  1458. const { method, headers, body, url, search, params, withCredentials, responseType } = opts;
  1459. this.method = method != null ? normalizeMethodName(method) : null;
  1460. this.headers = headers != null ? headers : null;
  1461. this.body = body != null ? body : null;
  1462. this.url = url != null ? url : null;
  1463. this.params = this._mergeSearchParams(params || search);
  1464. this.withCredentials = withCredentials != null ? withCredentials : null;
  1465. this.responseType = responseType != null ? responseType : null;
  1466. }
  1467. /**
  1468. * Creates a copy of the `RequestOptions` instance, using the optional input as values to override
  1469. * existing values. This method will not change the values of the instance on which it is being
  1470. * called.
  1471. *
  1472. * Note that `headers` and `search` will override existing values completely if present in
  1473. * the `options` object. If these values should be merged, it should be done prior to calling
  1474. * `merge` on the `RequestOptions` instance.
  1475. *
  1476. * ```typescript
  1477. * import {RequestOptions, Request, RequestMethod} from '\@angular/http';
  1478. *
  1479. * const options = new RequestOptions({
  1480. * method: RequestMethod.Post
  1481. * });
  1482. * const req = new Request(options.merge({
  1483. * url: 'https://google.com'
  1484. * }));
  1485. * console.log('req.method:', RequestMethod[req.method]); // Post
  1486. * console.log('options.url:', options.url); // null
  1487. * console.log('req.url:', req.url); // https://google.com
  1488. * ```
  1489. * @param {?=} options
  1490. * @return {?}
  1491. */
  1492. merge(options) {
  1493. return new RequestOptions({
  1494. method: options && options.method != null ? options.method : this.method,
  1495. headers: options && options.headers != null ? options.headers : new Headers(this.headers),
  1496. body: options && options.body != null ? options.body : this.body,
  1497. url: options && options.url != null ? options.url : this.url,
  1498. params: options && this._mergeSearchParams(options.params || options.search),
  1499. withCredentials: options && options.withCredentials != null ? options.withCredentials :
  1500. this.withCredentials,
  1501. responseType: options && options.responseType != null ? options.responseType :
  1502. this.responseType
  1503. });
  1504. }
  1505. /**
  1506. * @param {?=} params
  1507. * @return {?}
  1508. */
  1509. _mergeSearchParams(params) {
  1510. if (!params)
  1511. return this.params;
  1512. if (params instanceof URLSearchParams) {
  1513. return params.clone();
  1514. }
  1515. if (typeof params === 'string') {
  1516. return new URLSearchParams(params);
  1517. }
  1518. return this._parseParams(params);
  1519. }
  1520. /**
  1521. * @param {?=} objParams
  1522. * @return {?}
  1523. */
  1524. _parseParams(objParams = {}) {
  1525. const /** @type {?} */ params = new URLSearchParams();
  1526. Object.keys(objParams).forEach((key) => {
  1527. const /** @type {?} */ value = objParams[key];
  1528. if (Array.isArray(value)) {
  1529. value.forEach((item) => this._appendParam(key, item, params));
  1530. }
  1531. else {
  1532. this._appendParam(key, value, params);
  1533. }
  1534. });
  1535. return params;
  1536. }
  1537. /**
  1538. * @param {?} key
  1539. * @param {?} value
  1540. * @param {?} params
  1541. * @return {?}
  1542. */
  1543. _appendParam(key, value, params) {
  1544. if (typeof value !== 'string') {
  1545. value = JSON.stringify(value);
  1546. }
  1547. params.append(key, value);
  1548. }
  1549. }
  1550. /**
  1551. * Subclass of {\@link RequestOptions}, with default values.
  1552. *
  1553. * Default values:
  1554. * * method: {\@link RequestMethod RequestMethod.Get}
  1555. * * headers: empty {\@link Headers} object
  1556. *
  1557. * This class could be extended and bound to the {\@link RequestOptions} class
  1558. * when configuring an {\@link Injector}, in order to override the default options
  1559. * used by {\@link Http} to create and send {\@link Request Requests}.
  1560. *
  1561. * ```typescript
  1562. * import {BaseRequestOptions, RequestOptions} from '\@angular/http';
  1563. *
  1564. * class MyOptions extends BaseRequestOptions {
  1565. * search: string = 'coreTeam=true';
  1566. * }
  1567. *
  1568. * {provide: RequestOptions, useClass: MyOptions};
  1569. * ```
  1570. *
  1571. * The options could also be extended when manually creating a {\@link Request}
  1572. * object.
  1573. *
  1574. * ```
  1575. * import {BaseRequestOptions, Request, RequestMethod} from '\@angular/http';
  1576. *
  1577. * const options = new BaseRequestOptions();
  1578. * const req = new Request(options.merge({
  1579. * method: RequestMethod.Post,
  1580. * url: 'https://google.com'
  1581. * }));
  1582. * console.log('req.method:', RequestMethod[req.method]); // Post
  1583. * console.log('options.url:', options.url); // null
  1584. * console.log('req.url:', req.url); // https://google.com
  1585. * ```
  1586. *
  1587. * @deprecated use \@angular/common/http instead
  1588. */
  1589. class BaseRequestOptions extends RequestOptions {
  1590. constructor() { super({ method: RequestMethod.Get, headers: new Headers() }); }
  1591. }
  1592. BaseRequestOptions.decorators = [
  1593. { type: Injectable },
  1594. ];
  1595. /** @nocollapse */
  1596. BaseRequestOptions.ctorParameters = () => [];
  1597. /**
  1598. * @fileoverview added by tsickle
  1599. * @suppress {checkTypes} checked by tsc
  1600. */
  1601. /**
  1602. * @license
  1603. * Copyright Google Inc. All Rights Reserved.
  1604. *
  1605. * Use of this source code is governed by an MIT-style license that can be
  1606. * found in the LICENSE file at https://angular.io/license
  1607. */
  1608. /**
  1609. * Creates `Request` instances from provided values.
  1610. *
  1611. * The Request's interface is inspired by the Request constructor defined in the [Fetch
  1612. * Spec](https://fetch.spec.whatwg.org/#request-class),
  1613. * but is considered a static value whose body can be accessed many times. There are other
  1614. * differences in the implementation, but this is the most significant.
  1615. *
  1616. * `Request` instances are typically created by higher-level classes, like {\@link Http} and
  1617. * {\@link Jsonp}, but it may occasionally be useful to explicitly create `Request` instances.
  1618. * One such example is when creating services that wrap higher-level services, like {\@link Http},
  1619. * where it may be useful to generate a `Request` with arbitrary headers and search params.
  1620. *
  1621. * ```typescript
  1622. * import {Injectable, Injector} from '\@angular/core';
  1623. * import {HTTP_PROVIDERS, Http, Request, RequestMethod} from '\@angular/http';
  1624. *
  1625. * \@Injectable()
  1626. * class AutoAuthenticator {
  1627. * constructor(public http:Http) {}
  1628. * request(url:string) {
  1629. * return this.http.request(new Request({
  1630. * method: RequestMethod.Get,
  1631. * url: url,
  1632. * search: 'password=123'
  1633. * }));
  1634. * }
  1635. * }
  1636. *
  1637. * var injector = Injector.resolveAndCreate([HTTP_PROVIDERS, AutoAuthenticator]);
  1638. * var authenticator = injector.get(AutoAuthenticator);
  1639. * authenticator.request('people.json').subscribe(res => {
  1640. * //URL should have included '?password=123'
  1641. * console.log('people', res.json());
  1642. * });
  1643. * ```
  1644. *
  1645. * @deprecated use \@angular/common/http instead
  1646. */
  1647. class Request extends Body {
  1648. /**
  1649. * @param {?} requestOptions
  1650. */
  1651. constructor(requestOptions) {
  1652. super();
  1653. // TODO: assert that url is present
  1654. const /** @type {?} */ url = requestOptions.url;
  1655. this.url = /** @type {?} */ ((requestOptions.url));
  1656. const /** @type {?} */ paramsArg = requestOptions.params || requestOptions.search;
  1657. if (paramsArg) {
  1658. let /** @type {?} */ params;
  1659. if (typeof paramsArg === 'object' && !(paramsArg instanceof URLSearchParams)) {
  1660. params = urlEncodeParams(paramsArg).toString();
  1661. }
  1662. else {
  1663. params = paramsArg.toString();
  1664. }
  1665. if (params.length > 0) {
  1666. let /** @type {?} */ prefix = '?';
  1667. if (this.url.indexOf('?') != -1) {
  1668. prefix = (this.url[this.url.length - 1] == '&') ? '' : '&';
  1669. }
  1670. // TODO: just delete search-query-looking string in url?
  1671. this.url = url + prefix + params;
  1672. }
  1673. }
  1674. this._body = requestOptions.body;
  1675. this.method = normalizeMethodName(/** @type {?} */ ((requestOptions.method)));
  1676. // TODO(jeffbcross): implement behavior
  1677. // Defaults to 'omit', consistent with browser
  1678. this.headers = new Headers(requestOptions.headers);
  1679. this.contentType = this.detectContentType();
  1680. this.withCredentials = /** @type {?} */ ((requestOptions.withCredentials));
  1681. this.responseType = /** @type {?} */ ((requestOptions.responseType));
  1682. }
  1683. /**
  1684. * Returns the content type enum based on header options.
  1685. * @return {?}
  1686. */
  1687. detectContentType() {
  1688. switch (this.headers.get('content-type')) {
  1689. case 'application/json':
  1690. return ContentType.JSON;
  1691. case 'application/x-www-form-urlencoded':
  1692. return ContentType.FORM;
  1693. case 'multipart/form-data':
  1694. return ContentType.FORM_DATA;
  1695. case 'text/plain':
  1696. case 'text/html':
  1697. return ContentType.TEXT;
  1698. case 'application/octet-stream':
  1699. return this._body instanceof ArrayBuffer$1 ? ContentType.ARRAY_BUFFER : ContentType.BLOB;
  1700. default:
  1701. return this.detectContentTypeFromBody();
  1702. }
  1703. }
  1704. /**
  1705. * Returns the content type of request's body based on its type.
  1706. * @return {?}
  1707. */
  1708. detectContentTypeFromBody() {
  1709. if (this._body == null) {
  1710. return ContentType.NONE;
  1711. }
  1712. else if (this._body instanceof URLSearchParams) {
  1713. return ContentType.FORM;
  1714. }
  1715. else if (this._body instanceof FormData) {
  1716. return ContentType.FORM_DATA;
  1717. }
  1718. else if (this._body instanceof Blob$1) {
  1719. return ContentType.BLOB;
  1720. }
  1721. else if (this._body instanceof ArrayBuffer$1) {
  1722. return ContentType.ARRAY_BUFFER;
  1723. }
  1724. else if (this._body && typeof this._body === 'object') {
  1725. return ContentType.JSON;
  1726. }
  1727. else {
  1728. return ContentType.TEXT;
  1729. }
  1730. }
  1731. /**
  1732. * Returns the request's body according to its type. If body is undefined, return
  1733. * null.
  1734. * @return {?}
  1735. */
  1736. getBody() {
  1737. switch (this.contentType) {
  1738. case ContentType.JSON:
  1739. return this.text();
  1740. case ContentType.FORM:
  1741. return this.text();
  1742. case ContentType.FORM_DATA:
  1743. return this._body;
  1744. case ContentType.TEXT:
  1745. return this.text();
  1746. case ContentType.BLOB:
  1747. return this.blob();
  1748. case ContentType.ARRAY_BUFFER:
  1749. return this.arrayBuffer();
  1750. default:
  1751. return null;
  1752. }
  1753. }
  1754. }
  1755. /**
  1756. * @param {?} params
  1757. * @return {?}
  1758. */
  1759. function urlEncodeParams(params) {
  1760. const /** @type {?} */ searchParams = new URLSearchParams();
  1761. Object.keys(params).forEach(key => {
  1762. const /** @type {?} */ value = params[key];
  1763. if (value && Array.isArray(value)) {
  1764. value.forEach(element => searchParams.append(key, element.toString()));
  1765. }
  1766. else {
  1767. searchParams.append(key, value.toString());
  1768. }
  1769. });
  1770. return searchParams;
  1771. }
  1772. const noop = function () { };
  1773. const w = typeof window == 'object' ? window : noop;
  1774. const FormData = (/** @type {?} */ (w /** TODO #9100 */) /** TODO #9100 */)['FormData'] || noop;
  1775. const Blob$1 = (/** @type {?} */ (w /** TODO #9100 */) /** TODO #9100 */)['Blob'] || noop;
  1776. const ArrayBuffer$1 = (/** @type {?} */ (w /** TODO #9100 */) /** TODO #9100 */)['ArrayBuffer'] || noop;
  1777. /**
  1778. * @fileoverview added by tsickle
  1779. * @suppress {checkTypes} checked by tsc
  1780. */
  1781. /**
  1782. * @license
  1783. * Copyright Google Inc. All Rights Reserved.
  1784. *
  1785. * Use of this source code is governed by an MIT-style license that can be
  1786. * found in the LICENSE file at https://angular.io/license
  1787. */
  1788. /**
  1789. * @param {?} backend
  1790. * @param {?} request
  1791. * @return {?}
  1792. */
  1793. function httpRequest(backend, request) {
  1794. return backend.createConnection(request).response;
  1795. }
  1796. /**
  1797. * @param {?} defaultOpts
  1798. * @param {?} providedOpts
  1799. * @param {?} method
  1800. * @param {?} url
  1801. * @return {?}
  1802. */
  1803. function mergeOptions(defaultOpts, providedOpts, method, url) {
  1804. const /** @type {?} */ newOptions = defaultOpts;
  1805. if (providedOpts) {
  1806. // Hack so Dart can used named parameters
  1807. return /** @type {?} */ (newOptions.merge(new RequestOptions({
  1808. method: providedOpts.method || method,
  1809. url: providedOpts.url || url,
  1810. search: providedOpts.search,
  1811. params: providedOpts.params,
  1812. headers: providedOpts.headers,
  1813. body: providedOpts.body,
  1814. withCredentials: providedOpts.withCredentials,
  1815. responseType: providedOpts.responseType
  1816. })));
  1817. }
  1818. return /** @type {?} */ (newOptions.merge(new RequestOptions({ method, url })));
  1819. }
  1820. /**
  1821. * Performs http requests using `XMLHttpRequest` as the default backend.
  1822. *
  1823. * `Http` is available as an injectable class, with methods to perform http requests. Calling
  1824. * `request` returns an `Observable` which will emit a single {\@link Response} when a
  1825. * response is received.
  1826. *
  1827. * ### Example
  1828. *
  1829. * ```typescript
  1830. * import {Http, HTTP_PROVIDERS} from '\@angular/http';
  1831. * import 'rxjs/add/operator/map'
  1832. * \@Component({
  1833. * selector: 'http-app',
  1834. * viewProviders: [HTTP_PROVIDERS],
  1835. * templateUrl: 'people.html'
  1836. * })
  1837. * class PeopleComponent {
  1838. * constructor(http: Http) {
  1839. * http.get('people.json')
  1840. * // Call map on the response observable to get the parsed people object
  1841. * .map(res => res.json())
  1842. * // Subscribe to the observable to get the parsed people object and attach it to the
  1843. * // component
  1844. * .subscribe(people => this.people = people);
  1845. * }
  1846. * }
  1847. * ```
  1848. *
  1849. *
  1850. * ### Example
  1851. *
  1852. * ```
  1853. * http.get('people.json').subscribe((res:Response) => this.people = res.json());
  1854. * ```
  1855. *
  1856. * The default construct used to perform requests, `XMLHttpRequest`, is abstracted as a "Backend" (
  1857. * {\@link XHRBackend} in this case), which could be mocked with dependency injection by replacing
  1858. * the {\@link XHRBackend} provider, as in the following example:
  1859. *
  1860. * ### Example
  1861. *
  1862. * ```typescript
  1863. * import {BaseRequestOptions, Http} from '\@angular/http';
  1864. * import {MockBackend} from '\@angular/http/testing';
  1865. * var injector = Injector.resolveAndCreate([
  1866. * BaseRequestOptions,
  1867. * MockBackend,
  1868. * {provide: Http, useFactory:
  1869. * function(backend, defaultOptions) {
  1870. * return new Http(backend, defaultOptions);
  1871. * },
  1872. * deps: [MockBackend, BaseRequestOptions]}
  1873. * ]);
  1874. * var http = injector.get(Http);
  1875. * http.get('request-from-mock-backend.json').subscribe((res:Response) => doSomething(res));
  1876. * ```
  1877. *
  1878. * @deprecated use \@angular/common/http instead
  1879. */
  1880. class Http {
  1881. /**
  1882. * @param {?} _backend
  1883. * @param {?} _defaultOptions
  1884. */
  1885. constructor(_backend, _defaultOptions) {
  1886. this._backend = _backend;
  1887. this._defaultOptions = _defaultOptions;
  1888. }
  1889. /**
  1890. * Performs any type of http request. First argument is required, and can either be a url or
  1891. * a {\@link Request} instance. If the first argument is a url, an optional {\@link RequestOptions}
  1892. * object can be provided as the 2nd argument. The options object will be merged with the values
  1893. * of {\@link BaseRequestOptions} before performing the request.
  1894. * @param {?} url
  1895. * @param {?=} options
  1896. * @return {?}
  1897. */
  1898. request(url, options) {
  1899. let /** @type {?} */ responseObservable;
  1900. if (typeof url === 'string') {
  1901. responseObservable = httpRequest(this._backend, new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, /** @type {?} */ (url))));
  1902. }
  1903. else if (url instanceof Request) {
  1904. responseObservable = httpRequest(this._backend, url);
  1905. }
  1906. else {
  1907. throw new Error('First argument must be a url string or Request instance.');
  1908. }
  1909. return responseObservable;
  1910. }
  1911. /**
  1912. * Performs a request with `get` http method.
  1913. * @param {?} url
  1914. * @param {?=} options
  1915. * @return {?}
  1916. */
  1917. get(url, options) {
  1918. return this.request(new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, url)));
  1919. }
  1920. /**
  1921. * Performs a request with `post` http method.
  1922. * @param {?} url
  1923. * @param {?} body
  1924. * @param {?=} options
  1925. * @return {?}
  1926. */
  1927. post(url, body, options) {
  1928. return this.request(new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({ body: body })), options, RequestMethod.Post, url)));
  1929. }
  1930. /**
  1931. * Performs a request with `put` http method.
  1932. * @param {?} url
  1933. * @param {?} body
  1934. * @param {?=} options
  1935. * @return {?}
  1936. */
  1937. put(url, body, options) {
  1938. return this.request(new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({ body: body })), options, RequestMethod.Put, url)));
  1939. }
  1940. /**
  1941. * Performs a request with `delete` http method.
  1942. * @param {?} url
  1943. * @param {?=} options
  1944. * @return {?}
  1945. */
  1946. delete(url, options) {
  1947. return this.request(new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Delete, url)));
  1948. }
  1949. /**
  1950. * Performs a request with `patch` http method.
  1951. * @param {?} url
  1952. * @param {?} body
  1953. * @param {?=} options
  1954. * @return {?}
  1955. */
  1956. patch(url, body, options) {
  1957. return this.request(new Request(mergeOptions(this._defaultOptions.merge(new RequestOptions({ body: body })), options, RequestMethod.Patch, url)));
  1958. }
  1959. /**
  1960. * Performs a request with `head` http method.
  1961. * @param {?} url
  1962. * @param {?=} options
  1963. * @return {?}
  1964. */
  1965. head(url, options) {
  1966. return this.request(new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Head, url)));
  1967. }
  1968. /**
  1969. * Performs a request with `options` http method.
  1970. * @param {?} url
  1971. * @param {?=} options
  1972. * @return {?}
  1973. */
  1974. options(url, options) {
  1975. return this.request(new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Options, url)));
  1976. }
  1977. }
  1978. Http.decorators = [
  1979. { type: Injectable },
  1980. ];
  1981. /** @nocollapse */
  1982. Http.ctorParameters = () => [
  1983. { type: ConnectionBackend, },
  1984. { type: RequestOptions, },
  1985. ];
  1986. /**
  1987. * @deprecated use \@angular/common/http instead
  1988. */
  1989. class Jsonp extends Http {
  1990. /**
  1991. * @param {?} backend
  1992. * @param {?} defaultOptions
  1993. */
  1994. constructor(backend, defaultOptions) {
  1995. super(backend, defaultOptions);
  1996. }
  1997. /**
  1998. * Performs any type of http request. First argument is required, and can either be a url or
  1999. * a {\@link Request} instance. If the first argument is a url, an optional {\@link RequestOptions}
  2000. * object can be provided as the 2nd argument. The options object will be merged with the values
  2001. * of {\@link BaseRequestOptions} before performing the request.
  2002. *
  2003. * \@security Regular XHR is the safest alternative to JSONP for most applications, and is
  2004. * supported by all current browsers. Because JSONP creates a `<script>` element with
  2005. * contents retrieved from a remote source, attacker-controlled data introduced by an untrusted
  2006. * source could expose your application to XSS risks. Data exposed by JSONP may also be
  2007. * readable by malicious third-party websites. In addition, JSONP introduces potential risk for
  2008. * future security issues (e.g. content sniffing). For more detail, see the
  2009. * [Security Guide](http://g.co/ng/security).
  2010. * @param {?} url
  2011. * @param {?=} options
  2012. * @return {?}
  2013. */
  2014. request(url, options) {
  2015. let /** @type {?} */ responseObservable;
  2016. if (typeof url === 'string') {
  2017. url =
  2018. new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, /** @type {?} */ (url)));
  2019. }
  2020. if (url instanceof Request) {
  2021. if (url.method !== RequestMethod.Get) {
  2022. throw new Error('JSONP requests must use GET request method.');
  2023. }
  2024. responseObservable = httpRequest(this._backend, url);
  2025. }
  2026. else {
  2027. throw new Error('First argument must be a url string or Request instance.');
  2028. }
  2029. return responseObservable;
  2030. }
  2031. }
  2032. Jsonp.decorators = [
  2033. { type: Injectable },
  2034. ];
  2035. /** @nocollapse */
  2036. Jsonp.ctorParameters = () => [
  2037. { type: ConnectionBackend, },
  2038. { type: RequestOptions, },
  2039. ];
  2040. /**
  2041. * @fileoverview added by tsickle
  2042. * @suppress {checkTypes} checked by tsc
  2043. */
  2044. /**
  2045. * @license
  2046. * Copyright Google Inc. All Rights Reserved.
  2047. *
  2048. * Use of this source code is governed by an MIT-style license that can be
  2049. * found in the LICENSE file at https://angular.io/license
  2050. */
  2051. /**
  2052. * @return {?}
  2053. */
  2054. function _createDefaultCookieXSRFStrategy() {
  2055. return new CookieXSRFStrategy();
  2056. }
  2057. /**
  2058. * @param {?} xhrBackend
  2059. * @param {?} requestOptions
  2060. * @return {?}
  2061. */
  2062. function httpFactory(xhrBackend, requestOptions) {
  2063. return new Http(xhrBackend, requestOptions);
  2064. }
  2065. /**
  2066. * @param {?} jsonpBackend
  2067. * @param {?} requestOptions
  2068. * @return {?}
  2069. */
  2070. function jsonpFactory(jsonpBackend, requestOptions) {
  2071. return new Jsonp(jsonpBackend, requestOptions);
  2072. }
  2073. /**
  2074. * The module that includes http's providers
  2075. *
  2076. * @deprecated use \@angular/common/http instead
  2077. */
  2078. class HttpModule {
  2079. }
  2080. HttpModule.decorators = [
  2081. { type: NgModule, args: [{
  2082. providers: [
  2083. // TODO(pascal): use factory type annotations once supported in DI
  2084. // issue: https://github.com/angular/angular/issues/3183
  2085. { provide: Http, useFactory: httpFactory, deps: [XHRBackend, RequestOptions] },
  2086. BrowserXhr,
  2087. { provide: RequestOptions, useClass: BaseRequestOptions },
  2088. { provide: ResponseOptions, useClass: BaseResponseOptions },
  2089. XHRBackend,
  2090. { provide: XSRFStrategy, useFactory: _createDefaultCookieXSRFStrategy },
  2091. ],
  2092. },] },
  2093. ];
  2094. /** @nocollapse */
  2095. HttpModule.ctorParameters = () => [];
  2096. /**
  2097. * The module that includes jsonp's providers
  2098. *
  2099. * @deprecated use \@angular/common/http instead
  2100. */
  2101. class JsonpModule {
  2102. }
  2103. JsonpModule.decorators = [
  2104. { type: NgModule, args: [{
  2105. providers: [
  2106. // TODO(pascal): use factory type annotations once supported in DI
  2107. // issue: https://github.com/angular/angular/issues/3183
  2108. { provide: Jsonp, useFactory: jsonpFactory, deps: [JSONPBackend, RequestOptions] },
  2109. BrowserJsonp,
  2110. { provide: RequestOptions, useClass: BaseRequestOptions },
  2111. { provide: ResponseOptions, useClass: BaseResponseOptions },
  2112. JSONPBackend,
  2113. ],
  2114. },] },
  2115. ];
  2116. /** @nocollapse */
  2117. JsonpModule.ctorParameters = () => [];
  2118. /**
  2119. * @fileoverview added by tsickle
  2120. * @suppress {checkTypes} checked by tsc
  2121. */
  2122. /**
  2123. * @license
  2124. * Copyright Google Inc. All Rights Reserved.
  2125. *
  2126. * Use of this source code is governed by an MIT-style license that can be
  2127. * found in the LICENSE file at https://angular.io/license
  2128. */
  2129. /**
  2130. * @deprecated use \@angular/common/http instead
  2131. */
  2132. const VERSION = new Version('5.2.11');
  2133. /**
  2134. * @fileoverview added by tsickle
  2135. * @suppress {checkTypes} checked by tsc
  2136. */
  2137. /**
  2138. * @license
  2139. * Copyright Google Inc. All Rights Reserved.
  2140. *
  2141. * Use of this source code is governed by an MIT-style license that can be
  2142. * found in the LICENSE file at https://angular.io/license
  2143. */
  2144. /**
  2145. * @fileoverview added by tsickle
  2146. * @suppress {checkTypes} checked by tsc
  2147. */
  2148. /**
  2149. * @license
  2150. * Copyright Google Inc. All Rights Reserved.
  2151. *
  2152. * Use of this source code is governed by an MIT-style license that can be
  2153. * found in the LICENSE file at https://angular.io/license
  2154. */
  2155. /**
  2156. * @module
  2157. * @description
  2158. * Entry point for all public APIs of this package.
  2159. */
  2160. // This file only reexports content of the `src` folder. Keep it that way.
  2161. /**
  2162. * @fileoverview added by tsickle
  2163. * @suppress {checkTypes} checked by tsc
  2164. */
  2165. /**
  2166. * Generated bundle index. Do not edit.
  2167. */
  2168. export { BrowserXhr, JSONPBackend, JSONPConnection, CookieXSRFStrategy, XHRBackend, XHRConnection, BaseRequestOptions, RequestOptions, BaseResponseOptions, ResponseOptions, ReadyState, RequestMethod, ResponseContentType, ResponseType, Headers, Http, Jsonp, HttpModule, JsonpModule, Connection, ConnectionBackend, XSRFStrategy, Request, Response, QueryEncoder, URLSearchParams, VERSION, BrowserJsonp as ɵe, Body as ɵf, _createDefaultCookieXSRFStrategy as ɵa, httpFactory as ɵb, jsonpFactory as ɵc };
  2169. //# sourceMappingURL=http.js.map