Project

General

Profile

1
/**
2
 * @license Angular v4.4.6
3
 * (c) 2010-2017 Google, Inc. https://angular.io/
4
 * License: MIT
5
 */
6
(function (global, factory) {
7
	typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/Observable'), require('@angular/platform-browser')) :
8
	typeof define === 'function' && define.amd ? define(['exports', '@angular/core', 'rxjs/Observable', '@angular/platform-browser'], factory) :
9
	(factory((global.ng = global.ng || {}, global.ng.http = global.ng.http || {}),global.ng.core,global.Rx,global.ng.platformBrowser));
10
}(this, (function (exports,_angular_core,rxjs_Observable,_angular_platformBrowser) { 'use strict';
11

    
12
/*! *****************************************************************************
13
Copyright (c) Microsoft Corporation. All rights reserved.
14
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
15
this file except in compliance with the License. You may obtain a copy of the
16
License at http://www.apache.org/licenses/LICENSE-2.0
17

    
18
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
20
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
21
MERCHANTABLITY OR NON-INFRINGEMENT.
22

    
23
See the Apache Version 2.0 License for specific language governing permissions
24
and limitations under the License.
25
***************************************************************************** */
26
/* global Reflect, Promise */
27

    
28
var extendStatics = Object.setPrototypeOf ||
29
    ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
30
    function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
31

    
32
function __extends(d, b) {
33
    extendStatics(d, b);
34
    function __() { this.constructor = d; }
35
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
36
}
37

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

    
2193
exports.BrowserXhr = BrowserXhr;
2194
exports.JSONPBackend = JSONPBackend;
2195
exports.JSONPConnection = JSONPConnection;
2196
exports.CookieXSRFStrategy = CookieXSRFStrategy;
2197
exports.XHRBackend = XHRBackend;
2198
exports.XHRConnection = XHRConnection;
2199
exports.BaseRequestOptions = BaseRequestOptions;
2200
exports.RequestOptions = RequestOptions;
2201
exports.BaseResponseOptions = BaseResponseOptions;
2202
exports.ResponseOptions = ResponseOptions;
2203
exports.ReadyState = ReadyState;
2204
exports.RequestMethod = RequestMethod;
2205
exports.ResponseContentType = ResponseContentType;
2206
exports.ResponseType = ResponseType;
2207
exports.Headers = Headers;
2208
exports.Http = Http;
2209
exports.Jsonp = Jsonp;
2210
exports.HttpModule = HttpModule;
2211
exports.JsonpModule = JsonpModule;
2212
exports.Connection = Connection;
2213
exports.ConnectionBackend = ConnectionBackend;
2214
exports.XSRFStrategy = XSRFStrategy;
2215
exports.Request = Request;
2216
exports.Response = Response;
2217
exports.QueryEncoder = QueryEncoder;
2218
exports.URLSearchParams = URLSearchParams;
2219
exports.VERSION = VERSION;
2220
exports.ɵg = BrowserJsonp;
2221
exports.ɵa = JSONPBackend_;
2222
exports.ɵf = Body;
2223
exports.ɵb = _createDefaultCookieXSRFStrategy;
2224
exports.ɵc = httpFactory;
2225
exports.ɵd = jsonpFactory;
2226

    
2227
Object.defineProperty(exports, '__esModule', { value: true });
2228

    
2229
})));
2230
//# sourceMappingURL=http.umd.js.map
(5-5/8)