X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions modules/angular2/src/http/base_request_options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CONST_EXPR, CONST, isPresent, isString} from 'angular2/src/core/facade/lang';
import {Headers} from './headers';
import {RequestModesOpts, RequestMethods, RequestCacheOpts, RequestCredentialsOpts} from './enums';
import {RequestMethods} from './enums';
import {RequestOptionsArgs} from './interfaces';
import {Injectable} from 'angular2/di';
import {URLSearchParams} from './url_search_params';
Expand Down Expand Up @@ -30,19 +30,13 @@ export class RequestOptions {
*/
// TODO: support FormData, Blob, URLSearchParams
body: string;
mode: RequestModesOpts;
credentials: RequestCredentialsOpts;
cache: RequestCacheOpts;
url: string;
search: URLSearchParams;
constructor({method, headers, body, mode, credentials, cache, url, search}:
constructor({method, headers, body, url, search}:
RequestOptionsArgs = {}) {
this.method = isPresent(method) ? method : null;
this.headers = isPresent(headers) ? headers : null;
this.body = isPresent(body) ? body : null;
this.mode = isPresent(mode) ? mode : null;
this.credentials = isPresent(credentials) ? credentials : null;
this.cache = isPresent(cache) ? cache : null;
this.url = isPresent(url) ? url : null;
this.search = isPresent(search) ? (isString(search) ? new URLSearchParams(<string>(search)) :
<URLSearchParams>(search)) :
Expand All @@ -58,10 +52,6 @@ export class RequestOptions {
method: isPresent(options) && isPresent(options.method) ? options.method : this.method,
headers: isPresent(options) && isPresent(options.headers) ? options.headers : this.headers,
body: isPresent(options) && isPresent(options.body) ? options.body : this.body,
mode: isPresent(options) && isPresent(options.mode) ? options.mode : this.mode,
credentials: isPresent(options) && isPresent(options.credentials) ? options.credentials :
this.credentials,
cache: isPresent(options) && isPresent(options.cache) ? options.cache : this.cache,
url: isPresent(options) && isPresent(options.url) ? options.url : this.url,
search: isPresent(options) && isPresent(options.search) ?
(isString(options.search) ? new URLSearchParams(<string>(options.search)) :
Expand Down Expand Up @@ -92,6 +82,6 @@ export class RequestOptions {
@Injectable()
export class BaseRequestOptions extends RequestOptions {
constructor() {
super({method: RequestMethods.Get, headers: new Headers(), mode: RequestModesOpts.Cors});
super({method: RequestMethods.Get, headers: new Headers()});
}
}
8 changes: 1 addition & 7 deletions modules/angular2/src/http/static_request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {RequestMethods, RequestModesOpts, RequestCredentialsOpts, RequestCacheOpts} from './enums';
import {RequestMethods} from './enums';
import {RequestOptions} from './base_request_options';
import {Headers} from './headers';
import {
Expand Down Expand Up @@ -26,8 +26,6 @@ export class Request {
* Defaults to GET.
*/
method: RequestMethods;
mode: RequestModesOpts;
credentials: RequestCredentialsOpts;
/**
* Headers object based on the `Headers` class in the [Fetch
* Spec](https://fetch.spec.whatwg.org/#headers-class). {@link Headers} class reference.
Expand All @@ -37,7 +35,6 @@ export class Request {
url: string;
// TODO: support URLSearchParams | FormData | Blob | ArrayBuffer
private _body: string;
cache: RequestCacheOpts;
constructor(requestOptions: RequestOptions) {
// TODO: assert that url is present
let url = requestOptions.url;
Expand All @@ -56,12 +53,9 @@ export class Request {
this._body = requestOptions.body;
this.method = requestOptions.method;
// TODO(jeffbcross): implement behavior
this.mode = requestOptions.mode;
// Defaults to 'omit', consistent with browser
// TODO(jeffbcross): implement behavior
this.credentials = requestOptions.credentials;
this.headers = new Headers(requestOptions.headers);
this.cache = requestOptions.cache;
}


Expand Down
6 changes: 2 additions & 4 deletions modules/angular2/test/http/base_request_options_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
xit
} from 'angular2/test_lib';
import {BaseRequestOptions, RequestOptions} from 'angular2/src/http/base_request_options';
import {RequestMethods, RequestModesOpts} from 'angular2/src/http/enums';
import {RequestMethods} from 'angular2/src/http/enums';

export function main() {
describe('BaseRequestOptions', () => {
Expand All @@ -24,9 +24,7 @@ export function main() {
it('should retain previously merged values when merging again', () => {
var options1 = new BaseRequestOptions();
var options2 = options1.merge(new RequestOptions({method: RequestMethods.Delete}));
var options3 = options2.merge(new RequestOptions({mode: RequestModesOpts.NoCors}));
expect(options3.mode).toBe(RequestModesOpts.NoCors);
expect(options3.method).toBe(RequestMethods.Delete);
expect(options2.method).toBe(RequestMethods.Delete);
});
});
}
X Tutup