fix(http): restructure exports so that we don't leak private factory functions (#11016)
Ref #10615
This commit is contained in:
parent
c7a874dd2f
commit
7dfcaac730
|
@ -16,64 +16,22 @@ import {NgModule} from '@angular/core';
|
||||||
|
|
||||||
import {BrowserJsonp} from './src/backends/browser_jsonp';
|
import {BrowserJsonp} from './src/backends/browser_jsonp';
|
||||||
import {BrowserXhr} from './src/backends/browser_xhr';
|
import {BrowserXhr} from './src/backends/browser_xhr';
|
||||||
import {JSONPBackend, JSONPBackend_, JSONPConnection} from './src/backends/jsonp_backend';
|
import {JSONPBackend, JSONPBackend_} from './src/backends/jsonp_backend';
|
||||||
import {CookieXSRFStrategy, XHRBackend, XHRConnection} from './src/backends/xhr_backend';
|
import {CookieXSRFStrategy, XHRBackend} from './src/backends/xhr_backend';
|
||||||
import {BaseRequestOptions, RequestOptions} from './src/base_request_options';
|
import {BaseRequestOptions, RequestOptions} from './src/base_request_options';
|
||||||
import {BaseResponseOptions, ResponseOptions} from './src/base_response_options';
|
import {BaseResponseOptions, ResponseOptions} from './src/base_response_options';
|
||||||
import {Http, Jsonp} from './src/http';
|
import {Http, Jsonp} from './src/http';
|
||||||
import {ConnectionBackend, XSRFStrategy} from './src/interfaces';
|
import {XSRFStrategy} from './src/interfaces';
|
||||||
|
|
||||||
export {BrowserXhr} from './src/backends/browser_xhr';
|
|
||||||
export {JSONPBackend, JSONPConnection} from './src/backends/jsonp_backend';
|
|
||||||
export {CookieXSRFStrategy, XHRBackend, XHRConnection} from './src/backends/xhr_backend';
|
|
||||||
export {BaseRequestOptions, RequestOptions} from './src/base_request_options';
|
|
||||||
export {BaseResponseOptions, ResponseOptions} from './src/base_response_options';
|
|
||||||
export {ReadyState, RequestMethod, ResponseContentType, ResponseType} from './src/enums';
|
|
||||||
export {Headers} from './src/headers';
|
|
||||||
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';
|
|
||||||
export {QueryEncoder, URLSearchParams} from './src/url_search_params';
|
|
||||||
|
|
||||||
const HTTP_PROVIDERS: any[] = [
|
|
||||||
// TODO(pascal): use factory type annotations once supported in DI
|
|
||||||
// issue: https://github.com/angular/angular/issues/3183
|
|
||||||
{provide: Http, useFactory: httpFactory, deps: [XHRBackend, RequestOptions]},
|
|
||||||
BrowserXhr,
|
|
||||||
{provide: RequestOptions, useClass: BaseRequestOptions},
|
|
||||||
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
|
||||||
XHRBackend,
|
|
||||||
{provide: XSRFStrategy, useFactory: _createDefaultCookieXSRFStrategy},
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental
|
|
||||||
*/
|
|
||||||
export function _createDefaultCookieXSRFStrategy() {
|
export function _createDefaultCookieXSRFStrategy() {
|
||||||
return new CookieXSRFStrategy();
|
return new CookieXSRFStrategy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental
|
|
||||||
*/
|
|
||||||
export function httpFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http {
|
export function httpFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http {
|
||||||
return new Http(xhrBackend, requestOptions);
|
return new Http(xhrBackend, requestOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
const JSONP_PROVIDERS: any[] = [
|
|
||||||
// TODO(pascal): use factory type annotations once supported in DI
|
|
||||||
// issue: https://github.com/angular/angular/issues/3183
|
|
||||||
{provide: Jsonp, useFactory: jsonpFactory, deps: [JSONPBackend, RequestOptions]},
|
|
||||||
BrowserJsonp,
|
|
||||||
{provide: RequestOptions, useClass: BaseRequestOptions},
|
|
||||||
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
|
||||||
{provide: JSONPBackend, useClass: JSONPBackend_},
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @experimental
|
|
||||||
*/
|
|
||||||
export function jsonpFactory(jsonpBackend: JSONPBackend, requestOptions: RequestOptions): Jsonp {
|
export function jsonpFactory(jsonpBackend: JSONPBackend, requestOptions: RequestOptions): Jsonp {
|
||||||
return new Jsonp(jsonpBackend, requestOptions);
|
return new Jsonp(jsonpBackend, requestOptions);
|
||||||
}
|
}
|
||||||
|
@ -85,7 +43,6 @@ export function jsonpFactory(jsonpBackend: JSONPBackend, requestOptions: Request
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
@NgModule({
|
@NgModule({
|
||||||
// TODO(alxhub): switch back to HTTP_PROVIDERS when the metadata collector can inline it
|
|
||||||
providers: [
|
providers: [
|
||||||
// TODO(pascal): use factory type annotations once supported in DI
|
// TODO(pascal): use factory type annotations once supported in DI
|
||||||
// issue: https://github.com/angular/angular/issues/3183
|
// issue: https://github.com/angular/angular/issues/3183
|
||||||
|
@ -106,7 +63,6 @@ export class HttpModule {
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
@NgModule({
|
@NgModule({
|
||||||
// TODO(alxhub): switch back to JSONP_PROVIDERS when the metadata collector can inline it
|
|
||||||
providers: [
|
providers: [
|
||||||
// TODO(pascal): use factory type annotations once supported in DI
|
// TODO(pascal): use factory type annotations once supported in DI
|
||||||
// issue: https://github.com/angular/angular/issues/3183
|
// issue: https://github.com/angular/angular/issues/3183
|
||||||
|
|
|
@ -6,4 +6,16 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './http';
|
export {HttpModule, JsonpModule} from './http';
|
||||||
|
export {BrowserXhr} from './src/backends/browser_xhr';
|
||||||
|
export {JSONPBackend, JSONPConnection} from './src/backends/jsonp_backend';
|
||||||
|
export {CookieXSRFStrategy, XHRBackend, XHRConnection} from './src/backends/xhr_backend';
|
||||||
|
export {BaseRequestOptions, RequestOptions} from './src/base_request_options';
|
||||||
|
export {BaseResponseOptions, ResponseOptions} from './src/base_response_options';
|
||||||
|
export {ReadyState, RequestMethod, ResponseContentType, ResponseType} from './src/enums';
|
||||||
|
export {Headers} from './src/headers';
|
||||||
|
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';
|
||||||
|
export {QueryEncoder, URLSearchParams} from './src/url_search_params';
|
||||||
|
|
|
@ -13,7 +13,7 @@ import {expect} from '@angular/platform-browser/testing/matchers';
|
||||||
import {Observable} from 'rxjs/Observable';
|
import {Observable} from 'rxjs/Observable';
|
||||||
import {zip} from 'rxjs/observable/zip';
|
import {zip} from 'rxjs/observable/zip';
|
||||||
|
|
||||||
import {BaseRequestOptions, ConnectionBackend, Http, HttpModule, JSONPBackend, Jsonp, JsonpModule, Request, RequestMethod, RequestOptions, Response, ResponseContentType, ResponseOptions, URLSearchParams, XHRBackend} from '../http';
|
import {BaseRequestOptions, ConnectionBackend, Http, HttpModule, JSONPBackend, Jsonp, JsonpModule, Request, RequestMethod, RequestOptions, Response, ResponseContentType, ResponseOptions, URLSearchParams, XHRBackend} from '../index';
|
||||||
import {Json} from '../src/facade/lang';
|
import {Json} from '../src/facade/lang';
|
||||||
import {stringToArrayBuffer} from '../src/http_utils';
|
import {stringToArrayBuffer} from '../src/http_utils';
|
||||||
import {MockBackend, MockConnection} from '../testing/mock_backend';
|
import {MockBackend, MockConnection} from '../testing/mock_backend';
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
/** @experimental */
|
|
||||||
export declare function _createDefaultCookieXSRFStrategy(): CookieXSRFStrategy;
|
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare class BaseRequestOptions extends RequestOptions {
|
export declare class BaseRequestOptions extends RequestOptions {
|
||||||
constructor();
|
constructor();
|
||||||
|
@ -71,9 +68,6 @@ export declare class Http {
|
||||||
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response>;
|
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @experimental */
|
|
||||||
export declare function httpFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http;
|
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare class HttpModule {
|
export declare class HttpModule {
|
||||||
}
|
}
|
||||||
|
@ -96,9 +90,6 @@ export declare abstract class JSONPConnection implements Connection {
|
||||||
abstract finished(data?: any): void;
|
abstract finished(data?: any): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @experimental */
|
|
||||||
export declare function jsonpFactory(jsonpBackend: JSONPBackend, requestOptions: RequestOptions): Jsonp;
|
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare class JsonpModule {
|
export declare class JsonpModule {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue