Skip to content

Commit

Permalink
fix(http): Headers.append should append to the list
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb authored and tbosch committed Oct 6, 2016
1 parent d9d57d7 commit a67c067
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion modules/@angular/http/src/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ export class Headers {
*/
append(name: string, value: string): void {
const values = this.getAll(name);
this.set(name, values === null ? [value] : [...values, value]);

if (values === null) {
this.set(name, value);
} else {
values.push(value);
}
}

/**
Expand Down
8 changes: 8 additions & 0 deletions modules/@angular/http/test/headers_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ export function main() {
});

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', () => {
const headers = new Headers();

Expand Down

0 comments on commit a67c067

Please sign in to comment.