Project

General

Profile

1
/**
2
 * @license Angular v4.4.6
3
 * (c) 2010-2017 Google, Inc. https://angular.io/
4
 * License: MIT
5
 */
6
import { Inject, Injectable, InjectionToken, NgModule, Optional, PLATFORM_ID } from '@angular/core';
7
import { of } from 'rxjs/observable/of';
8
import { concatMap } from 'rxjs/operator/concatMap';
9
import { filter } from 'rxjs/operator/filter';
10
import { map } from 'rxjs/operator/map';
11
import { DOCUMENT, ɵparseCookieValue } from '@angular/common';
12
import { Observable } from 'rxjs/Observable';
13

    
14
/**
15
 * @license
16
 * Copyright Google Inc. All Rights Reserved.
17
 *
18
 * Use of this source code is governed by an MIT-style license that can be
19
 * found in the LICENSE file at https://angular.io/license
20
 */
21
/**
22
 * Transforms an `HttpRequest` into a stream of `HttpEvent`s, one of which will likely be a
23
 * `HttpResponse`.
24
 *
25
 * `HttpHandler` is injectable. When injected, the handler instance dispatches requests to the
26
 * first interceptor in the chain, which dispatches to the second, etc, eventually reaching the
27
 * `HttpBackend`.
28
 *
29
 * In an `HttpInterceptor`, the `HttpHandler` parameter is the next interceptor in the chain.
30
 *
31
 * \@experimental
32
 * @abstract
33
 */
34
class HttpHandler {
35
    /**
36
     * @abstract
37
     * @param {?} req
38
     * @return {?}
39
     */
40
    handle(req) { }
41
}
42
/**
43
 * A final `HttpHandler` which will dispatch the request via browser HTTP APIs to a backend.
44
 *
45
 * Interceptors sit between the `HttpClient` interface and the `HttpBackend`.
46
 *
47
 * When injected, `HttpBackend` dispatches requests directly to the backend, without going
48
 * through the interceptor chain.
49
 *
50
 * \@experimental
51
 * @abstract
52
 */
53
class HttpBackend {
54
    /**
55
     * @abstract
56
     * @param {?} req
57
     * @return {?}
58
     */
59
    handle(req) { }
60
}
61

    
62
/**
63
 * @license
64
 * Copyright Google Inc. All Rights Reserved.
65
 *
66
 * Use of this source code is governed by an MIT-style license that can be
67
 * found in the LICENSE file at https://angular.io/license
68
 */
69
/**
70
 * A `HttpParameterCodec` that uses `encodeURIComponent` and `decodeURIComponent` to
71
 * serialize and parse URL parameter keys and values.
72
 *
73
 * \@experimental
74
 */
75
class HttpUrlEncodingCodec {
76
    /**
77
     * @param {?} k
78
     * @return {?}
79
     */
80
    encodeKey(k) { return standardEncoding(k); }
81
    /**
82
     * @param {?} v
83
     * @return {?}
84
     */
85
    encodeValue(v) { return standardEncoding(v); }
86
    /**
87
     * @param {?} k
88
     * @return {?}
89
     */
90
    decodeKey(k) { return decodeURIComponent(k); }
91
    /**
92
     * @param {?} v
93
     * @return {?}
94
     */
95
    decodeValue(v) { return decodeURIComponent(v); }
96
}
97
/**
98
 * @param {?} rawParams
99
 * @param {?} codec
100
 * @return {?}
101
 */
102
function paramParser(rawParams, codec) {
103
    const /** @type {?} */ map$$1 = new Map();
104
    if (rawParams.length > 0) {
105
        const /** @type {?} */ params = rawParams.split('&');
106
        params.forEach((param) => {
107
            const /** @type {?} */ eqIdx = param.indexOf('=');
108
            const [key, val] = eqIdx == -1 ?
109
                [codec.decodeKey(param), ''] :
110
                [codec.decodeKey(param.slice(0, eqIdx)), codec.decodeValue(param.slice(eqIdx + 1))];
111
            const /** @type {?} */ list = map$$1.get(key) || [];
112
            list.push(val);
113
            map$$1.set(key, list);
114
        });
115
    }
116
    return map$$1;
117
}
118
/**
119
 * @param {?} v
120
 * @return {?}
121
 */
122
function standardEncoding(v) {
123
    return encodeURIComponent(v)
124
        .replace(/%40/gi, '@')
125
        .replace(/%3A/gi, ':')
126
        .replace(/%24/gi, '$')
127
        .replace(/%2C/gi, ',')
128
        .replace(/%3B/gi, ';')
129
        .replace(/%2B/gi, '+')
130
        .replace(/%3D/gi, '=')
131
        .replace(/%3F/gi, '?')
132
        .replace(/%2F/gi, '/');
133
}
134
/**
135
 * An HTTP request/response body that represents serialized parameters,
136
 * per the MIME type `application/x-www-form-urlencoded`.
137
 *
138
 * This class is immuatable - all mutation operations return a new instance.
139
 *
140
 * \@experimental
141
 */
142
class HttpParams {
143
    /**
144
     * @param {?=} options
145
     */
146
    constructor(options = {}) {
147
        this.updates = null;
148
        this.cloneFrom = null;
149
        this.encoder = options.encoder || new HttpUrlEncodingCodec();
150
        this.map = !!options.fromString ? paramParser(options.fromString, this.encoder) : null;
151
    }
152
    /**
153
     * Check whether the body has one or more values for the given parameter name.
154
     * @param {?} param
155
     * @return {?}
156
     */
157
    has(param) {
158
        this.init();
159
        return ((this.map)).has(param);
160
    }
161
    /**
162
     * Get the first value for the given parameter name, or `null` if it's not present.
163
     * @param {?} param
164
     * @return {?}
165
     */
166
    get(param) {
167
        this.init();
168
        const /** @type {?} */ res = ((this.map)).get(param);
169
        return !!res ? res[0] : null;
170
    }
171
    /**
172
     * Get all values for the given parameter name, or `null` if it's not present.
173
     * @param {?} param
174
     * @return {?}
175
     */
176
    getAll(param) {
177
        this.init();
178
        return ((this.map)).get(param) || null;
179
    }
180
    /**
181
     * Get all the parameter names for this body.
182
     * @return {?}
183
     */
184
    keys() {
185
        this.init();
186
        return Array.from(/** @type {?} */ ((this.map)).keys());
187
    }
188
    /**
189
     * Construct a new body with an appended value for the given parameter name.
190
     * @param {?} param
191
     * @param {?} value
192
     * @return {?}
193
     */
194
    append(param, value) { return this.clone({ param, value, op: 'a' }); }
195
    /**
196
     * Construct a new body with a new value for the given parameter name.
197
     * @param {?} param
198
     * @param {?} value
199
     * @return {?}
200
     */
201
    set(param, value) { return this.clone({ param, value, op: 's' }); }
202
    /**
203
     * Construct a new body with either the given value for the given parameter
204
     * removed, if a value is given, or all values for the given parameter removed
205
     * if not.
206
     * @param {?} param
207
     * @param {?=} value
208
     * @return {?}
209
     */
210
    delete(param, value) { return this.clone({ param, value, op: 'd' }); }
211
    /**
212
     * Serialize the body to an encoded string, where key-value pairs (separated by `=`) are
213
     * separated by `&`s.
214
     * @return {?}
215
     */
216
    toString() {
217
        this.init();
218
        return this.keys()
219
            .map(key => {
220
            const /** @type {?} */ eKey = this.encoder.encodeKey(key);
221
            return ((((this.map)).get(key))).map(value => eKey + '=' + this.encoder.encodeValue(value))
222
                .join('&');
223
        })
224
            .join('&');
225
    }
226
    /**
227
     * @param {?} update
228
     * @return {?}
229
     */
230
    clone(update) {
231
        const /** @type {?} */ clone = new HttpParams({ encoder: this.encoder });
232
        clone.cloneFrom = this.cloneFrom || this;
233
        clone.updates = (this.updates || []).concat([update]);
234
        return clone;
235
    }
236
    /**
237
     * @return {?}
238
     */
239
    init() {
240
        if (this.map === null) {
241
            this.map = new Map();
242
        }
243
        if (this.cloneFrom !== null) {
244
            this.cloneFrom.init();
245
            this.cloneFrom.keys().forEach(key => ((this.map)).set(key, /** @type {?} */ ((((((this.cloneFrom)).map)).get(key))))); /** @type {?} */
246
            ((this.updates)).forEach(update => {
247
                switch (update.op) {
248
                    case 'a':
249
                    case 's':
250
                        const /** @type {?} */ base = (update.op === 'a' ? ((this.map)).get(update.param) : undefined) || [];
251
                        base.push(/** @type {?} */ ((update.value))); /** @type {?} */
252
                        ((this.map)).set(update.param, base);
253
                        break;
254
                    case 'd':
255
                        if (update.value !== undefined) {
256
                            let /** @type {?} */ base = ((this.map)).get(update.param) || [];
257
                            const /** @type {?} */ idx = base.indexOf(update.value);
258
                            if (idx !== -1) {
259
                                base.splice(idx, 1);
260
                            }
261
                            if (base.length > 0) {
262
                                ((this.map)).set(update.param, base);
263
                            }
264
                            else {
265
                                ((this.map)).delete(update.param);
266
                            }
267
                        }
268
                        else {
269
                            ((this.map)).delete(update.param);
270
                            break;
271
                        }
272
                }
273
            });
274
            this.cloneFrom = null;
275
        }
276
    }
277
}
278

    
279
/**
280
 * @license
281
 * Copyright Google Inc. All Rights Reserved.
282
 *
283
 * Use of this source code is governed by an MIT-style license that can be
284
 * found in the LICENSE file at https://angular.io/license
285
 */
286
/**
287
 * Immutable set of Http headers, with lazy parsing.
288
 * \@experimental
289
 */
290
class HttpHeaders {
291
    /**
292
     * @param {?=} headers
293
     */
294
    constructor(headers) {
295
        /**
296
         * Internal map of lowercased header names to the normalized
297
         * form of the name (the form seen first).
298
         */
299
        this.normalizedNames = new Map();
300
        /**
301
         * Queued updates to be materialized the next initialization.
302
         */
303
        this.lazyUpdate = null;
304
        if (!headers) {
305
            this.headers = new Map();
306
        }
307
        else if (typeof headers === 'string') {
308
            this.lazyInit = () => {
309
                this.headers = new Map();
310
                headers.split('\n').forEach(line => {
311
                    const index = line.indexOf(':');
312
                    if (index > 0) {
313
                        const name = line.slice(0, index);
314
                        const key = name.toLowerCase();
315
                        const value = line.slice(index + 1).trim();
316
                        this.maybeSetNormalizedName(name, key);
317
                        if (this.headers.has(key)) {
318
                            this.headers.get(key).push(value);
319
                        }
320
                        else {
321
                            this.headers.set(key, [value]);
322
                        }
323
                    }
324
                });
325
            };
326
        }
327
        else {
328
            this.lazyInit = () => {
329
                this.headers = new Map();
330
                Object.keys(headers).forEach(name => {
331
                    let values = headers[name];
332
                    const key = name.toLowerCase();
333
                    if (typeof values === 'string') {
334
                        values = [values];
335
                    }
336
                    if (values.length > 0) {
337
                        this.headers.set(key, values);
338
                        this.maybeSetNormalizedName(name, key);
339
                    }
340
                });
341
            };
342
        }
343
    }
344
    /**
345
     * Checks for existence of header by given name.
346
     * @param {?} name
347
     * @return {?}
348
     */
349
    has(name) {
350
        this.init();
351
        return this.headers.has(name.toLowerCase());
352
    }
353
    /**
354
     * Returns first header that matches given name.
355
     * @param {?} name
356
     * @return {?}
357
     */
358
    get(name) {
359
        this.init();
360
        const /** @type {?} */ values = this.headers.get(name.toLowerCase());
361
        return values && values.length > 0 ? values[0] : null;
362
    }
363
    /**
364
     * Returns the names of the headers
365
     * @return {?}
366
     */
367
    keys() {
368
        this.init();
369
        return Array.from(this.normalizedNames.values());
370
    }
371
    /**
372
     * Returns list of header values for a given name.
373
     * @param {?} name
374
     * @return {?}
375
     */
376
    getAll(name) {
377
        this.init();
378
        return this.headers.get(name.toLowerCase()) || null;
379
    }
380
    /**
381
     * @param {?} name
382
     * @param {?} value
383
     * @return {?}
384
     */
385
    append(name, value) {
386
        return this.clone({ name, value, op: 'a' });
387
    }
388
    /**
389
     * @param {?} name
390
     * @param {?} value
391
     * @return {?}
392
     */
393
    set(name, value) {
394
        return this.clone({ name, value, op: 's' });
395
    }
396
    /**
397
     * @param {?} name
398
     * @param {?=} value
399
     * @return {?}
400
     */
401
    delete(name, value) {
402
        return this.clone({ name, value, op: 'd' });
403
    }
404
    /**
405
     * @param {?} name
406
     * @param {?} lcName
407
     * @return {?}
408
     */
409
    maybeSetNormalizedName(name, lcName) {
410
        if (!this.normalizedNames.has(lcName)) {
411
            this.normalizedNames.set(lcName, name);
412
        }
413
    }
414
    /**
415
     * @return {?}
416
     */
417
    init() {
418
        if (!!this.lazyInit) {
419
            if (this.lazyInit instanceof HttpHeaders) {
420
                this.copyFrom(this.lazyInit);
421
            }
422
            else {
423
                this.lazyInit();
424
            }
425
            this.lazyInit = null;
426
            if (!!this.lazyUpdate) {
427
                this.lazyUpdate.forEach(update => this.applyUpdate(update));
428
                this.lazyUpdate = null;
429
            }
430
        }
431
    }
432
    /**
433
     * @param {?} other
434
     * @return {?}
435
     */
436
    copyFrom(other) {
437
        other.init();
438
        Array.from(other.headers.keys()).forEach(key => {
439
            this.headers.set(key, /** @type {?} */ ((other.headers.get(key))));
440
            this.normalizedNames.set(key, /** @type {?} */ ((other.normalizedNames.get(key))));
441
        });
442
    }
443
    /**
444
     * @param {?} update
445
     * @return {?}
446
     */
447
    clone(update) {
448
        const /** @type {?} */ clone = new HttpHeaders();
449
        clone.lazyInit =
450
            (!!this.lazyInit && this.lazyInit instanceof HttpHeaders) ? this.lazyInit : this;
451
        clone.lazyUpdate = (this.lazyUpdate || []).concat([update]);
452
        return clone;
453
    }
454
    /**
455
     * @param {?} update
456
     * @return {?}
457
     */
458
    applyUpdate(update) {
459
        const /** @type {?} */ key = update.name.toLowerCase();
460
        switch (update.op) {
461
            case 'a':
462
            case 's':
463
                let /** @type {?} */ value = ((update.value));
464
                if (typeof value === 'string') {
465
                    value = [value];
466
                }
467
                if (value.length === 0) {
468
                    return;
469
                }
470
                this.maybeSetNormalizedName(update.name, key);
471
                const /** @type {?} */ base = (update.op === 'a' ? this.headers.get(key) : undefined) || [];
472
                base.push(...value);
473
                this.headers.set(key, base);
474
                break;
475
            case 'd':
476
                const /** @type {?} */ toDelete = (update.value);
477
                if (!toDelete) {
478
                    this.headers.delete(key);
479
                    this.normalizedNames.delete(key);
480
                }
481
                else {
482
                    let /** @type {?} */ existing = this.headers.get(key);
483
                    if (!existing) {
484
                        return;
485
                    }
486
                    existing = existing.filter(value => toDelete.indexOf(value) === -1);
487
                    if (existing.length === 0) {
488
                        this.headers.delete(key);
489
                        this.normalizedNames.delete(key);
490
                    }
491
                    else {
492
                        this.headers.set(key, existing);
493
                    }
494
                }
495
                break;
496
        }
497
    }
498
    /**
499
     * \@internal
500
     * @param {?} fn
501
     * @return {?}
502
     */
503
    forEach(fn) {
504
        this.init();
505
        Array.from(this.normalizedNames.keys())
506
            .forEach(key => fn(/** @type {?} */ ((this.normalizedNames.get(key))), /** @type {?} */ ((this.headers.get(key)))));
507
    }
508
}
509

    
510
/**
511
 * @license
512
 * Copyright Google Inc. All Rights Reserved.
513
 *
514
 * Use of this source code is governed by an MIT-style license that can be
515
 * found in the LICENSE file at https://angular.io/license
516
 */
517
/**
518
 * Determine whether the given HTTP method may include a body.
519
 * @param {?} method
520
 * @return {?}
521
 */
522
function mightHaveBody(method) {
523
    switch (method) {
524
        case 'DELETE':
525
        case 'GET':
526
        case 'HEAD':
527
        case 'OPTIONS':
528
        case 'JSONP':
529
            return false;
530
        default:
531
            return true;
532
    }
533
}
534
/**
535
 * Safely assert whether the given value is an ArrayBuffer.
536
 *
537
 * In some execution environments ArrayBuffer is not defined.
538
 * @param {?} value
539
 * @return {?}
540
 */
541
function isArrayBuffer(value) {
542
    return typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer;
543
}
544
/**
545
 * Safely assert whether the given value is a Blob.
546
 *
547
 * In some execution environments Blob is not defined.
548
 * @param {?} value
549
 * @return {?}
550
 */
551
function isBlob(value) {
552
    return typeof Blob !== 'undefined' && value instanceof Blob;
553
}
554
/**
555
 * Safely assert whether the given value is a FormData instance.
556
 *
557
 * In some execution environments FormData is not defined.
558
 * @param {?} value
559
 * @return {?}
560
 */
561
function isFormData(value) {
562
    return typeof FormData !== 'undefined' && value instanceof FormData;
563
}
564
/**
565
 * An outgoing HTTP request with an optional typed body.
566
 *
567
 * `HttpRequest` represents an outgoing request, including URL, method,
568
 * headers, body, and other request configuration options. Instances should be
569
 * assumed to be immutable. To modify a `HttpRequest`, the `clone`
570
 * method should be used.
571
 *
572
 * \@experimental
573
 */
574
class HttpRequest {
575
    /**
576
     * @param {?} method
577
     * @param {?} url
578
     * @param {?=} third
579
     * @param {?=} fourth
580
     */
581
    constructor(method, url, third, fourth) {
582
        this.url = url;
583
        /**
584
         * The request body, or `null` if one isn't set.
585
         *
586
         * Bodies are not enforced to be immutable, as they can include a reference to any
587
         * user-defined data type. However, interceptors should take care to preserve
588
         * idempotence by treating them as such.
589
         */
590
        this.body = null;
591
        /**
592
         * Whether this request should be made in a way that exposes progress events.
593
         *
594
         * Progress events are expensive (change detection runs on each event) and so
595
         * they should only be requested if the consumer intends to monitor them.
596
         */
597
        this.reportProgress = false;
598
        /**
599
         * Whether this request should be sent with outgoing credentials (cookies).
600
         */
601
        this.withCredentials = false;
602
        /**
603
         * The expected response type of the server.
604
         *
605
         * This is used to parse the response appropriately before returning it to
606
         * the requestee.
607
         */
608
        this.responseType = 'json';
609
        this.method = method.toUpperCase();
610
        // Next, need to figure out which argument holds the HttpRequestInit
611
        // options, if any.
612
        let options;
613
        // Check whether a body argument is expected. The only valid way to omit
614
        // the body argument is to use a known no-body method like GET.
615
        if (mightHaveBody(this.method) || !!fourth) {
616
            // Body is the third argument, options are the fourth.
617
            this.body = third || null;
618
            options = fourth;
619
        }
620
        else {
621
            // No body required, options are the third argument. The body stays null.
622
            options = third;
623
        }
624
        // If options have been passed, interpret them.
625
        if (options) {
626
            // Normalize reportProgress and withCredentials.
627
            this.reportProgress = !!options.reportProgress;
628
            this.withCredentials = !!options.withCredentials;
629
            // Override default response type of 'json' if one is provided.
630
            if (!!options.responseType) {
631
                this.responseType = options.responseType;
632
            }
633
            // Override headers if they're provided.
634
            if (!!options.headers) {
635
                this.headers = options.headers;
636
            }
637
            if (!!options.params) {
638
                this.params = options.params;
639
            }
640
        }
641
        // If no headers have been passed in, construct a new HttpHeaders instance.
642
        if (!this.headers) {
643
            this.headers = new HttpHeaders();
644
        }
645
        // If no parameters have been passed in, construct a new HttpUrlEncodedParams instance.
646
        if (!this.params) {
647
            this.params = new HttpParams();
648
            this.urlWithParams = url;
649
        }
650
        else {
651
            // Encode the parameters to a string in preparation for inclusion in the URL.
652
            const params = this.params.toString();
653
            if (params.length === 0) {
654
                // No parameters, the visible URL is just the URL given at creation time.
655
                this.urlWithParams = url;
656
            }
657
            else {
658
                // Does the URL already have query parameters? Look for '?'.
659
                const qIdx = url.indexOf('?');
660
                // There are 3 cases to handle:
661
                // 1) No existing parameters -> append '?' followed by params.
662
                // 2) '?' exists and is followed by existing query string ->
663
                //    append '&' followed by params.
664
                // 3) '?' exists at the end of the url -> append params directly.
665
                // This basically amounts to determining the character, if any, with
666
                // which to join the URL and parameters.
667
                const sep = qIdx === -1 ? '?' : (qIdx < url.length - 1 ? '&' : '');
668
                this.urlWithParams = url + sep + params;
669
            }
670
        }
671
    }
672
    /**
673
     * Transform the free-form body into a serialized format suitable for
674
     * transmission to the server.
675
     * @return {?}
676
     */
677
    serializeBody() {
678
        // If no body is present, no need to serialize it.
679
        if (this.body === null) {
680
            return null;
681
        }
682
        // Check whether the body is already in a serialized form. If so,
683
        // it can just be returned directly.
684
        if (isArrayBuffer(this.body) || isBlob(this.body) || isFormData(this.body) ||
685
            typeof this.body === 'string') {
686
            return this.body;
687
        }
688
        // Check whether the body is an instance of HttpUrlEncodedParams.
689
        if (this.body instanceof HttpParams) {
690
            return this.body.toString();
691
        }
692
        // Check whether the body is an object or array, and serialize with JSON if so.
693
        if (typeof this.body === 'object' || typeof this.body === 'boolean' ||
694
            Array.isArray(this.body)) {
695
            return JSON.stringify(this.body);
696
        }
697
        // Fall back on toString() for everything else.
698
        return ((this.body)).toString();
699
    }
700
    /**
701
     * Examine the body and attempt to infer an appropriate MIME type
702
     * for it.
703
     *
704
     * If no such type can be inferred, this method will return `null`.
705
     * @return {?}
706
     */
707
    detectContentTypeHeader() {
708
        // An empty body has no content type.
709
        if (this.body === null) {
710
            return null;
711
        }
712
        // FormData bodies rely on the browser's content type assignment.
713
        if (isFormData(this.body)) {
714
            return null;
715
        }
716
        // Blobs usually have their own content type. If it doesn't, then
717
        // no type can be inferred.
718
        if (isBlob(this.body)) {
719
            return this.body.type || null;
720
        }
721
        // Array buffers have unknown contents and thus no type can be inferred.
722
        if (isArrayBuffer(this.body)) {
723
            return null;
724
        }
725
        // Technically, strings could be a form of JSON data, but it's safe enough
726
        // to assume they're plain strings.
727
        if (typeof this.body === 'string') {
728
            return 'text/plain';
729
        }
730
        // `HttpUrlEncodedParams` has its own content-type.
731
        if (this.body instanceof HttpParams) {
732
            return 'application/x-www-form-urlencoded;charset=UTF-8';
733
        }
734
        // Arrays, objects, and numbers will be encoded as JSON.
735
        if (typeof this.body === 'object' || typeof this.body === 'number' ||
736
            Array.isArray(this.body)) {
737
            return 'application/json';
738
        }
739
        // No type could be inferred.
740
        return null;
741
    }
742
    /**
743
     * @param {?=} update
744
     * @return {?}
745
     */
746
    clone(update = {}) {
747
        // For method, url, and responseType, take the current value unless
748
        // it is overridden in the update hash.
749
        const /** @type {?} */ method = update.method || this.method;
750
        const /** @type {?} */ url = update.url || this.url;
751
        const /** @type {?} */ responseType = update.responseType || this.responseType;
752
        // The body is somewhat special - a `null` value in update.body means
753
        // whatever current body is present is being overridden with an empty
754
        // body, whereas an `undefined` value in update.body implies no
755
        // override.
756
        const /** @type {?} */ body = (update.body !== undefined) ? update.body : this.body;
757
        // Carefully handle the boolean options to differentiate between
758
        // `false` and `undefined` in the update args.
759
        const /** @type {?} */ withCredentials = (update.withCredentials !== undefined) ? update.withCredentials : this.withCredentials;
760
        const /** @type {?} */ reportProgress = (update.reportProgress !== undefined) ? update.reportProgress : this.reportProgress;
761
        // Headers and params may be appended to if `setHeaders` or
762
        // `setParams` are used.
763
        let /** @type {?} */ headers = update.headers || this.headers;
764
        let /** @type {?} */ params = update.params || this.params;
765
        // Check whether the caller has asked to add headers.
766
        if (update.setHeaders !== undefined) {
767
            // Set every requested header.
768
            headers =
769
                Object.keys(update.setHeaders)
770
                    .reduce((headers, name) => headers.set(name, /** @type {?} */ ((update.setHeaders))[name]), headers);
771
        }
772
        // Check whether the caller has asked to set params.
773
        if (update.setParams) {
774
            // Set every requested param.
775
            params = Object.keys(update.setParams)
776
                .reduce((params, param) => params.set(param, /** @type {?} */ ((update.setParams))[param]), params);
777
        }
778
        // Finally, construct the new HttpRequest using the pieces from above.
779
        return new HttpRequest(method, url, body, {
780
            params, headers, reportProgress, responseType, withCredentials,
781
        });
782
    }
783
}
784

    
785
/**
786
 * @license
787
 * Copyright Google Inc. All Rights Reserved.
788
 *
789
 * Use of this source code is governed by an MIT-style license that can be
790
 * found in the LICENSE file at https://angular.io/license
791
 */
792
let HttpEventType = {};
793
HttpEventType.Sent = 0;
794
HttpEventType.UploadProgress = 1;
795
HttpEventType.ResponseHeader = 2;
796
HttpEventType.DownloadProgress = 3;
797
HttpEventType.Response = 4;
798
HttpEventType.User = 5;
799
HttpEventType[HttpEventType.Sent] = "Sent";
800
HttpEventType[HttpEventType.UploadProgress] = "UploadProgress";
801
HttpEventType[HttpEventType.ResponseHeader] = "ResponseHeader";
802
HttpEventType[HttpEventType.DownloadProgress] = "DownloadProgress";
803
HttpEventType[HttpEventType.Response] = "Response";
804
HttpEventType[HttpEventType.User] = "User";
805
/**
806
 * Base class for both `HttpResponse` and `HttpHeaderResponse`.
807
 *
808
 * \@experimental
809
 * @abstract
810
 */
811
class HttpResponseBase {
812
    /**
813
     * Super-constructor for all responses.
814
     *
815
     * The single parameter accepted is an initialization hash. Any properties
816
     * of the response passed there will override the default values.
817
     * @param {?} init
818
     * @param {?=} defaultStatus
819
     * @param {?=} defaultStatusText
820
     */
821
    constructor(init, defaultStatus = 200, defaultStatusText = 'OK') {
822
        // If the hash has values passed, use them to initialize the response.
823
        // Otherwise use the default values.
824
        this.headers = init.headers || new HttpHeaders();
825
        this.status = init.status !== undefined ? init.status : defaultStatus;
826
        this.statusText = init.statusText || defaultStatusText;
827
        this.url = init.url || null;
828
        // Cache the ok value to avoid defining a getter.
829
        this.ok = this.status >= 200 && this.status < 300;
830
    }
831
}
832
/**
833
 * A partial HTTP response which only includes the status and header data,
834
 * but no response body.
835
 *
836
 * `HttpHeaderResponse` is a `HttpEvent` available on the response
837
 * event stream, only when progress events are requested.
838
 *
839
 * \@experimental
840
 */
841
class HttpHeaderResponse extends HttpResponseBase {
842
    /**
843
     * Create a new `HttpHeaderResponse` with the given parameters.
844
     * @param {?=} init
845
     */
846
    constructor(init = {}) {
847
        super(init);
848
        this.type = HttpEventType.ResponseHeader;
849
    }
850
    /**
851
     * Copy this `HttpHeaderResponse`, overriding its contents with the
852
     * given parameter hash.
853
     * @param {?=} update
854
     * @return {?}
855
     */
856
    clone(update = {}) {
857
        // Perform a straightforward initialization of the new HttpHeaderResponse,
858
        // overriding the current parameters with new ones if given.
859
        return new HttpHeaderResponse({
860
            headers: update.headers || this.headers,
861
            status: update.status !== undefined ? update.status : this.status,
862
            statusText: update.statusText || this.statusText,
863
            url: update.url || this.url || undefined,
864
        });
865
    }
866
}
867
/**
868
 * A full HTTP response, including a typed response body (which may be `null`
869
 * if one was not returned).
870
 *
871
 * `HttpResponse` is a `HttpEvent` available on the response event
872
 * stream.
873
 *
874
 * \@experimental
875
 */
876
class HttpResponse extends HttpResponseBase {
877
    /**
878
     * Construct a new `HttpResponse`.
879
     * @param {?=} init
880
     */
881
    constructor(init = {}) {
882
        super(init);
883
        this.type = HttpEventType.Response;
884
        this.body = init.body || null;
885
    }
886
    /**
887
     * @param {?=} update
888
     * @return {?}
889
     */
890
    clone(update = {}) {
891
        return new HttpResponse({
892
            body: (update.body !== undefined) ? update.body : this.body,
893
            headers: update.headers || this.headers,
894
            status: (update.status !== undefined) ? update.status : this.status,
895
            statusText: update.statusText || this.statusText,
896
            url: update.url || this.url || undefined,
897
        });
898
    }
899
}
900
/**
901
 * A response that represents an error or failure, either from a
902
 * non-successful HTTP status, an error while executing the request,
903
 * or some other failure which occurred during the parsing of the response.
904
 *
905
 * Any error returned on the `Observable` response stream will be
906
 * wrapped in an `HttpErrorResponse` to provide additional context about
907
 * the state of the HTTP layer when the error occurred. The error property
908
 * will contain either a wrapped Error object or the error response returned
909
 * from the server.
910
 *
911
 * \@experimental
912
 */
913
class HttpErrorResponse extends HttpResponseBase {
914
    /**
915
     * @param {?} init
916
     */
917
    constructor(init) {
918
        // Initialize with a default status of 0 / Unknown Error.
919
        super(init, 0, 'Unknown Error');
920
        this.name = 'HttpErrorResponse';
921
        /**
922
         * Errors are never okay, even when the status code is in the 2xx success range.
923
         */
924
        this.ok = false;
925
        // If the response was successful, then this was a parse error. Otherwise, it was
926
        // a protocol-level failure of some sort. Either the request failed in transit
927
        // or the server returned an unsuccessful status code.
928
        if (this.status >= 200 && this.status < 300) {
929
            this.message = `Http failure during parsing for ${init.url || '(unknown url)'}`;
930
        }
931
        else {
932
            this.message =
933
                `Http failure response for ${init.url || '(unknown url)'}: ${init.status} ${init.statusText}`;
934
        }
935
        this.error = init.error || null;
936
    }
937
}
938

    
939
/**
940
 * @license
941
 * Copyright Google Inc. All Rights Reserved.
942
 *
943
 * Use of this source code is governed by an MIT-style license that can be
944
 * found in the LICENSE file at https://angular.io/license
945
 */
946
/**
947
 * Construct an instance of `HttpRequestOptions<T>` from a source `HttpMethodOptions` and
948
 * the given `body`. Basically, this clones the object and adds the body.
949
 * @template T
950
 * @param {?} options
951
 * @param {?} body
952
 * @return {?}
953
 */
954
function addBody(options, body) {
955
    return {
956
        body,
957
        headers: options.headers,
958
        observe: options.observe,
959
        params: options.params,
960
        reportProgress: options.reportProgress,
961
        responseType: options.responseType,
962
        withCredentials: options.withCredentials,
963
    };
964
}
965
/**
966
 * Perform HTTP requests.
967
 *
968
 * `HttpClient` is available as an injectable class, with methods to perform HTTP requests.
969
 * Each request method has multiple signatures, and the return type varies according to which
970
 * signature is called (mainly the values of `observe` and `responseType`).
971
 *
972
 * \@experimental
973
 */
974
class HttpClient {
975
    /**
976
     * @param {?} handler
977
     */
978
    constructor(handler) {
979
        this.handler = handler;
980
    }
981
    /**
982
     * Constructs an `Observable` for a particular HTTP request that, when subscribed,
983
     * fires the request through the chain of registered interceptors and on to the
984
     * server.
985
     *
986
     * This method can be called in one of two ways. Either an `HttpRequest`
987
     * instance can be passed directly as the only parameter, or a method can be
988
     * passed as the first parameter, a string URL as the second, and an
989
     * options hash as the third.
990
     *
991
     * If a `HttpRequest` object is passed directly, an `Observable` of the
992
     * raw `HttpEvent` stream will be returned.
993
     *
994
     * If a request is instead built by providing a URL, the options object
995
     * determines the return type of `request()`. In addition to configuring
996
     * request parameters such as the outgoing headers and/or the body, the options
997
     * hash specifies two key pieces of information about the request: the
998
     * `responseType` and what to `observe`.
999
     *
1000
     * The `responseType` value determines how a successful response body will be
1001
     * parsed. If `responseType` is the default `json`, a type interface for the
1002
     * resulting object may be passed as a type parameter to `request()`.
1003
     *
1004
     * The `observe` value determines the return type of `request()`, based on what
1005
     * the consumer is interested in observing. A value of `events` will return an
1006
     * `Observable<HttpEvent>` representing the raw `HttpEvent` stream,
1007
     * including progress events by default. A value of `response` will return an
1008
     * `Observable<HttpResponse<T>>` where the `T` parameter of `HttpResponse`
1009
     * depends on the `responseType` and any optionally provided type parameter.
1010
     * A value of `body` will return an `Observable<T>` with the same `T` body type.
1011
     * @param {?} first
1012
     * @param {?=} url
1013
     * @param {?=} options
1014
     * @return {?}
1015
     */
1016
    request(first, url, options = {}) {
1017
        let /** @type {?} */ req;
1018
        // Firstly, check whether the primary argument is an instance of `HttpRequest`.
1019
        if (first instanceof HttpRequest) {
1020
            // It is. The other arguments must be undefined (per the signatures) and can be
1021
            // ignored.
1022
            req = (first);
1023
        }
1024
        else {
1025
            // It's a string, so it represents a URL. Construct a request based on it,
1026
            // and incorporate the remaining arguments (assuming GET unless a method is
1027
            // provided.
1028
            req = new HttpRequest(first, /** @type {?} */ ((url)), options.body || null, {
1029
                headers: options.headers,
1030
                params: options.params,
1031
                reportProgress: options.reportProgress,
1032
                // By default, JSON is assumed to be returned for all calls.
1033
                responseType: options.responseType || 'json',
1034
                withCredentials: options.withCredentials,
1035
            });
1036
        }
1037
        // Start with an Observable.of() the initial request, and run the handler (which
1038
        // includes all interceptors) inside a concatMap(). This way, the handler runs
1039
        // inside an Observable chain, which causes interceptors to be re-run on every
1040
        // subscription (this also makes retries re-run the handler, including interceptors).
1041
        const /** @type {?} */ events$ = concatMap.call(of(req), (req) => this.handler.handle(req));
1042
        // If coming via the API signature which accepts a previously constructed HttpRequest,
1043
        // the only option is to get the event stream. Otherwise, return the event stream if
1044
        // that is what was requested.
1045
        if (first instanceof HttpRequest || options.observe === 'events') {
1046
            return events$;
1047
        }
1048
        // The requested stream contains either the full response or the body. In either
1049
        // case, the first step is to filter the event stream to extract a stream of
1050
        // responses(s).
1051
        const /** @type {?} */ res$ = filter.call(events$, (event) => event instanceof HttpResponse);
1052
        // Decide which stream to return.
1053
        switch (options.observe || 'body') {
1054
            case 'body':
1055
                // The requested stream is the body. Map the response stream to the response
1056
                // body. This could be done more simply, but a misbehaving interceptor might
1057
                // transform the response body into a different format and ignore the requested
1058
                // responseType. Guard against this by validating that the response is of the
1059
                // requested type.
1060
                switch (req.responseType) {
1061
                    case 'arraybuffer':
1062
                        return map.call(res$, (res) => {
1063
                            // Validate that the body is an ArrayBuffer.
1064
                            if (res.body !== null && !(res.body instanceof ArrayBuffer)) {
1065
                                throw new Error('Response is not an ArrayBuffer.');
1066
                            }
1067
                            return res.body;
1068
                        });
1069
                    case 'blob':
1070
                        return map.call(res$, (res) => {
1071
                            // Validate that the body is a Blob.
1072
                            if (res.body !== null && !(res.body instanceof Blob)) {
1073
                                throw new Error('Response is not a Blob.');
1074
                            }
1075
                            return res.body;
1076
                        });
1077
                    case 'text':
1078
                        return map.call(res$, (res) => {
1079
                            // Validate that the body is a string.
1080
                            if (res.body !== null && typeof res.body !== 'string') {
1081
                                throw new Error('Response is not a string.');
1082
                            }
1083
                            return res.body;
1084
                        });
1085
                    case 'json':
1086
                    default:
1087
                        // No validation needed for JSON responses, as they can be of any type.
1088
                        return map.call(res$, (res) => res.body);
1089
                }
1090
            case 'response':
1091
                // The response stream was requested directly, so return it.
1092
                return res$;
1093
            default:
1094
                // Guard against new future observe types being added.
1095
                throw new Error(`Unreachable: unhandled observe type ${options.observe}}`);
1096
        }
1097
    }
1098
    /**
1099
     * Constructs an `Observable` which, when subscribed, will cause the configured
1100
     * DELETE request to be executed on the server. See the individual overloads for
1101
     * details of `delete()`'s return type based on the provided options.
1102
     * @param {?} url
1103
     * @param {?=} options
1104
     * @return {?}
1105
     */
1106
    delete(url, options = {}) {
1107
        return this.request('DELETE', url, /** @type {?} */ (options));
1108
    }
1109
    /**
1110
     * Constructs an `Observable` which, when subscribed, will cause the configured
1111
     * GET request to be executed on the server. See the individual overloads for
1112
     * details of `get()`'s return type based on the provided options.
1113
     * @param {?} url
1114
     * @param {?=} options
1115
     * @return {?}
1116
     */
1117
    get(url, options = {}) {
1118
        return this.request('GET', url, /** @type {?} */ (options));
1119
    }
1120
    /**
1121
     * Constructs an `Observable` which, when subscribed, will cause the configured
1122
     * HEAD request to be executed on the server. See the individual overloads for
1123
     * details of `head()`'s return type based on the provided options.
1124
     * @param {?} url
1125
     * @param {?=} options
1126
     * @return {?}
1127
     */
1128
    head(url, options = {}) {
1129
        return this.request('HEAD', url, /** @type {?} */ (options));
1130
    }
1131
    /**
1132
     * Constructs an `Observable` which, when subscribed, will cause a request
1133
     * with the special method `JSONP` to be dispatched via the interceptor pipeline.
1134
     *
1135
     * A suitable interceptor must be installed (e.g. via the `HttpClientJsonpModule`).
1136
     * If no such interceptor is reached, then the `JSONP` request will likely be
1137
     * rejected by the configured backend.
1138
     * @template T
1139
     * @param {?} url
1140
     * @param {?} callbackParam
1141
     * @return {?}
1142
     */
1143
    jsonp(url, callbackParam) {
1144
        return this.request('JSONP', url, {
1145
            params: new HttpParams().append(callbackParam, 'JSONP_CALLBACK'),
1146
            observe: 'body',
1147
            responseType: 'json',
1148
        });
1149
    }
1150
    /**
1151
     * Constructs an `Observable` which, when subscribed, will cause the configured
1152
     * OPTIONS request to be executed on the server. See the individual overloads for
1153
     * details of `options()`'s return type based on the provided options.
1154
     * @param {?} url
1155
     * @param {?=} options
1156
     * @return {?}
1157
     */
1158
    options(url, options = {}) {
1159
        return this.request('OPTIONS', url, /** @type {?} */ (options));
1160
    }
1161
    /**
1162
     * Constructs an `Observable` which, when subscribed, will cause the configured
1163
     * PATCH request to be executed on the server. See the individual overloads for
1164
     * details of `patch()`'s return type based on the provided options.
1165
     * @param {?} url
1166
     * @param {?} body
1167
     * @param {?=} options
1168
     * @return {?}
1169
     */
1170
    patch(url, body, options = {}) {
1171
        return this.request('PATCH', url, addBody(options, body));
1172
    }
1173
    /**
1174
     * Constructs an `Observable` which, when subscribed, will cause the configured
1175
     * POST request to be executed on the server. See the individual overloads for
1176
     * details of `post()`'s return type based on the provided options.
1177
     * @param {?} url
1178
     * @param {?} body
1179
     * @param {?=} options
1180
     * @return {?}
1181
     */
1182
    post(url, body, options = {}) {
1183
        return this.request('POST', url, addBody(options, body));
1184
    }
1185
    /**
1186
     * Constructs an `Observable` which, when subscribed, will cause the configured
1187
     * POST request to be executed on the server. See the individual overloads for
1188
     * details of `post()`'s return type based on the provided options.
1189
     * @param {?} url
1190
     * @param {?} body
1191
     * @param {?=} options
1192
     * @return {?}
1193
     */
1194
    put(url, body, options = {}) {
1195
        return this.request('PUT', url, addBody(options, body));
1196
    }
1197
}
1198
HttpClient.decorators = [
1199
    { type: Injectable },
1200
];
1201
/**
1202
 * @nocollapse
1203
 */
1204
HttpClient.ctorParameters = () => [
1205
    { type: HttpHandler, },
1206
];
1207

    
1208
/**
1209
 * @license
1210
 * Copyright Google Inc. All Rights Reserved.
1211
 *
1212
 * Use of this source code is governed by an MIT-style license that can be
1213
 * found in the LICENSE file at https://angular.io/license
1214
 */
1215
/**
1216
 * `HttpHandler` which applies an `HttpInterceptor` to an `HttpRequest`.
1217
 *
1218
 * \@experimental
1219
 */
1220
class HttpInterceptorHandler {
1221
    /**
1222
     * @param {?} next
1223
     * @param {?} interceptor
1224
     */
1225
    constructor(next, interceptor) {
1226
        this.next = next;
1227
        this.interceptor = interceptor;
1228
    }
1229
    /**
1230
     * @param {?} req
1231
     * @return {?}
1232
     */
1233
    handle(req) {
1234
        return this.interceptor.intercept(req, this.next);
1235
    }
1236
}
1237
/**
1238
 * A multi-provider token which represents the array of `HttpInterceptor`s that
1239
 * are registered.
1240
 *
1241
 * \@experimental
1242
 */
1243
const HTTP_INTERCEPTORS = new InjectionToken('HTTP_INTERCEPTORS');
1244
class NoopInterceptor {
1245
    /**
1246
     * @param {?} req
1247
     * @param {?} next
1248
     * @return {?}
1249
     */
1250
    intercept(req, next) {
1251
        return next.handle(req);
1252
    }
1253
}
1254
NoopInterceptor.decorators = [
1255
    { type: Injectable },
1256
];
1257
/**
1258
 * @nocollapse
1259
 */
1260
NoopInterceptor.ctorParameters = () => [];
1261

    
1262
/**
1263
 * @license
1264
 * Copyright Google Inc. All Rights Reserved.
1265
 *
1266
 * Use of this source code is governed by an MIT-style license that can be
1267
 * found in the LICENSE file at https://angular.io/license
1268
 */
1269
// Every request made through JSONP needs a callback name that's unique across the
1270
// whole page. Each request is assigned an id and the callback name is constructed
1271
// from that. The next id to be assigned is tracked in a global variable here that
1272
// is shared among all applications on the page.
1273
let nextRequestId = 0;
1274
// Error text given when a JSONP script is injected, but doesn't invoke the callback
1275
// passed in its URL.
1276
const JSONP_ERR_NO_CALLBACK = 'JSONP injected script did not invoke callback.';
1277
// Error text given when a request is passed to the JsonpClientBackend that doesn't
1278
// have a request method JSONP.
1279
const JSONP_ERR_WRONG_METHOD = 'JSONP requests must use JSONP request method.';
1280
const JSONP_ERR_WRONG_RESPONSE_TYPE = 'JSONP requests must use Json response type.';
1281
/**
1282
 * DI token/abstract type representing a map of JSONP callbacks.
1283
 *
1284
 * In the browser, this should always be the `window` object.
1285
 *
1286
 * \@experimental
1287
 * @abstract
1288
 */
1289
class JsonpCallbackContext {
1290
}
1291
/**
1292
 * `HttpBackend` that only processes `HttpRequest` with the JSONP method,
1293
 * by performing JSONP style requests.
1294
 *
1295
 * \@experimental
1296
 */
1297
class JsonpClientBackend {
1298
    /**
1299
     * @param {?} callbackMap
1300
     * @param {?} document
1301
     */
1302
    constructor(callbackMap, document) {
1303
        this.callbackMap = callbackMap;
1304
        this.document = document;
1305
    }
1306
    /**
1307
     * Get the name of the next callback method, by incrementing the global `nextRequestId`.
1308
     * @return {?}
1309
     */
1310
    nextCallback() { return `ng_jsonp_callback_${nextRequestId++}`; }
1311
    /**
1312
     * Process a JSONP request and return an event stream of the results.
1313
     * @param {?} req
1314
     * @return {?}
1315
     */
1316
    handle(req) {
1317
        // Firstly, check both the method and response type. If either doesn't match
1318
        // then the request was improperly routed here and cannot be handled.
1319
        if (req.method !== 'JSONP') {
1320
            throw new Error(JSONP_ERR_WRONG_METHOD);
1321
        }
1322
        else if (req.responseType !== 'json') {
1323
            throw new Error(JSONP_ERR_WRONG_RESPONSE_TYPE);
1324
        }
1325
        // Everything else happens inside the Observable boundary.
1326
        return new Observable((observer) => {
1327
            // The first step to make a request is to generate the callback name, and replace the
1328
            // callback placeholder in the URL with the name. Care has to be taken here to ensure
1329
            // a trailing &, if matched, gets inserted back into the URL in the correct place.
1330
            const /** @type {?} */ callback = this.nextCallback();
1331
            const /** @type {?} */ url = req.urlWithParams.replace(/=JSONP_CALLBACK(&|$)/, `=${callback}$1`);
1332
            // Construct the <script> tag and point it at the URL.
1333
            const /** @type {?} */ node = this.document.createElement('script');
1334
            node.src = url;
1335
            // A JSONP request requires waiting for multiple callbacks. These variables
1336
            // are closed over and track state across those callbacks.
1337
            // The response object, if one has been received, or null otherwise.
1338
            let /** @type {?} */ body = null;
1339
            // Whether the response callback has been called.
1340
            let /** @type {?} */ finished = false;
1341
            // Whether the request has been cancelled (and thus any other callbacks)
1342
            // should be ignored.
1343
            let /** @type {?} */ cancelled = false;
1344
            // Set the response callback in this.callbackMap (which will be the window
1345
            // object in the browser. The script being loaded via the <script> tag will
1346
            // eventually call this callback.
1347
            this.callbackMap[callback] = (data) => {
1348
                // Data has been received from the JSONP script. Firstly, delete this callback.
1349
                delete this.callbackMap[callback];
1350
                // Next, make sure the request wasn't cancelled in the meantime.
1351
                if (cancelled) {
1352
                    return;
1353
                }
1354
                // Set state to indicate data was received.
1355
                body = data;
1356
                finished = true;
1357
            };
1358
            // cleanup() is a utility closure that removes the <script> from the page and
1359
            // the response callback from the window. This logic is used in both the
1360
            // success, error, and cancellation paths, so it's extracted out for convenience.
1361
            const /** @type {?} */ cleanup = () => {
1362
                // Remove the <script> tag if it's still on the page.
1363
                if (node.parentNode) {
1364
                    node.parentNode.removeChild(node);
1365
                }
1366
                // Remove the response callback from the callbackMap (window object in the
1367
                // browser).
1368
                delete this.callbackMap[callback];
1369
            };
1370
            // onLoad() is the success callback which runs after the response callback
1371
            // if the JSONP script loads successfully. The event itself is unimportant.
1372
            // If something went wrong, onLoad() may run without the response callback
1373
            // having been invoked.
1374
            const /** @type {?} */ onLoad = (event) => {
1375
                // Do nothing if the request has been cancelled.
1376
                if (cancelled) {
1377
                    return;
1378
                }
1379
                // Cleanup the page.
1380
                cleanup();
1381
                // Check whether the response callback has run.
1382
                if (!finished) {
1383
                    // It hasn't, something went wrong with the request. Return an error via
1384
                    // the Observable error path. All JSONP errors have status 0.
1385
                    observer.error(new HttpErrorResponse({
1386
                        url,
1387
                        status: 0,
1388
                        statusText: 'JSONP Error',
1389
                        error: new Error(JSONP_ERR_NO_CALLBACK),
1390
                    }));
1391
                    return;
1392
                }
1393
                // Success. body either contains the response body or null if none was
1394
                // returned.
1395
                observer.next(new HttpResponse({
1396
                    body,
1397
                    status: 200,
1398
                    statusText: 'OK', url,
1399
                }));
1400
                // Complete the stream, the resposne is over.
1401
                observer.complete();
1402
            };
1403
            // onError() is the error callback, which runs if the script returned generates
1404
            // a Javascript error. It emits the error via the Observable error channel as
1405
            // a HttpErrorResponse.
1406
            const /** @type {?} */ onError = (error) => {
1407
                // If the request was already cancelled, no need to emit anything.
1408
                if (cancelled) {
1409
                    return;
1410
                }
1411
                cleanup();
1412
                // Wrap the error in a HttpErrorResponse.
1413
                observer.error(new HttpErrorResponse({
1414
                    error,
1415
                    status: 0,
1416
                    statusText: 'JSONP Error', url,
1417
                }));
1418
            };
1419
            // Subscribe to both the success (load) and error events on the <script> tag,
1420
            // and add it to the page.
1421
            node.addEventListener('load', onLoad);
1422
            node.addEventListener('error', onError);
1423
            this.document.body.appendChild(node);
1424
            // The request has now been successfully sent.
1425
            observer.next({ type: HttpEventType.Sent });
1426
            // Cancellation handler.
1427
            return () => {
1428
                // Track the cancellation so event listeners won't do anything even if already scheduled.
1429
                cancelled = true;
1430
                // Remove the event listeners so they won't run if the events later fire.
1431
                node.removeEventListener('load', onLoad);
1432
                node.removeEventListener('error', onError);
1433
                // And finally, clean up the page.
1434
                cleanup();
1435
            };
1436
        });
1437
    }
1438
}
1439
JsonpClientBackend.decorators = [
1440
    { type: Injectable },
1441
];
1442
/**
1443
 * @nocollapse
1444
 */
1445
JsonpClientBackend.ctorParameters = () => [
1446
    { type: JsonpCallbackContext, },
1447
    { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] },] },
1448
];
1449
/**
1450
 * An `HttpInterceptor` which identifies requests with the method JSONP and
1451
 * shifts them to the `JsonpClientBackend`.
1452
 *
1453
 * \@experimental
1454
 */
1455
class JsonpInterceptor {
1456
    /**
1457
     * @param {?} jsonp
1458
     */
1459
    constructor(jsonp) {
1460
        this.jsonp = jsonp;
1461
    }
1462
    /**
1463
     * @param {?} req
1464
     * @param {?} next
1465
     * @return {?}
1466
     */
1467
    intercept(req, next) {
1468
        if (req.method === 'JSONP') {
1469
            return this.jsonp.handle(/** @type {?} */ (req));
1470
        }
1471
        // Fall through for normal HTTP requests.
1472
        return next.handle(req);
1473
    }
1474
}
1475
JsonpInterceptor.decorators = [
1476
    { type: Injectable },
1477
];
1478
/**
1479
 * @nocollapse
1480
 */
1481
JsonpInterceptor.ctorParameters = () => [
1482
    { type: JsonpClientBackend, },
1483
];
1484

    
1485
/**
1486
 * @license
1487
 * Copyright Google Inc. All Rights Reserved.
1488
 *
1489
 * Use of this source code is governed by an MIT-style license that can be
1490
 * found in the LICENSE file at https://angular.io/license
1491
 */
1492
const XSSI_PREFIX = /^\)\]\}',?\n/;
1493
/**
1494
 * Determine an appropriate URL for the response, by checking either
1495
 * XMLHttpRequest.responseURL or the X-Request-URL header.
1496
 * @param {?} xhr
1497
 * @return {?}
1498
 */
1499
function getResponseUrl(xhr) {
1500
    if ('responseURL' in xhr && xhr.responseURL) {
1501
        return xhr.responseURL;
1502
    }
1503
    if (/^X-Request-URL:/m.test(xhr.getAllResponseHeaders())) {
1504
        return xhr.getResponseHeader('X-Request-URL');
1505
    }
1506
    return null;
1507
}
1508
/**
1509
 * A wrapper around the `XMLHttpRequest` constructor.
1510
 *
1511
 * \@experimental
1512
 * @abstract
1513
 */
1514
class XhrFactory {
1515
    /**
1516
     * @abstract
1517
     * @return {?}
1518
     */
1519
    build() { }
1520
}
1521
/**
1522
 * A factory for \@{link HttpXhrBackend} that uses the `XMLHttpRequest` browser API.
1523
 *
1524
 * \@experimental
1525
 */
1526
class BrowserXhr {
1527
    constructor() { }
1528
    /**
1529
     * @return {?}
1530
     */
1531
    build() { return ((new XMLHttpRequest())); }
1532
}
1533
BrowserXhr.decorators = [
1534
    { type: Injectable },
1535
];
1536
/**
1537
 * @nocollapse
1538
 */
1539
BrowserXhr.ctorParameters = () => [];
1540
/**
1541
 * An `HttpBackend` which uses the XMLHttpRequest API to send
1542
 * requests to a backend server.
1543
 *
1544
 * \@experimental
1545
 */
1546
class HttpXhrBackend {
1547
    /**
1548
     * @param {?} xhrFactory
1549
     */
1550
    constructor(xhrFactory) {
1551
        this.xhrFactory = xhrFactory;
1552
    }
1553
    /**
1554
     * Process a request and return a stream of response events.
1555
     * @param {?} req
1556
     * @return {?}
1557
     */
1558
    handle(req) {
1559
        // Quick check to give a better error message when a user attempts to use
1560
        // HttpClient.jsonp() without installing the JsonpClientModule
1561
        if (req.method === 'JSONP') {
1562
            throw new Error(`Attempted to construct Jsonp request without JsonpClientModule installed.`);
1563
        }
1564
        // Everything happens on Observable subscription.
1565
        return new Observable((observer) => {
1566
            // Start by setting up the XHR object with request method, URL, and withCredentials flag.
1567
            const /** @type {?} */ xhr = this.xhrFactory.build();
1568
            xhr.open(req.method, req.urlWithParams);
1569
            if (!!req.withCredentials) {
1570
                xhr.withCredentials = true;
1571
            }
1572
            // Add all the requested headers.
1573
            req.headers.forEach((name, values) => xhr.setRequestHeader(name, values.join(',')));
1574
            // Add an Accept header if one isn't present already.
1575
            if (!req.headers.has('Accept')) {
1576
                xhr.setRequestHeader('Accept', 'application/json, text/plain, */*');
1577
            }
1578
            // Auto-detect the Content-Type header if one isn't present already.
1579
            if (!req.headers.has('Content-Type')) {
1580
                const /** @type {?} */ detectedType = req.detectContentTypeHeader();
1581
                // Sometimes Content-Type detection fails.
1582
                if (detectedType !== null) {
1583
                    xhr.setRequestHeader('Content-Type', detectedType);
1584
                }
1585
            }
1586
            // Set the responseType if one was requested.
1587
            if (req.responseType) {
1588
                const /** @type {?} */ responseType = req.responseType.toLowerCase();
1589
                // JSON responses need to be processed as text. This is because if the server
1590
                // returns an XSSI-prefixed JSON response, the browser will fail to parse it,
1591
                // xhr.response will be null, and xhr.responseText cannot be accessed to
1592
                // retrieve the prefixed JSON data in order to strip the prefix. Thus, all JSON
1593
                // is parsed by first requesting text and then applying JSON.parse.
1594
                xhr.responseType = (((responseType !== 'json') ? responseType : 'text'));
1595
            }
1596
            // Serialize the request body if one is present. If not, this will be set to null.
1597
            const /** @type {?} */ reqBody = req.serializeBody();
1598
            // If progress events are enabled, response headers will be delivered
1599
            // in two events - the HttpHeaderResponse event and the full HttpResponse
1600
            // event. However, since response headers don't change in between these
1601
            // two events, it doesn't make sense to parse them twice. So headerResponse
1602
            // caches the data extracted from the response whenever it's first parsed,
1603
            // to ensure parsing isn't duplicated.
1604
            let /** @type {?} */ headerResponse = null;
1605
            // partialFromXhr extracts the HttpHeaderResponse from the current XMLHttpRequest
1606
            // state, and memoizes it into headerResponse.
1607
            const /** @type {?} */ partialFromXhr = () => {
1608
                if (headerResponse !== null) {
1609
                    return headerResponse;
1610
                }
1611
                // Read status and normalize an IE9 bug (http://bugs.jquery.com/ticket/1450).
1612
                const /** @type {?} */ status = xhr.status === 1223 ? 204 : xhr.status;
1613
                const /** @type {?} */ statusText = xhr.statusText || 'OK';
1614
                // Parse headers from XMLHttpRequest - this step is lazy.
1615
                const /** @type {?} */ headers = new HttpHeaders(xhr.getAllResponseHeaders());
1616
                // Read the response URL from the XMLHttpResponse instance and fall back on the
1617
                // request URL.
1618
                const /** @type {?} */ url = getResponseUrl(xhr) || req.url;
1619
                // Construct the HttpHeaderResponse and memoize it.
1620
                headerResponse = new HttpHeaderResponse({ headers, status, statusText, url });
1621
                return headerResponse;
1622
            };
1623
            // Next, a few closures are defined for the various events which XMLHttpRequest can
1624
            // emit. This allows them to be unregistered as event listeners later.
1625
            // First up is the load event, which represents a response being fully available.
1626
            const /** @type {?} */ onLoad = () => {
1627
                // Read response state from the memoized partial data.
1628
                let { headers, status, statusText, url } = partialFromXhr();
1629
                // The body will be read out if present.
1630
                let /** @type {?} */ body = null;
1631
                if (status !== 204) {
1632
                    // Use XMLHttpRequest.response if set, responseText otherwise.
1633
                    body = (typeof xhr.response === 'undefined') ? xhr.responseText : xhr.response;
1634
                }
1635
                // Normalize another potential bug (this one comes from CORS).
1636
                if (status === 0) {
1637
                    status = !!body ? 200 : 0;
1638
                }
1639
                // ok determines whether the response will be transmitted on the event or
1640
                // error channel. Unsuccessful status codes (not 2xx) will always be errors,
1641
                // but a successful status code can still result in an error if the user
1642
                // asked for JSON data and the body cannot be parsed as such.
1643
                let /** @type {?} */ ok = status >= 200 && status < 300;
1644
                // Check whether the body needs to be parsed as JSON (in many cases the browser
1645
                // will have done that already).
1646
                if (ok && req.responseType === 'json' && typeof body === 'string') {
1647
                    // Attempt the parse. If it fails, a parse error should be delivered to the user.
1648
                    body = body.replace(XSSI_PREFIX, '');
1649
                    try {
1650
                        body = JSON.parse(body);
1651
                    }
1652
                    catch (error) {
1653
                        // Even though the response status was 2xx, this is still an error.
1654
                        ok = false;
1655
                        // The parse error contains the text of the body that failed to parse.
1656
                        body = ({ error, text: body });
1657
                    }
1658
                }
1659
                else if (!ok && req.responseType === 'json' && typeof body === 'string') {
1660
                    try {
1661
                        // Attempt to parse the body as JSON.
1662
                        body = JSON.parse(body);
1663
                    }
1664
                    catch (error) {
1665
                        // Cannot be certain that the body was meant to be parsed as JSON.
1666
                        // Leave the body as a string.
1667
                    }
1668
                }
1669
                if (ok) {
1670
                    // A successful response is delivered on the event stream.
1671
                    observer.next(new HttpResponse({
1672
                        body,
1673
                        headers,
1674
                        status,
1675
                        statusText,
1676
                        url: url || undefined,
1677
                    }));
1678
                    // The full body has been received and delivered, no further events
1679
                    // are possible. This request is complete.
1680
                    observer.complete();
1681
                }
1682
                else {
1683
                    // An unsuccessful request is delivered on the error channel.
1684
                    observer.error(new HttpErrorResponse({
1685
                        // The error in this case is the response body (error from the server).
1686
                        error: body,
1687
                        headers,
1688
                        status,
1689
                        statusText,
1690
                        url: url || undefined,
1691
                    }));
1692
                }
1693
            };
1694
            // The onError callback is called when something goes wrong at the network level.
1695
            // Connection timeout, DNS error, offline, etc. These are actual errors, and are
1696
            // transmitted on the error channel.
1697
            const /** @type {?} */ onError = (error) => {
1698
                const /** @type {?} */ res = new HttpErrorResponse({
1699
                    error,
1700
                    status: xhr.status || 0,
1701
                    statusText: xhr.statusText || 'Unknown Error',
1702
                });
1703
                observer.error(res);
1704
            };
1705
            // The sentHeaders flag tracks whether the HttpResponseHeaders event
1706
            // has been sent on the stream. This is necessary to track if progress
1707
            // is enabled since the event will be sent on only the first download
1708
            // progerss event.
1709
            let /** @type {?} */ sentHeaders = false;
1710
            // The download progress event handler, which is only registered if
1711
            // progress events are enabled.
1712
            const /** @type {?} */ onDownProgress = (event) => {
1713
                // Send the HttpResponseHeaders event if it hasn't been sent already.
1714
                if (!sentHeaders) {
1715
                    observer.next(partialFromXhr());
1716
                    sentHeaders = true;
1717
                }
1718
                // Start building the download progress event to deliver on the response
1719
                // event stream.
1720
                let /** @type {?} */ progressEvent = {
1721
                    type: HttpEventType.DownloadProgress,
1722
                    loaded: event.loaded,
1723
                };
1724
                // Set the total number of bytes in the event if it's available.
1725
                if (event.lengthComputable) {
1726
                    progressEvent.total = event.total;
1727
                }
1728
                // If the request was for text content and a partial response is
1729
                // available on XMLHttpRequest, include it in the progress event
1730
                // to allow for streaming reads.
1731
                if (req.responseType === 'text' && !!xhr.responseText) {
1732
                    progressEvent.partialText = xhr.responseText;
1733
                }
1734
                // Finally, fire the event.
1735
                observer.next(progressEvent);
1736
            };
1737
            // The upload progress event handler, which is only registered if
1738
            // progress events are enabled.
1739
            const /** @type {?} */ onUpProgress = (event) => {
1740
                // Upload progress events are simpler. Begin building the progress
1741
                // event.
1742
                let /** @type {?} */ progress = {
1743
                    type: HttpEventType.UploadProgress,
1744
                    loaded: event.loaded,
1745
                };
1746
                // If the total number of bytes being uploaded is available, include
1747
                // it.
1748
                if (event.lengthComputable) {
1749
                    progress.total = event.total;
1750
                }
1751
                // Send the event.
1752
                observer.next(progress);
1753
            };
1754
            // By default, register for load and error events.
1755
            xhr.addEventListener('load', onLoad);
1756
            xhr.addEventListener('error', onError);
1757
            // Progress events are only enabled if requested.
1758
            if (req.reportProgress) {
1759
                // Download progress is always enabled if requested.
1760
                xhr.addEventListener('progress', onDownProgress);
1761
                // Upload progress depends on whether there is a body to upload.
1762
                if (reqBody !== null && xhr.upload) {
1763
                    xhr.upload.addEventListener('progress', onUpProgress);
1764
                }
1765
            }
1766
            // Fire the request, and notify the event stream that it was fired.
1767
            xhr.send(reqBody);
1768
            observer.next({ type: HttpEventType.Sent });
1769
            // This is the return from the Observable function, which is the
1770
            // request cancellation handler.
1771
            return () => {
1772
                // On a cancellation, remove all registered event listeners.
1773
                xhr.removeEventListener('error', onError);
1774
                xhr.removeEventListener('load', onLoad);
1775
                if (req.reportProgress) {
1776
                    xhr.removeEventListener('progress', onDownProgress);
1777
                    if (reqBody !== null && xhr.upload) {
1778
                        xhr.upload.removeEventListener('progress', onUpProgress);
1779
                    }
1780
                }
1781
                // Finally, abort the in-flight request.
1782
                xhr.abort();
1783
            };
1784
        });
1785
    }
1786
}
1787
HttpXhrBackend.decorators = [
1788
    { type: Injectable },
1789
];
1790
/**
1791
 * @nocollapse
1792
 */
1793
HttpXhrBackend.ctorParameters = () => [
1794
    { type: XhrFactory, },
1795
];
1796

    
1797
/**
1798
 * @license
1799
 * Copyright Google Inc. All Rights Reserved.
1800
 *
1801
 * Use of this source code is governed by an MIT-style license that can be
1802
 * found in the LICENSE file at https://angular.io/license
1803
 */
1804
const XSRF_COOKIE_NAME = new InjectionToken('XSRF_COOKIE_NAME');
1805
const XSRF_HEADER_NAME = new InjectionToken('XSRF_HEADER_NAME');
1806
/**
1807
 * Retrieves the current XSRF token to use with the next outgoing request.
1808
 *
1809
 * \@experimental
1810
 * @abstract
1811
 */
1812
class HttpXsrfTokenExtractor {
1813
    /**
1814
     * Get the XSRF token to use with an outgoing request.
1815
     *
1816
     * Will be called for every request, so the token may change between requests.
1817
     * @abstract
1818
     * @return {?}
1819
     */
1820
    getToken() { }
1821
}
1822
/**
1823
 * `HttpXsrfTokenExtractor` which retrieves the token from a cookie.
1824
 */
1825
class HttpXsrfCookieExtractor {
1826
    /**
1827
     * @param {?} doc
1828
     * @param {?} platform
1829
     * @param {?} cookieName
1830
     */
1831
    constructor(doc, platform, cookieName) {
1832
        this.doc = doc;
1833
        this.platform = platform;
1834
        this.cookieName = cookieName;
1835
        this.lastCookieString = '';
1836
        this.lastToken = null;
1837
        /**
1838
         * \@internal for testing
1839
         */
1840
        this.parseCount = 0;
1841
    }
1842
    /**
1843
     * @return {?}
1844
     */
1845
    getToken() {
1846
        if (this.platform === 'server') {
1847
            return null;
1848
        }
1849
        const /** @type {?} */ cookieString = this.doc.cookie || '';
1850
        if (cookieString !== this.lastCookieString) {
1851
            this.parseCount++;
1852
            this.lastToken = ɵparseCookieValue(cookieString, this.cookieName);
1853
            this.lastCookieString = cookieString;
1854
        }
1855
        return this.lastToken;
1856
    }
1857
}
1858
HttpXsrfCookieExtractor.decorators = [
1859
    { type: Injectable },
1860
];
1861
/**
1862
 * @nocollapse
1863
 */
1864
HttpXsrfCookieExtractor.ctorParameters = () => [
1865
    { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] },] },
1866
    { type: undefined, decorators: [{ type: Inject, args: [PLATFORM_ID,] },] },
1867
    { type: undefined, decorators: [{ type: Inject, args: [XSRF_COOKIE_NAME,] },] },
1868
];
1869
/**
1870
 * `HttpInterceptor` which adds an XSRF token to eligible outgoing requests.
1871
 */
1872
class HttpXsrfInterceptor {
1873
    /**
1874
     * @param {?} tokenService
1875
     * @param {?} headerName
1876
     */
1877
    constructor(tokenService, headerName) {
1878
        this.tokenService = tokenService;
1879
        this.headerName = headerName;
1880
    }
1881
    /**
1882
     * @param {?} req
1883
     * @param {?} next
1884
     * @return {?}
1885
     */
1886
    intercept(req, next) {
1887
        const /** @type {?} */ lcUrl = req.url.toLowerCase();
1888
        // Skip both non-mutating requests and absolute URLs.
1889
        // Non-mutating requests don't require a token, and absolute URLs require special handling
1890
        // anyway as the cookie set
1891
        // on our origin is not the same as the token expected by another origin.
1892
        if (req.method === 'GET' || req.method === 'HEAD' || lcUrl.startsWith('http://') ||
1893
            lcUrl.startsWith('https://')) {
1894
            return next.handle(req);
1895
        }
1896
        const /** @type {?} */ token = this.tokenService.getToken();
1897
        // Be careful not to overwrite an existing header of the same name.
1898
        if (token !== null && !req.headers.has(this.headerName)) {
1899
            req = req.clone({ headers: req.headers.set(this.headerName, token) });
1900
        }
1901
        return next.handle(req);
1902
    }
1903
}
1904
HttpXsrfInterceptor.decorators = [
1905
    { type: Injectable },
1906
];
1907
/**
1908
 * @nocollapse
1909
 */
1910
HttpXsrfInterceptor.ctorParameters = () => [
1911
    { type: HttpXsrfTokenExtractor, },
1912
    { type: undefined, decorators: [{ type: Inject, args: [XSRF_HEADER_NAME,] },] },
1913
];
1914

    
1915
/**
1916
 * @license
1917
 * Copyright Google Inc. All Rights Reserved.
1918
 *
1919
 * Use of this source code is governed by an MIT-style license that can be
1920
 * found in the LICENSE file at https://angular.io/license
1921
 */
1922
/**
1923
 * Constructs an `HttpHandler` that applies a bunch of `HttpInterceptor`s
1924
 * to a request before passing it to the given `HttpBackend`.
1925
 *
1926
 * Meant to be used as a factory function within `HttpClientModule`.
1927
 *
1928
 * \@experimental
1929
 * @param {?} backend
1930
 * @param {?=} interceptors
1931
 * @return {?}
1932
 */
1933
function interceptingHandler(backend, interceptors = []) {
1934
    if (!interceptors) {
1935
        return backend;
1936
    }
1937
    return interceptors.reduceRight((next, interceptor) => new HttpInterceptorHandler(next, interceptor), backend);
1938
}
1939
/**
1940
 * Factory function that determines where to store JSONP callbacks.
1941
 *
1942
 * Ordinarily JSONP callbacks are stored on the `window` object, but this may not exist
1943
 * in test environments. In that case, callbacks are stored on an anonymous object instead.
1944
 *
1945
 * \@experimental
1946
 * @return {?}
1947
 */
1948
function jsonpCallbackContext() {
1949
    if (typeof window === 'object') {
1950
        return window;
1951
    }
1952
    return {};
1953
}
1954
/**
1955
 * `NgModule` which adds XSRF protection support to outgoing requests.
1956
 *
1957
 * Provided the server supports a cookie-based XSRF protection system, this
1958
 * module can be used directly to configure XSRF protection with the correct
1959
 * cookie and header names.
1960
 *
1961
 * If no such names are provided, the default is to use `X-XSRF-TOKEN` for
1962
 * the header name and `XSRF-TOKEN` for the cookie name.
1963
 *
1964
 * \@experimental
1965
 */
1966
class HttpClientXsrfModule {
1967
    /**
1968
     * Disable the default XSRF protection.
1969
     * @return {?}
1970
     */
1971
    static disable() {
1972
        return {
1973
            ngModule: HttpClientXsrfModule,
1974
            providers: [
1975
                { provide: HttpXsrfInterceptor, useClass: NoopInterceptor },
1976
            ],
1977
        };
1978
    }
1979
    /**
1980
     * Configure XSRF protection to use the given cookie name or header name,
1981
     * or the default names (as described above) if not provided.
1982
     * @param {?=} options
1983
     * @return {?}
1984
     */
1985
    static withOptions(options = {}) {
1986
        return {
1987
            ngModule: HttpClientXsrfModule,
1988
            providers: [
1989
                options.cookieName ? { provide: XSRF_COOKIE_NAME, useValue: options.cookieName } : [],
1990
                options.headerName ? { provide: XSRF_HEADER_NAME, useValue: options.headerName } : [],
1991
            ],
1992
        };
1993
    }
1994
}
1995
HttpClientXsrfModule.decorators = [
1996
    { type: NgModule, args: [{
1997
                providers: [
1998
                    HttpXsrfInterceptor,
1999
                    { provide: HTTP_INTERCEPTORS, useExisting: HttpXsrfInterceptor, multi: true },
2000
                    { provide: HttpXsrfTokenExtractor, useClass: HttpXsrfCookieExtractor },
2001
                    { provide: XSRF_COOKIE_NAME, useValue: 'XSRF-TOKEN' },
2002
                    { provide: XSRF_HEADER_NAME, useValue: 'X-XSRF-TOKEN' },
2003
                ],
2004
            },] },
2005
];
2006
/**
2007
 * @nocollapse
2008
 */
2009
HttpClientXsrfModule.ctorParameters = () => [];
2010
/**
2011
 * `NgModule` which provides the `HttpClient` and associated services.
2012
 *
2013
 * Interceptors can be added to the chain behind `HttpClient` by binding them
2014
 * to the multiprovider for `HTTP_INTERCEPTORS`.
2015
 *
2016
 * \@experimental
2017
 */
2018
class HttpClientModule {
2019
}
2020
HttpClientModule.decorators = [
2021
    { type: NgModule, args: [{
2022
                imports: [
2023
                    HttpClientXsrfModule.withOptions({
2024
                        cookieName: 'XSRF-TOKEN',
2025
                        headerName: 'X-XSRF-TOKEN',
2026
                    }),
2027
                ],
2028
                providers: [
2029
                    HttpClient,
2030
                    // HttpHandler is the backend + interceptors and is constructed
2031
                    // using the interceptingHandler factory function.
2032
                    {
2033
                        provide: HttpHandler,
2034
                        useFactory: interceptingHandler,
2035
                        deps: [HttpBackend, [new Optional(), new Inject(HTTP_INTERCEPTORS)]],
2036
                    },
2037
                    HttpXhrBackend,
2038
                    { provide: HttpBackend, useExisting: HttpXhrBackend },
2039
                    BrowserXhr,
2040
                    { provide: XhrFactory, useExisting: BrowserXhr },
2041
                ],
2042
            },] },
2043
];
2044
/**
2045
 * @nocollapse
2046
 */
2047
HttpClientModule.ctorParameters = () => [];
2048
/**
2049
 * `NgModule` which enables JSONP support in `HttpClient`.
2050
 *
2051
 * Without this module, Jsonp requests will reach the backend
2052
 * with method JSONP, where they'll be rejected.
2053
 *
2054
 * \@experimental
2055
 */
2056
class HttpClientJsonpModule {
2057
}
2058
HttpClientJsonpModule.decorators = [
2059
    { type: NgModule, args: [{
2060
                providers: [
2061
                    JsonpClientBackend,
2062
                    { provide: JsonpCallbackContext, useFactory: jsonpCallbackContext },
2063
                    { provide: HTTP_INTERCEPTORS, useClass: JsonpInterceptor, multi: true },
2064
                ],
2065
            },] },
2066
];
2067
/**
2068
 * @nocollapse
2069
 */
2070
HttpClientJsonpModule.ctorParameters = () => [];
2071

    
2072
/**
2073
 * @license
2074
 * Copyright Google Inc. All Rights Reserved.
2075
 *
2076
 * Use of this source code is governed by an MIT-style license that can be
2077
 * found in the LICENSE file at https://angular.io/license
2078
 */
2079

    
2080
/**
2081
 * Generated bundle index. Do not edit.
2082
 */
2083

    
2084
export { HttpBackend, HttpHandler, HttpClient, HttpHeaders, HTTP_INTERCEPTORS, JsonpClientBackend, JsonpInterceptor, HttpClientJsonpModule, HttpClientModule, HttpClientXsrfModule, interceptingHandler as ɵinterceptingHandler, HttpParams, HttpUrlEncodingCodec, HttpRequest, HttpErrorResponse, HttpEventType, HttpHeaderResponse, HttpResponse, HttpResponseBase, HttpXhrBackend, XhrFactory, HttpXsrfTokenExtractor, NoopInterceptor as ɵa, JsonpCallbackContext as ɵb, jsonpCallbackContext as ɵc, BrowserXhr as ɵd, HttpXsrfCookieExtractor as ɵg, HttpXsrfInterceptor as ɵh, XSRF_COOKIE_NAME as ɵe, XSRF_HEADER_NAME as ɵf };
2085
//# sourceMappingURL=http.js.map
(3-3/8)