fix(http): preserve header case when copying headers (#12697)
This commit is contained in:
parent
fe1d0e29c5
commit
121e5080aa
|
@ -49,7 +49,7 @@ export class Headers {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (headers instanceof 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));
|
values.forEach(value => this.append(name, value));
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -233,9 +233,9 @@ export function main() {
|
||||||
var connection = new XHRConnection(
|
var connection = new XHRConnection(
|
||||||
new Request(base.merge(new RequestOptions({headers: headers}))), new MockBrowserXHR());
|
new Request(base.merge(new RequestOptions({headers: headers}))), new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/xml');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/xml');
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('breaking-bad', '<3');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Breaking-Bad', '<3');
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('x-multi', 'a,b');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('X-Multi', 'a,b');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should skip content type detection if custom content type header is set', () => {
|
it('should skip content type detection if custom content type header is set', () => {
|
||||||
|
@ -246,7 +246,8 @@ export function main() {
|
||||||
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
new Request(base.merge(new RequestOptions({body: body, headers: headers}))),
|
||||||
new MockBrowserXHR());
|
new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
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');
|
expect(setRequestHeaderSpy).not.toHaveBeenCalledWith('content-type', 'application/json');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -355,7 +356,7 @@ export function main() {
|
||||||
new MockBrowserXHR());
|
new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
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', () => {
|
it('should use array buffer body to the request', () => {
|
||||||
|
@ -386,7 +387,7 @@ export function main() {
|
||||||
new MockBrowserXHR());
|
new MockBrowserXHR());
|
||||||
connection.response.subscribe();
|
connection.response.subscribe();
|
||||||
expect(sendSpy).toHaveBeenCalledWith(body);
|
expect(sendSpy).toHaveBeenCalledWith(body);
|
||||||
expect(setRequestHeaderSpy).toHaveBeenCalledWith('content-type', 'text/css');
|
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/css');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,13 @@ export function main() {
|
||||||
expect(JSON.stringify(headers)).toEqual('{"fOo":["bat"]}');
|
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', () => {
|
it('should convert input array to string', () => {
|
||||||
const headers = new Headers();
|
const headers = new Headers();
|
||||||
headers.set('foo', ['bar', 'baz']);
|
headers.set('foo', ['bar', 'baz']);
|
||||||
|
|
Loading…
Reference in New Issue