chore(http): remove unused properties from Request

This removes properties mentioned in #3339

Closes #3339
Closes #3823
This commit is contained in:
Pascal Precht 2015-08-25 10:27:59 +02:00 committed by Jeff Cross
parent 2acc1ad08b
commit 5a3ce87915
6 changed files with 8 additions and 79 deletions

View File

@ -34,14 +34,7 @@ export {Http, Jsonp} from './src/http/http';
export {Headers} from './src/http/headers';
export {
ResponseTypes,
ReadyStates,
RequestMethods,
RequestCredentialsOpts,
RequestCacheOpts,
RequestModesOpts
} from './src/http/enums';
export {ResponseTypes, ReadyStates, RequestMethods} from './src/http/enums';
export {URLSearchParams} from './src/http/url_search_params';
/**

View File

@ -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/src/core/di';
import {URLSearchParams} from './url_search_params';
@ -30,19 +30,12 @@ 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}:
RequestOptionsArgs = {}) {
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)) :
@ -58,10 +51,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)) :
@ -91,7 +80,5 @@ export class RequestOptions {
*/
@Injectable()
export class BaseRequestOptions extends RequestOptions {
constructor() {
super({method: RequestMethods.Get, headers: new Headers(), mode: RequestModesOpts.Cors});
}
constructor() { super({method: RequestMethods.Get, headers: new Headers()}); }
}

View File

@ -1,38 +1,5 @@
import {StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
/**
* Acceptable origin modes to be associated with a {@link Request}, based on
* [RequestMode](https://fetch.spec.whatwg.org/#requestmode) from the Fetch spec.
*/
export enum RequestModesOpts {
Cors,
NoCors,
SameOrigin
}
/**
* Acceptable cache option to be associated with a {@link Request}, based on
* [RequestCache](https://fetch.spec.whatwg.org/#requestcache) from the Fetch spec.
*/
export enum RequestCacheOpts {
Default,
NoStore,
Reload,
NoCache,
ForceCache,
OnlyIfCached
}
/**
* Acceptable credentials option to be associated with a {@link Request}, based on
* [RequestCredentials](https://fetch.spec.whatwg.org/#requestcredentials) from the Fetch spec.
*/
export enum RequestCredentialsOpts {
Omit,
SameOrigin,
Include
}
/**
* Supported http methods.
*/

View File

@ -1,11 +1,4 @@
import {
ReadyStates,
RequestModesOpts,
RequestMethods,
RequestCacheOpts,
RequestCredentialsOpts,
ResponseTypes
} from './enums';
import {ReadyStates, RequestMethods, ResponseTypes} from './enums';
import {Headers} from './headers';
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
import {EventEmitter} from 'angular2/src/core/facade/async';
@ -49,9 +42,6 @@ export interface RequestOptionsArgs {
headers?: Headers;
// TODO: Support Blob, ArrayBuffer, JSON, URLSearchParams, FormData
body?: string;
mode?: RequestModesOpts;
credentials?: RequestCredentialsOpts;
cache?: RequestCacheOpts;
}
/**

View File

@ -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 {
@ -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.
@ -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;
@ -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;
}

View File

@ -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', () => {
@ -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);
});
});
}