2016-06-23 09:47:54 -07: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-12-03 22:44:14 +01:00
|
|
|
import {ReadyState, RequestMethod, ResponseType} from './enums';
|
2015-04-28 23:07:55 -07:00
|
|
|
import {Headers} from './headers';
|
2015-06-19 12:14:12 -07:00
|
|
|
import {Request} from './static_request';
|
2015-09-25 13:23:05 +03:00
|
|
|
import {URLSearchParams} from './url_search_params';
|
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-10-06 06:53:39 -07:00
|
|
|
export abstract class ConnectionBackend { abstract createConnection(request: any): Connection; }
|
2015-06-19 12:14:12 -07:00
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
|
|
|
* Abstract class from which real connections are derived.
|
|
|
|
*/
|
2015-09-25 14:48:17 -07:00
|
|
|
export abstract class Connection {
|
2015-12-03 22:44:14 +01:00
|
|
|
readyState: ReadyState;
|
2015-06-19 12:14:12 -07:00
|
|
|
request: Request;
|
2015-10-01 16:04:20 -07:00
|
|
|
response: any; // TODO: generic of <Response>;
|
2015-06-19 12:14:12 -07:00
|
|
|
}
|
2015-04-28 23:07:55 -07:00
|
|
|
|
2016-05-27 20:15:40 -07:00
|
|
|
/** An XSRFStrategy configures XSRF protection (e.g. via headers) on an HTTP request. */
|
2016-06-08 16:38:52 -07:00
|
|
|
export abstract class XSRFStrategy { abstract configureRequest(req: Request): void; }
|
2016-05-27 20:15:40 -07:00
|
|
|
|
2015-06-24 00:27:07 -07:00
|
|
|
/**
|
2015-10-10 19:37:29 +03:00
|
|
|
* Interface for options to construct a RequestOptions, based on
|
2015-06-24 00:27:07 -07:00
|
|
|
* [RequestInit](https://fetch.spec.whatwg.org/#requestinit) from the Fetch spec.
|
|
|
|
*/
|
2015-10-10 19:37:29 +03:00
|
|
|
export interface RequestOptionsArgs {
|
2015-06-19 12:14:12 -07:00
|
|
|
url?: string;
|
2016-06-08 16:38:52 -07:00
|
|
|
method?: string|RequestMethod;
|
|
|
|
search?: string|URLSearchParams;
|
2015-04-28 23:07:55 -07:00
|
|
|
headers?: Headers;
|
2016-02-26 12:25:55 +01:00
|
|
|
body?: any;
|
2016-02-24 22:57:35 +01:00
|
|
|
withCredentials?: boolean;
|
2015-04-28 23:07:55 -07:00
|
|
|
}
|
|
|
|
|
2015-10-10 19:37:29 +03:00
|
|
|
/**
|
|
|
|
* Required structure when constructing new Request();
|
|
|
|
*/
|
|
|
|
export interface RequestArgs extends RequestOptionsArgs { url: string; }
|
|
|
|
|
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-09-06 22:14:19 -07:00
|
|
|
export type ResponseOptionsArgs = {
|
2015-06-19 12:14:12 -07:00
|
|
|
// TODO: Support Blob, ArrayBuffer, JSON
|
2016-06-08 16:38:52 -07:00
|
|
|
body?: string | Object | FormData; status?: number; statusText?: string; headers?: Headers;
|
2015-12-03 22:44:14 +01:00
|
|
|
type?: ResponseType;
|
2015-04-28 23:07:55 -07:00
|
|
|
url?: string;
|
|
|
|
}
|