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