2016-06-23 12:47:54 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2015-07-28 16:10:25 -04:00
|
|
|
/**
|
|
|
|
* @module
|
|
|
|
* @description
|
|
|
|
* The http module provides services to perform http requests. To get started, see the {@link Http}
|
|
|
|
* class.
|
|
|
|
*/
|
2016-07-27 16:09:05 -04:00
|
|
|
import {NgModule} from '@angular/core';
|
2016-06-08 19:38:52 -04:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {BrowserJsonp} from './src/backends/browser_jsonp';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {BrowserXhr} from './src/backends/browser_xhr';
|
|
|
|
import {JSONPBackend, JSONPBackend_, JSONPConnection} from './src/backends/jsonp_backend';
|
|
|
|
import {CookieXSRFStrategy, XHRBackend, XHRConnection} from './src/backends/xhr_backend';
|
2016-04-28 20:50:03 -04:00
|
|
|
import {BaseRequestOptions, RequestOptions} from './src/base_request_options';
|
|
|
|
import {BaseResponseOptions, ResponseOptions} from './src/base_response_options';
|
2016-06-08 19:38:52 -04:00
|
|
|
import {Http, Jsonp} from './src/http';
|
|
|
|
import {ConnectionBackend, XSRFStrategy} from './src/interfaces';
|
2015-07-28 16:10:25 -04:00
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
export {BrowserXhr} from './src/backends/browser_xhr';
|
2016-06-08 19:38:52 -04:00
|
|
|
export {JSONPBackend, JSONPConnection} from './src/backends/jsonp_backend';
|
|
|
|
export {CookieXSRFStrategy, XHRBackend, XHRConnection} from './src/backends/xhr_backend';
|
2016-04-28 20:50:03 -04:00
|
|
|
export {BaseRequestOptions, RequestOptions} from './src/base_request_options';
|
|
|
|
export {BaseResponseOptions, ResponseOptions} from './src/base_response_options';
|
2016-05-26 18:47:20 -04:00
|
|
|
export {ReadyState, RequestMethod, ResponseContentType, ResponseType} from './src/enums';
|
2016-04-28 20:50:03 -04:00
|
|
|
export {Headers} from './src/headers';
|
2016-06-08 19:38:52 -04:00
|
|
|
export {Http, Jsonp} from './src/http';
|
|
|
|
export {Connection, ConnectionBackend, RequestOptionsArgs, ResponseOptionsArgs, XSRFStrategy} from './src/interfaces';
|
|
|
|
export {Request} from './src/static_request';
|
|
|
|
export {Response} from './src/static_response';
|
2016-06-28 14:31:35 -04:00
|
|
|
export {QueryEncoder, URLSearchParams} from './src/url_search_params';
|
|
|
|
|
2016-08-17 10:43:31 -04:00
|
|
|
const HTTP_PROVIDERS: any[] = [
|
2015-07-30 10:29:16 -04:00
|
|
|
// TODO(pascal): use factory type annotations once supported in DI
|
|
|
|
// issue: https://github.com/angular/angular/issues/3183
|
2016-06-08 19:38:52 -04:00
|
|
|
{provide: Http, useFactory: httpFactory, deps: [XHRBackend, RequestOptions]},
|
2016-04-12 12:40:37 -04:00
|
|
|
BrowserXhr,
|
2016-06-02 20:30:40 -04:00
|
|
|
{provide: RequestOptions, useClass: BaseRequestOptions},
|
|
|
|
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
2016-05-27 23:15:40 -04:00
|
|
|
XHRBackend,
|
2016-07-27 16:09:05 -04:00
|
|
|
{provide: XSRFStrategy, useFactory: _createDefaultCookieXSRFStrategy},
|
2015-07-28 16:10:25 -04:00
|
|
|
];
|
|
|
|
|
2016-07-27 16:09:05 -04:00
|
|
|
/**
|
|
|
|
* @experimental
|
|
|
|
*/
|
|
|
|
export function _createDefaultCookieXSRFStrategy() {
|
|
|
|
return new CookieXSRFStrategy();
|
|
|
|
}
|
2016-06-27 15:27:23 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @experimental
|
|
|
|
*/
|
2016-06-01 17:58:11 -04:00
|
|
|
export function httpFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http {
|
2016-06-02 20:30:40 -04:00
|
|
|
return new Http(xhrBackend, requestOptions);
|
|
|
|
}
|
|
|
|
|
2016-08-17 10:43:31 -04:00
|
|
|
const JSONP_PROVIDERS: any[] = [
|
2015-07-30 10:29:16 -04:00
|
|
|
// TODO(pascal): use factory type annotations once supported in DI
|
|
|
|
// issue: https://github.com/angular/angular/issues/3183
|
2016-06-02 20:30:40 -04:00
|
|
|
{provide: Jsonp, useFactory: jsonpFactory, deps: [JSONPBackend, RequestOptions]},
|
2016-04-12 12:40:37 -04:00
|
|
|
BrowserJsonp,
|
2016-06-02 20:30:40 -04:00
|
|
|
{provide: RequestOptions, useClass: BaseRequestOptions},
|
|
|
|
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
|
|
|
{provide: JSONPBackend, useClass: JSONPBackend_},
|
2015-07-28 16:10:25 -04:00
|
|
|
];
|
2015-10-11 01:11:13 -04:00
|
|
|
|
2016-08-12 14:30:12 -04:00
|
|
|
/**
|
|
|
|
* @experimental
|
|
|
|
*/
|
|
|
|
export function jsonpFactory(jsonpBackend: JSONPBackend, requestOptions: RequestOptions): Jsonp {
|
2016-06-02 20:30:40 -04:00
|
|
|
return new Jsonp(jsonpBackend, requestOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-27 16:09:05 -04:00
|
|
|
/**
|
|
|
|
* The module that includes http's providers
|
|
|
|
*
|
|
|
|
* @experimental
|
|
|
|
*/
|
|
|
|
@NgModule({providers: HTTP_PROVIDERS})
|
|
|
|
export class HttpModule {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The module that includes jsonp's providers
|
|
|
|
*
|
|
|
|
* @experimental
|
|
|
|
*/
|
|
|
|
@NgModule({providers: JSONP_PROVIDERS})
|
|
|
|
export class JsonpModule {
|
|
|
|
}
|