2015-06-13 00:50:19 -04:00
|
|
|
import {CONST_EXPR, CONST, isPresent} from 'angular2/src/facade/lang';
|
2015-04-29 02:07:55 -04:00
|
|
|
import {Headers} from './headers';
|
|
|
|
import {URLSearchParams} from './url_search_params';
|
|
|
|
import {RequestModesOpts, RequestMethods, RequestCacheOpts, RequestCredentialsOpts} from './enums';
|
2015-06-13 22:48:40 -04:00
|
|
|
import {IRequestOptions} from './interfaces';
|
2015-04-29 02:07:55 -04:00
|
|
|
import {Injectable} from 'angular2/di';
|
2015-06-13 00:50:19 -04:00
|
|
|
import {ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
2015-04-29 02:07:55 -04:00
|
|
|
|
2015-06-13 22:48:40 -04:00
|
|
|
export class RequestOptions implements IRequestOptions {
|
2015-06-13 00:50:19 -04:00
|
|
|
method: RequestMethods = RequestMethods.GET;
|
2015-04-29 02:07:55 -04:00
|
|
|
headers: Headers;
|
2015-06-13 18:49:05 -04:00
|
|
|
body: URLSearchParams | FormData | Blob | string;
|
2015-06-13 00:50:19 -04:00
|
|
|
mode: RequestModesOpts = RequestModesOpts.Cors;
|
2015-04-29 02:07:55 -04:00
|
|
|
credentials: RequestCredentialsOpts;
|
|
|
|
cache: RequestCacheOpts;
|
2015-06-13 22:48:40 -04:00
|
|
|
constructor({method, headers, body, mode, credentials, cache}: IRequestOptions = {
|
|
|
|
method: RequestMethods.GET,
|
|
|
|
mode: RequestModesOpts.Cors
|
|
|
|
}) {
|
2015-06-13 00:50:19 -04:00
|
|
|
this.method = method;
|
|
|
|
this.headers = headers;
|
|
|
|
this.body = body;
|
|
|
|
this.mode = mode;
|
|
|
|
this.credentials = credentials;
|
|
|
|
this.cache = cache;
|
|
|
|
}
|
2015-04-29 02:07:55 -04:00
|
|
|
|
2015-06-13 22:48:40 -04:00
|
|
|
merge(opts: IRequestOptions = {}): RequestOptions {
|
|
|
|
return new RequestOptions(StringMapWrapper.merge(this, opts));
|
2015-04-29 02:07:55 -04:00
|
|
|
}
|
|
|
|
}
|
2015-06-13 00:50:19 -04:00
|
|
|
|
|
|
|
@Injectable()
|
2015-06-13 22:48:40 -04:00
|
|
|
export class BaseRequestOptions extends RequestOptions {
|
2015-06-13 00:50:19 -04:00
|
|
|
constructor() { super(); }
|
|
|
|
}
|