Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(XhrBackend): setRequestHeader takes a string arg #4597

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/angular2/src/http/backends/xhr_backend.ts
Expand Up @@ -64,7 +64,7 @@ export class XHRConnection implements Connection {
};

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);
Expand Down
2 changes: 1 addition & 1 deletion modules/angular2/src/http/headers.ts
Expand Up @@ -70,7 +70,7 @@ export class Headers {
*/
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);
}

Expand Down
8 changes: 5 additions & 3 deletions modules/angular2/test/http/backends/xhr_backend_spec.ts
Expand Up @@ -148,14 +148,16 @@ export function main() {
});

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 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('Content-Type', 'text/xml');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('Breaking-Bad', '<3');
expect(setRequestHeaderSpy).toHaveBeenCalledWith('X-Multi', 'a,b');
});

it('should return the correct status code', inject([AsyncTestCompleter], async => {
Expand Down