Skip to content

Commit

Permalink
fix(http): preserve header case when copying headers
Browse files Browse the repository at this point in the history
  • Loading branch information
alxhub committed Nov 4, 2016
1 parent 69f006c commit bd74214
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/@angular/http/src/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class Headers {
}

if (headers instanceof Headers) {
headers._headers.forEach((values: string[], name: string) => {
headers.forEach((values: string[], name: string) => {
values.forEach(value => this.append(name, value));
});
return;
Expand Down
13 changes: 7 additions & 6 deletions modules/@angular/http/test/backends/xhr_backend_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ export function main() {
var connection = new XHRConnection(
new Request(base.merge(new RequestOptions({headers: headers}))), new MockBrowserXHR());
connection.response.subscribe();
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/xml');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('breaking-bad', '<3');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('x-multi', 'a,b');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/xml');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Breaking-Bad', '<3');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('X-Multi', 'a,b');
});

it('should skip content type detection if custom content type header is set', () => {
Expand All @@ -246,7 +246,8 @@ export function main() {
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
new MockBrowserXHR());
connection.response.subscribe();
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/plain');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/plain');
expect(setRequestHeaderSpy).not.toHaveBeenCalledWith('Content-Type', 'application/json');
expect(setRequestHeaderSpy).not.toHaveBeenCalledWith('content-type', 'application/json');
});

Expand Down Expand Up @@ -355,7 +356,7 @@ export function main() {
new MockBrowserXHR());
connection.response.subscribe();
expect(sendSpy).toHaveBeenCalledWith(body);
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/css');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/css');
});

it('should use array buffer body to the request', () => {
Expand Down Expand Up @@ -386,7 +387,7 @@ export function main() {
new MockBrowserXHR());
connection.response.subscribe();
expect(sendSpy).toHaveBeenCalledWith(body);
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/css');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/css');
});
}

Expand Down
7 changes: 7 additions & 0 deletions modules/@angular/http/test/headers_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export function main() {
expect(JSON.stringify(headers)).toEqual('{"fOo":["bat"]}');
});

it('should preserve cases after cloning', () => {
const headers = new Headers();
headers.set('fOo', 'baz');
headers.set('foo', 'bat');
expect(JSON.stringify(new Headers(headers))).toEqual('{"fOo":["bat"]}');
});

it('should convert input array to string', () => {
const headers = new Headers();
headers.set('foo', ['bar', 'baz']);
Expand Down

0 comments on commit bd74214

Please sign in to comment.