parent
5e9daed2e8
commit
b55f1764b5
|
@ -9,6 +9,7 @@ import {
|
||||||
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
|
import {BaseException, WrappedException} from 'angular2/src/facade/exceptions';
|
||||||
import {
|
import {
|
||||||
isListLikeIterable,
|
isListLikeIterable,
|
||||||
|
iterateListLike,
|
||||||
Map,
|
Map,
|
||||||
MapWrapper,
|
MapWrapper,
|
||||||
StringMapWrapper,
|
StringMapWrapper,
|
||||||
|
@ -131,7 +132,17 @@ export class Headers {
|
||||||
/**
|
/**
|
||||||
* Returns string of all headers.
|
* Returns string of all headers.
|
||||||
*/
|
*/
|
||||||
toJSON(): string { return Json.stringify(this.values()); }
|
toJSON(): {[key: string]: any} {
|
||||||
|
let serializableHeaders = {};
|
||||||
|
this._headersMap.forEach((values: string[], name: string) => {
|
||||||
|
let list = [];
|
||||||
|
|
||||||
|
iterateListLike(values, val => list = ListWrapper.concat(list, val.split(',')));
|
||||||
|
|
||||||
|
serializableHeaders[name] = list;
|
||||||
|
});
|
||||||
|
return serializableHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns list of header values for a given name.
|
* Returns list of header values for a given name.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {Headers} from 'angular2/src/http/headers';
|
import {Headers} from 'angular2/src/http/headers';
|
||||||
|
import {Json} from 'angular2/src/facade/lang';
|
||||||
import {Map, StringMapWrapper} from 'angular2/src/facade/collection';
|
import {Map, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||||
import {
|
import {
|
||||||
AsyncTestCompleter,
|
AsyncTestCompleter,
|
||||||
|
@ -62,6 +63,42 @@ export function main() {
|
||||||
expect(/bar, ?baz/g.test(headers.getAll('foo')[0])).toBe(true);
|
expect(/bar, ?baz/g.test(headers.getAll('foo')[0])).toBe(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('.toJSON()', () => {
|
||||||
|
let headers = null;
|
||||||
|
let inputArr = null;
|
||||||
|
let obj = null;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
headers = new Headers();
|
||||||
|
inputArr = ['application/jeisen', 'application/jason', 'application/patrickjs'];
|
||||||
|
obj = {'Accept': inputArr};
|
||||||
|
headers.set('Accept', inputArr);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should be serializable with toJSON', () => {
|
||||||
|
let stringifed = Json.stringify(obj);
|
||||||
|
let serializedHeaders = Json.stringify(headers);
|
||||||
|
expect(serializedHeaders).toEqual(stringifed);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should be able to parse serialized header', () => {
|
||||||
|
let stringifed = Json.stringify(obj);
|
||||||
|
let serializedHeaders = Json.stringify(headers);
|
||||||
|
expect(Json.parse(serializedHeaders)).toEqual(Json.parse(stringifed));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should be able to recreate serializedHeaders', () => {
|
||||||
|
let serializedHeaders = Json.stringify(headers);
|
||||||
|
let parsedHeaders = Json.parse(serializedHeaders);
|
||||||
|
let recreatedHeaders = new Headers(parsedHeaders);
|
||||||
|
expect(Json.stringify(parsedHeaders)).toEqual(Json.stringify(recreatedHeaders));
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.fromResponseHeaderString()', () => {
|
describe('.fromResponseHeaderString()', () => {
|
||||||
|
|
Loading…
Reference in New Issue