fix(XhrBackend): setRequestHeader takes a string arg

Closes #4597
This commit is contained in:
Victor Berchet 2015-10-07 14:56:18 -07:00
parent bffab0f2db
commit 6b00b60488
3 changed files with 7 additions and 5 deletions

View File

@ -64,7 +64,7 @@ export class XHRConnection implements Connection {
}; };
if (isPresent(req.headers)) { if (isPresent(req.headers)) {
req.headers.forEach((value, name) => { _xhr.setRequestHeader(name, value); }); req.headers.forEach((values, name) => { _xhr.setRequestHeader(name, values.join(',')); });
} }
_xhr.addEventListener('load', onLoad); _xhr.addEventListener('load', onLoad);

View File

@ -70,7 +70,7 @@ export class Headers {
*/ */
delete (name: string): void { MapWrapper.delete(this._headersMap, name); } delete (name: string): void { MapWrapper.delete(this._headersMap, name); }
forEach(fn: (value: string, name: string, headers: Headers) => any): void { forEach(fn: (values: string[], name: string, headers: Map<string, string[]>) => void): void {
MapWrapper.forEach(this._headersMap, fn); MapWrapper.forEach(this._headersMap, fn);
} }

View File

@ -148,14 +148,16 @@ export function main() {
}); });
it('should attach headers to the request', () => { it('should attach headers to the request', () => {
var headers = new Headers({'Content-Type': 'text/xml', 'Breaking-Bad': '<3'}); var headers =
new Headers({'Content-Type': 'text/xml', 'Breaking-Bad': '<3', 'X-Multi': ['a', 'b']});
var base = new BaseRequestOptions(); var base = new BaseRequestOptions();
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');
}); });
it('should return the correct status code', inject([AsyncTestCompleter], async => { it('should return the correct status code', inject([AsyncTestCompleter], async => {