fix(http): Headers.append should append to the list

This commit is contained in:
Victor Berchet 2016-10-05 16:36:42 -07:00 committed by Tobias Bosch
parent d9d57d71dd
commit a67c06708d
2 changed files with 14 additions and 1 deletions

View File

@ -88,7 +88,12 @@ export class Headers {
*/ */
append(name: string, value: string): void { append(name: string, value: string): void {
const values = this.getAll(name); const values = this.getAll(name);
this.set(name, values === null ? [value] : [...values, value]);
if (values === null) {
this.set(name, value);
} else {
values.push(value);
}
} }
/** /**

View File

@ -111,6 +111,14 @@ export function main() {
}); });
describe('.append', () => { describe('.append', () => {
it('should append a value to the list', () => {
const headers = new Headers();
headers.append('foo', 'bar');
headers.append('foo', 'baz');
expect(headers.get('foo')).toEqual('bar');
expect(headers.getAll('foo')).toEqual(['bar', 'baz']);
});
it('should preserve the case of the first call', () => { it('should preserve the case of the first call', () => {
const headers = new Headers(); const headers = new Headers();