diff --git a/modules/@angular/http/src/backends/xhr_backend.ts b/modules/@angular/http/src/backends/xhr_backend.ts index 6a0cb815e6..5478d190e9 100644 --- a/modules/@angular/http/src/backends/xhr_backend.ts +++ b/modules/@angular/http/src/backends/xhr_backend.ts @@ -108,7 +108,7 @@ export class XHRConnection implements Connection { setDetectedContentType(req: any /** TODO #9100 */, _xhr: any /** TODO #9100 */) { // Skip if a custom Content-Type header is provided - if (isPresent(req.headers) && isPresent(req.headers['Content-Type'])) { + if (isPresent(req.headers) && isPresent(req.headers.get('Content-Type'))) { return; } diff --git a/modules/@angular/http/test/backends/xhr_backend_spec.ts b/modules/@angular/http/test/backends/xhr_backend_spec.ts index 77fc078e77..3569ca8e1b 100644 --- a/modules/@angular/http/test/backends/xhr_backend_spec.ts +++ b/modules/@angular/http/test/backends/xhr_backend_spec.ts @@ -212,6 +212,18 @@ export function main() { expect(setRequestHeaderSpy).toHaveBeenCalledWith('X-Multi', 'a,b'); }); + it('should skip content type detection if custom content type header is set', () => { + let headers = new Headers({'Content-Type': 'text/plain'}); + let body = {test: 'val'}; + let base = new BaseRequestOptions(); + let connection = new XHRConnection( + new Request(base.merge(new RequestOptions({body: body, headers: headers}))), + new MockBrowserXHR()); + connection.response.subscribe(); + expect(setRequestHeaderSpy).toHaveBeenCalledWith('Content-Type', 'text/plain'); + expect(setRequestHeaderSpy).not.toHaveBeenCalledWith('Content-Type', 'application/json'); + }); + it('should use object body and detect content type header to the request', () => { var body = {test: 'val'}; var base = new BaseRequestOptions();