diff --git a/modules/@angular/http/src/headers.ts b/modules/@angular/http/src/headers.ts index dc49ddc644..bc243a6976 100644 --- a/modules/@angular/http/src/headers.ts +++ b/modules/@angular/http/src/headers.ts @@ -64,13 +64,18 @@ export class Headers { * Returns a new Headers instance from the given DOMString of Response Headers */ static fromResponseHeaderString(headersString: string): Headers { - return headersString.trim() - .split('\n') - .map(val => val.split(':')) - .map(([key, ...parts]) => ([key.trim(), parts.join(':').trim()])) - .reduce( - (headers, [key, value]) => !headers.set(normalize(key), value) && headers, - new Headers()); + let headers = new Headers(); + + headersString.split('\n').forEach(line => { + const index = line.indexOf(':'); + if (index > 0) { + const key = line.substring(0, index); + const value = line.substring(index + 1).trim(); + headers.set(key, value); + } + }); + + return headers; } /** diff --git a/modules/@angular/http/test/backends/xhr_backend_spec.ts b/modules/@angular/http/test/backends/xhr_backend_spec.ts index 0d214e83bf..8f0e70ca5f 100644 --- a/modules/@angular/http/test/backends/xhr_backend_spec.ts +++ b/modules/@angular/http/test/backends/xhr_backend_spec.ts @@ -571,9 +571,9 @@ export function main() { sampleRequest, new MockBrowserXHR(), new ResponseOptions({status: statusCode})); let responseHeaderString = `Date: Fri, 20 Nov 2015 01:45:26 GMT - Content-Type: application/json; charset=utf-8 - Transfer-Encoding: chunked - Connection: keep-alive`; +Content-Type: application/json; charset=utf-8 +Transfer-Encoding: chunked +Connection: keep-alive`; connection.response.subscribe((res: Response) => { expect(res.headers.get('Date')).toEqual('Fri, 20 Nov 2015 01:45:26 GMT'); diff --git a/modules/@angular/http/test/headers_spec.ts b/modules/@angular/http/test/headers_spec.ts index cc522651a2..9b79275ee2 100644 --- a/modules/@angular/http/test/headers_spec.ts +++ b/modules/@angular/http/test/headers_spec.ts @@ -109,9 +109,9 @@ export function main() { it('should parse a response header string', () => { let responseHeaderString = `Date: Fri, 20 Nov 2015 01:45:26 GMT - Content-Type: application/json; charset=utf-8 - Transfer-Encoding: chunked - Connection: keep-alive`; +Content-Type: application/json; charset=utf-8 +Transfer-Encoding: chunked +Connection: keep-alive`; let responseHeaders = Headers.fromResponseHeaderString(responseHeaderString);