angular-cn/modules/angular2/src/http/static_request.ts

40 lines
1.6 KiB
TypeScript
Raw Normal View History

import {RequestMethods, RequestModesOpts, RequestCredentialsOpts} from './enums';
import {URLSearchParams} from './url_search_params';
import {IRequestOptions, Request as IRequest} from './interfaces';
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,
headers = new Headers()}: IRequestOptions = {}) {
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() : ''; }
}