2015-07-28 13:10:25 -07:00
|
|
|
/// <reference path="../../angular2/typings/rx/rx.d.ts" />
|
2015-04-28 23:07:55 -07:00
|
|
|
|
|
|
|
import {
|
|
|
|
ReadyStates,
|
|
|
|
RequestModesOpts,
|
|
|
|
RequestMethods,
|
|
|
|
RequestCacheOpts,
|
|
|
|
RequestCredentialsOpts,
|
|
|
|
ResponseTypes
|
|
|
|
} from './enums';
|
|
|
|
import {Headers} from './headers';
|
2015-06-19 12:14:12 -07:00
|
|
|
import {BaseException} from 'angular2/src/facade/lang';
|
|
|
|
import {EventEmitter} from 'angular2/src/facade/async';
|
|
|
|
import {Request} from './static_request';
|
2015-07-13 14:47:10 -04:00
|
|
|
import {URLSearchParamsUnionFixer, URLSearchParams} from './url_search_params';
|
|
|
|
|
|
|
|
// Work around Dartanalyzer problem :(
|
|
|
|
const URLSearchParams_UnionFixer = URLSearchParamsUnionFixer;
|
2015-06-19 12:14:12 -07:00
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
|
|
|
* Abstract class from which real backends are derived.
|
|
|
|
*
|
|
|
|
* The primary purpose of a `ConnectionBackend` is to create new connections to fulfill a given
|
|
|
|
* {@link Request}.
|
|
|
|
*/
|
2015-06-19 12:14:12 -07:00
|
|
|
export class ConnectionBackend {
|
|
|
|
constructor() {}
|
|
|
|
createConnection(request: any): Connection { throw new BaseException('Abstract!'); }
|
|
|
|
}
|
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
|
|
|
* Abstract class from which real connections are derived.
|
|
|
|
*/
|
2015-06-19 12:14:12 -07:00
|
|
|
export class Connection {
|
|
|
|
readyState: ReadyStates;
|
|
|
|
request: Request;
|
2015-06-24 00:27:07 -07:00
|
|
|
response: EventEmitter; // TODO: generic of <Response>;
|
2015-06-19 12:14:12 -07:00
|
|
|
dispose(): void { throw new BaseException('Abstract!'); }
|
|
|
|
}
|
2015-04-28 23:07:55 -07:00
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
|
|
|
* Interface for options to construct a Request, based on
|
|
|
|
* [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
|
|
|
|
*/
|
2015-08-25 10:11:28 -07:00
|
|
|
// TODO(jeffbcross): Change to type declaration when #3828 is fixed
|
|
|
|
// https://github.com/angular/angular/issues/3828
|
|
|
|
export interface RequestOptionsArgs {
|
2015-06-19 12:14:12 -07:00
|
|
|
url?: string;
|
2015-04-28 23:07:55 -07:00
|
|
|
method?: RequestMethods;
|
2015-07-13 14:47:10 -04:00
|
|
|
search?: string | URLSearchParams;
|
2015-04-28 23:07:55 -07:00
|
|
|
headers?: Headers;
|
2015-06-19 12:14:12 -07:00
|
|
|
// TODO: Support Blob, ArrayBuffer, JSON, URLSearchParams, FormData
|
|
|
|
body?: string;
|
2015-04-28 23:07:55 -07:00
|
|
|
mode?: RequestModesOpts;
|
|
|
|
credentials?: RequestCredentialsOpts;
|
|
|
|
cache?: RequestCacheOpts;
|
|
|
|
}
|
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
|
|
|
* Interface for options to construct a Response, based on
|
|
|
|
* [ResponseInit](https://fetch.spec.whatwg.org/#responseinit) from the Fetch spec.
|
|
|
|
*/
|
2015-08-25 10:11:28 -07:00
|
|
|
export interface ResponseOptionsArgs {
|
2015-06-19 12:14:12 -07:00
|
|
|
// TODO: Support Blob, ArrayBuffer, JSON
|
|
|
|
body?: string | Object | FormData;
|
2015-04-28 23:07:55 -07:00
|
|
|
status?: number;
|
|
|
|
statusText?: string;
|
2015-06-24 00:27:07 -07:00
|
|
|
headers?: Headers;
|
2015-04-28 23:07:55 -07:00
|
|
|
type?: ResponseTypes;
|
|
|
|
url?: string;
|
|
|
|
}
|