{"version":3,"file":"http.umd.min.js","sources":["../../../../packages/http/src/static_request.ts","../../../../packages/http/src/http.ts","../../../../packages/http/src/http_module.ts","../../../../packages/http/src/base_request_options.ts","../../../../packages/http/src/backends/xhr_backend.ts","../../../../packages/http/src/backends/jsonp_backend.ts","../../../../packages/http/src/http_utils.ts","../../../../packages/http/src/url_search_params.ts","../../../../packages/http/src/body.ts","../../../../packages/http/src/static_response.ts","../../../../packages/http/src/backends/browser_jsonp.ts","../../../../node_modules/tslib/tslib.es6.js","../../../../packages/http/src/enums.ts","../../../../packages/http/src/headers.ts","../../../../packages/http/src/base_response_options.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n\nimport {Body} from './body';\nimport {ContentType, RequestMethod, ResponseContentType} from './enums';\nimport {Headers} from './headers';\nimport {normalizeMethodName} from './http_utils';\nimport {RequestArgs} from './interfaces';\nimport {URLSearchParams} from './url_search_params';\n/**\n * Creates `Request` instances from provided values.\n * \n * The Request's interface is inspired by the Request constructor defined in the [Fetch\n * Spec](https://fetch.spec.whatwg.org/#request-class),\n * but is considered a static value whose body can be accessed many times. There are other\n * differences in the implementation, but this is the most significant.\n * \n * `Request` instances are typically created by higher-level classes, like {\\@link Http} and\n * {\\@link Jsonp}, but it may occasionally be useful to explicitly create `Request` instances.\n * One such example is when creating services that wrap higher-level services, like {\\@link Http},\n * where it may be useful to generate a `Request` with arbitrary headers and search params.\n * \n * ```typescript\n * import {Injectable, Injector} from '\\@angular/core';\n * import {HTTP_PROVIDERS, Http, Request, RequestMethod} from '\\@angular/http';\n * \n * \\@Injectable() \n * class AutoAuthenticator {\n * constructor(public http:Http) {}\n * request(url:string) {\n * return this.http.request(new Request({\n * method: RequestMethod.Get,\n * url: url,\n * search: 'password=123'\n * }));\n * }\n * }\n * \n * var injector = Injector.resolveAndCreate([HTTP_PROVIDERS, AutoAuthenticator]);\n * var authenticator = injector.get(AutoAuthenticator);\n * authenticator.request('people.json').subscribe(res => {\n * //URL should have included '?password=123'\n * console.log('people', res.json());\n * });\n * ```\n * \n * \\@experimental\n */\nexport class Request extends Body {\n/**\n * Http method with which to perform the request.\n */\nmethod: RequestMethod;\n/**\n * {\\@link Headers} instance\n */\nheaders: Headers;\n/**\n * Url of the remote resource\n */\nurl: string;\n/**\n * Type of the request body *\n */\nprivate contentType: ContentType;\n/**\n * Enable use credentials\n */\nwithCredentials: boolean;\n/**\n * Buffer to store the response\n */\nresponseType: ResponseContentType;\n/**\n * @param {?} requestOptions\n */\nconstructor(requestOptions: RequestArgs) {\n super();\n // TODO: assert that url is present\n const url = requestOptions.url;\n this.url = requestOptions.url !;\n const paramsArg = requestOptions.params || requestOptions.search;\n if (paramsArg) {\n let params: string;\n if (typeof paramsArg === 'object' && !(paramsArg instanceof URLSearchParams)) {\n params = urlEncodeParams(paramsArg).toString();\n } else {\n params = paramsArg.toString();\n }\n if (params.length > 0) {\n let prefix = '?';\n if (this.url.indexOf('?') != -1) {\n prefix = (this.url[this.url.length - 1] == '&') ? '' : '&';\n }\n // TODO: just delete search-query-looking string in url?\n this.url = url + prefix + params;\n }\n }\n this._body = requestOptions.body;\n this.method = normalizeMethodName(requestOptions.method !);\n // TODO(jeffbcross): implement behavior\n // Defaults to 'omit', consistent with browser\n this.headers = new Headers(requestOptions.headers);\n this.contentType = this.detectContentType();\n this.withCredentials = requestOptions.withCredentials !;\n this.responseType = requestOptions.responseType !;\n }\n/**\n * Returns the content type enum based on header options.\n * @return {?}\n */\ndetectContentType(): ContentType {\n switch (this.headers.get('content-type')) {\n case 'application/json':\n return ContentType.JSON;\n case 'application/x-www-form-urlencoded':\n return ContentType.FORM;\n case 'multipart/form-data':\n return ContentType.FORM_DATA;\n case 'text/plain':\n case 'text/html':\n return ContentType.TEXT;\n case 'application/octet-stream':\n return this._body instanceof ArrayBuffer ? ContentType.ARRAY_BUFFER : ContentType.BLOB;\n default:\n return this.detectContentTypeFromBody();\n }\n }\n/**\n * Returns the content type of request's body based on its type.\n * @return {?}\n */\ndetectContentTypeFromBody(): ContentType {\n if (this._body == null) {\n return ContentType.NONE;\n } else if (this._body instanceof URLSearchParams) {\n return ContentType.FORM;\n } else if (this._body instanceof FormData) {\n return ContentType.FORM_DATA;\n } else if (this._body instanceof Blob) {\n return ContentType.BLOB;\n } else if (this._body instanceof ArrayBuffer) {\n return ContentType.ARRAY_BUFFER;\n } else if (this._body && typeof this._body === 'object') {\n return ContentType.JSON;\n } else {\n return ContentType.TEXT;\n }\n }\n/**\n * Returns the request's body according to its type. If body is undefined, return\n * null.\n * @return {?}\n */\ngetBody(): any {\n switch (this.contentType) {\n case ContentType.JSON:\n return this.text();\n case ContentType.FORM:\n return this.text();\n case ContentType.FORM_DATA:\n return this._body;\n case ContentType.TEXT:\n return this.text();\n case ContentType.BLOB:\n return this.blob();\n case ContentType.ARRAY_BUFFER:\n return this.arrayBuffer();\n default:\n return null;\n }\n }\n}\n\nfunction Request_tsickle_Closure_declarations() {\n/**\n * Http method with which to perform the request.\n * @type {?}\n */\nRequest.prototype.method;\n/**\n * {\\@link Headers} instance\n * @type {?}\n */\nRequest.prototype.headers;\n/**\n * Url of the remote resource\n * @type {?}\n */\nRequest.prototype.url;\n/**\n * Type of the request body *\n * @type {?}\n */\nRequest.prototype.contentType;\n/**\n * Enable use credentials\n * @type {?}\n */\nRequest.prototype.withCredentials;\n/**\n * Buffer to store the response\n * @type {?}\n */\nRequest.prototype.responseType;\n}\n\n/**\n * @param {?} params\n * @return {?}\n */\nfunction urlEncodeParams(params: {[key: string]: any}): URLSearchParams {\n const /** @type {?} */ searchParams = new URLSearchParams();\n Object.keys(params).forEach(key => {\n const /** @type {?} */ value = params[key];\n if (value && Array.isArray(value)) {\n value.forEach(element => searchParams.append(key, element.toString()));\n } else {\n searchParams.append(key, value.toString());\n }\n });\n return searchParams;\n}\n\nconst /** @type {?} */ noop = function() {};\nconst /** @type {?} */ w = typeof window == 'object' ? window : noop;\nconst /** @type {?} */ FormData = ( /** @type {?} */((w as any)) /** TODO #9100 */)['FormData'] || noop;\nconst /** @type {?} */ Blob = ( /** @type {?} */((w as any)) /** TODO #9100 */)['Blob'] || noop;\nexport const /** @type {?} */ ArrayBuffer: ArrayBufferConstructor =\n ( /** @type {?} */((w as any)) /** TODO #9100 */)['ArrayBuffer'] || noop;\n","/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n\nimport {Injectable} from '@angular/core';\nimport {Observable} from 'rxjs/Observable';\n\nimport {BaseRequestOptions, RequestOptions} from './base_request_options';\nimport {RequestMethod} from './enums';\nimport {ConnectionBackend, RequestArgs, RequestOptionsArgs} from './interfaces';\nimport {Request} from './static_request';\nimport {Response} from './static_response';\n/**\n * @param {?} backend\n * @param {?} request\n * @return {?}\n */\nfunction httpRequest(backend: ConnectionBackend, request: Request): Observable {\n return backend.createConnection(request).response;\n}\n/**\n * @param {?} defaultOpts\n * @param {?} providedOpts\n * @param {?} method\n * @param {?} url\n * @return {?}\n */\nfunction mergeOptions(\n defaultOpts: BaseRequestOptions, providedOpts: RequestOptionsArgs | undefined,\n method: RequestMethod, url: string): RequestArgs {\n const /** @type {?} */ newOptions = defaultOpts;\n if (providedOpts) {\n // Hack so Dart can used named parameters\n return /** @type {?} */(( newOptions.merge(new RequestOptions({\n method: providedOpts.method || method,\n url: providedOpts.url || url,\n search: providedOpts.search,\n params: providedOpts.params,\n headers: providedOpts.headers,\n body: providedOpts.body,\n withCredentials: providedOpts.withCredentials,\n responseType: providedOpts.responseType\n })) as RequestArgs));\n }\n\n return /** @type {?} */(( newOptions.merge(new RequestOptions({method, url})) as RequestArgs));\n}\n/**\n * Performs http requests using `XMLHttpRequest` as the default backend.\n * \n * `Http` is available as an injectable class, with methods to perform http requests. Calling\n * `request` returns an `Observable` which will emit a single {\\@link Response} when a\n * response is received.\n * \n * ### Example\n * \n * ```typescript\n * import {Http, HTTP_PROVIDERS} from '\\@angular/http';\n * import 'rxjs/add/operator/map'\n * \\@Component({ \n * selector: 'http-app',\n * viewProviders: [HTTP_PROVIDERS],\n * templateUrl: 'people.html'\n * })\n * class PeopleComponent {\n * constructor(http: Http) {\n * http.get('people.json')\n * // Call map on the response observable to get the parsed people object\n * .map(res => res.json())\n * // Subscribe to the observable to get the parsed people object and attach it to the\n * // component\n * .subscribe(people => this.people = people);\n * }\n * }\n * ```\n * \n * \n * ### Example\n * \n * ```\n * http.get('people.json').subscribe((res:Response) => this.people = res.json());\n * ```\n * \n * The default construct used to perform requests, `XMLHttpRequest`, is abstracted as a \"Backend\" (\n * {\\@link XHRBackend} in this case), which could be mocked with dependency injection by replacing\n * the {\\@link XHRBackend} provider, as in the following example:\n * \n * ### Example\n * \n * ```typescript\n * import {BaseRequestOptions, Http} from '\\@angular/http';\n * import {MockBackend} from '\\@angular/http/testing';\n * var injector = Injector.resolveAndCreate([\n * BaseRequestOptions,\n * MockBackend,\n * {provide: Http, useFactory:\n * function(backend, defaultOptions) {\n * return new Http(backend, defaultOptions);\n * },\n * deps: [MockBackend, BaseRequestOptions]}\n * ]);\n * var http = injector.get(Http);\n * http.get('request-from-mock-backend.json').subscribe((res:Response) => doSomething(res));\n * ```\n * \n * \\@experimental\n */\nexport class Http {\n/**\n * @param {?} _backend\n * @param {?} _defaultOptions\n */\nconstructor(protected _backend: ConnectionBackend, protected _defaultOptions: RequestOptions) {}\n/**\n * Performs any type of http request. First argument is required, and can either be a url or\n * a {\\@link Request} instance. If the first argument is a url, an optional {\\@link RequestOptions}\n * object can be provided as the 2nd argument. The options object will be merged with the values\n * of {\\@link BaseRequestOptions} before performing the request.\n * @param {?} url\n * @param {?=} options\n * @return {?}\n */\nrequest(url: string|Request, options?: RequestOptionsArgs): Observable {\n let /** @type {?} */ responseObservable: any;\n if (typeof url === 'string') {\n responseObservable = httpRequest(\n this._backend,\n new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, /** @type {?} */(( url)))));\n } else if (url instanceof Request) {\n responseObservable = httpRequest(this._backend, url);\n } else {\n throw new Error('First argument must be a url string or Request instance.');\n }\n return responseObservable;\n }\n/**\n * Performs a request with `get` http method.\n * @param {?} url\n * @param {?=} options\n * @return {?}\n */\nget(url: string, options?: RequestOptionsArgs): Observable {\n return this.request(\n new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Get, url)));\n }\n/**\n * Performs a request with `post` http method.\n * @param {?} url\n * @param {?} body\n * @param {?=} options\n * @return {?}\n */\npost(url: string, body: any, options?: RequestOptionsArgs): Observable {\n return this.request(new Request(mergeOptions(\n this._defaultOptions.merge(new RequestOptions({body: body})), options, RequestMethod.Post,\n url)));\n }\n/**\n * Performs a request with `put` http method.\n * @param {?} url\n * @param {?} body\n * @param {?=} options\n * @return {?}\n */\nput(url: string, body: any, options?: RequestOptionsArgs): Observable {\n return this.request(new Request(mergeOptions(\n this._defaultOptions.merge(new RequestOptions({body: body})), options, RequestMethod.Put,\n url)));\n }\n/**\n * Performs a request with `delete` http method.\n * @param {?} url\n * @param {?=} options\n * @return {?}\n */\ndelete (url: string, options?: RequestOptionsArgs): Observable {\n return this.request(\n new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Delete, url)));\n }\n/**\n * Performs a request with `patch` http method.\n * @param {?} url\n * @param {?} body\n * @param {?=} options\n * @return {?}\n */\npatch(url: string, body: any, options?: RequestOptionsArgs): Observable {\n return this.request(new Request(mergeOptions(\n this._defaultOptions.merge(new RequestOptions({body: body})), options, RequestMethod.Patch,\n url)));\n }\n/**\n * Performs a request with `head` http method.\n * @param {?} url\n * @param {?=} options\n * @return {?}\n */\nhead(url: string, options?: RequestOptionsArgs): Observable {\n return this.request(\n new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Head, url)));\n }\n/**\n * Performs a request with `options` http method.\n * @param {?} url\n * @param {?=} options\n * @return {?}\n */\noptions(url: string, options?: RequestOptionsArgs): Observable {\n return this.request(\n new Request(mergeOptions(this._defaultOptions, options, RequestMethod.Options, url)));\n }\nstatic decorators: DecoratorInvocation[] = [\n{ type: Injectable },\n];\n/**\n * @nocollapse\n */\nstatic ctorParameters: () => ({type: any, decorators?: DecoratorInvocation[]}|null)[] = () => [\n{type: ConnectionBackend, },\n{type: RequestOptions, },\n];\n}\n\nfunction Http_tsickle_Closure_declarations() {\n/** @type {?} */\nHttp.decorators;\n/**\n * @nocollapse\n * @type {?}\n */\nHttp.ctorParameters;\n/** @type {?} */\nHttp.prototype._backend;\n/** @type {?} */\nHttp.prototype._defaultOptions;\n}\n\n/**\n * \\@experimental\n */\nexport class Jsonp extends Http {\n/**\n * @param {?} backend\n * @param {?} defaultOptions\n */\nconstructor(backend: ConnectionBackend, defaultOptions: RequestOptions) {\n super(backend, defaultOptions);\n }\n/**\n * Performs any type of http request. First argument is required, and can either be a url or\n * a {\\@link Request} instance. If the first argument is a url, an optional {\\@link RequestOptions}\n * object can be provided as the 2nd argument. The options object will be merged with the values\n * of {\\@link BaseRequestOptions} before performing the request.\n * \n * \\@security Regular XHR is the safest alternative to JSONP for most applications, and is\n * supported by all current browsers. Because JSONP creates a `