2015-04-29 02:07:55 -04:00
|
|
|
import {RequestMethods, RequestModesOpts, RequestCredentialsOpts} from './enums';
|
|
|
|
import {URLSearchParams} from './url_search_params';
|
2015-06-13 22:48:40 -04:00
|
|
|
import {IRequestOptions, Request as IRequest} from './interfaces';
|
2015-04-29 02:07:55 -04:00
|
|
|
import {Headers} from './headers';
|
|
|
|
import {BaseException, RegExpWrapper} from 'angular2/src/facade/lang';
|
|
|
|
|
|
|
|
// TODO(jeffbcross): implement body accessors
|
|
|
|
export class Request implements IRequest {
|
|
|
|
method: RequestMethods;
|
|
|
|
mode: RequestModesOpts;
|
|
|
|
credentials: RequestCredentialsOpts;
|
|
|
|
headers: Headers;
|
|
|
|
/*
|
|
|
|
* Non-Standard Properties
|
|
|
|
*/
|
|
|
|
// This property deviates from the standard. Body can be set in constructor, but is only
|
|
|
|
// accessible
|
|
|
|
// via json(), text(), arrayBuffer(), and blob() accessors, which also change the request's state
|
|
|
|
// to "used".
|
|
|
|
private body: URLSearchParams | FormData | Blob | string;
|
|
|
|
|
|
|
|
constructor(public url: string, {body, method = RequestMethods.GET, mode = RequestModesOpts.Cors,
|
|
|
|
credentials = RequestCredentialsOpts.Omit,
|
2015-06-13 22:48:40 -04:00
|
|
|
headers = new Headers()}: IRequestOptions = {}) {
|
2015-04-29 02:07:55 -04:00
|
|
|
this.body = body;
|
|
|
|
// Defaults to 'GET', consistent with browser
|
|
|
|
this.method = method;
|
|
|
|
// Defaults to 'cors', consistent with browser
|
|
|
|
// TODO(jeffbcross): implement behavior
|
|
|
|
this.mode = mode;
|
|
|
|
// Defaults to 'omit', consistent with browser
|
|
|
|
// TODO(jeffbcross): implement behavior
|
|
|
|
this.credentials = credentials;
|
|
|
|
// Defaults to empty headers object, consistent with browser
|
|
|
|
this.headers = headers;
|
|
|
|
}
|
|
|
|
|
|
|
|
text(): String { return this.body ? this.body.toString() : ''; }
|
|
|
|
}
|