feat(http): add support for ArrayBuffer

Add the buffer option to store response in ArrayBuffer
Improve the interface to get back response independently of the buffer type
This commit is contained in:
Damien Cassan
2016-02-24 16:37:18 +01:00
committed by Jeff Cross
parent 0ccb6e0dfc
commit 1266460386
12 changed files with 218 additions and 29 deletions

View File

@ -10,7 +10,7 @@ import {Injectable} from '@angular/core';
import {isPresent, isString} from '../src/facade/lang';
import {RequestMethod} from './enums';
import {RequestMethod, ResponseBuffer} from './enums';
import {Headers} from './headers';
import {normalizeMethodName} from './http_utils';
import {RequestOptionsArgs} from './interfaces';
@ -69,7 +69,13 @@ export class RequestOptions {
* Enable use credentials for a {@link Request}.
*/
withCredentials: boolean;
constructor({method, headers, body, url, search, withCredentials}: RequestOptionsArgs = {}) {
/*
* 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 = {}) {
this.method = isPresent(method) ? normalizeMethodName(method) : null;
this.headers = isPresent(headers) ? headers : null;
this.body = isPresent(body) ? body : null;
@ -78,6 +84,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;
}
/**
@ -117,7 +124,8 @@ export class RequestOptions {
this.search,
withCredentials: isPresent(options) && isPresent(options.withCredentials) ?
options.withCredentials :
this.withCredentials
this.withCredentials,
buffer: isPresent(options) && isPresent(options.buffer) ? options.buffer : this.buffer
});
}
}