refactor(http): share 'body' logic between Request and Response
This commit is contained in:

committed by
Jeff Cross

parent
1266460386
commit
e7a8e2757b
@ -10,7 +10,7 @@ import {Injectable} from '@angular/core';
|
||||
|
||||
import {isPresent, isString} from '../src/facade/lang';
|
||||
|
||||
import {RequestMethod, ResponseBuffer} from './enums';
|
||||
import {RequestMethod, ResponseContentType} from './enums';
|
||||
import {Headers} from './headers';
|
||||
import {normalizeMethodName} from './http_utils';
|
||||
import {RequestOptionsArgs} from './interfaces';
|
||||
@ -72,10 +72,11 @@ export class RequestOptions {
|
||||
/*
|
||||
* Select a buffer to store the response, such as ArrayBuffer, Blob, Json (or Document)
|
||||
*/
|
||||
buffer: ResponseBuffer;
|
||||
|
||||
constructor({method, headers, body, url, search, withCredentials, buffer}: RequestOptionsArgs = {}) {
|
||||
responseType: ResponseContentType;
|
||||
|
||||
constructor(
|
||||
{method, headers, body, url, search, withCredentials,
|
||||
responseType}: RequestOptionsArgs = {}) {
|
||||
this.method = isPresent(method) ? normalizeMethodName(method) : null;
|
||||
this.headers = isPresent(headers) ? headers : null;
|
||||
this.body = isPresent(body) ? body : null;
|
||||
@ -84,7 +85,7 @@ export class RequestOptions {
|
||||
(isString(search) ? new URLSearchParams(<string>(search)) : <URLSearchParams>(search)) :
|
||||
null;
|
||||
this.withCredentials = isPresent(withCredentials) ? withCredentials : null;
|
||||
this.buffer = isPresent(buffer) ? buffer : null;
|
||||
this.responseType = isPresent(responseType) ? responseType : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,8 +125,9 @@ export class RequestOptions {
|
||||
this.search,
|
||||
withCredentials: isPresent(options) && isPresent(options.withCredentials) ?
|
||||
options.withCredentials :
|
||||
this.withCredentials,
|
||||
buffer: isPresent(options) && isPresent(options.buffer) ? options.buffer : this.buffer
|
||||
this.withCredentials,
|
||||
responseType: isPresent(options) && isPresent(options.responseType) ? options.responseType :
|
||||
this.responseType
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user