From 7cd4741fcbbea6d58281b3055d1ae7691de1662b Mon Sep 17 00:00:00 2001 From: Daniel Leib Date: Fri, 12 Aug 2016 06:40:18 +0200 Subject: [PATCH] fix(http): return empty string if no body is present (#10668) --- modules/@angular/http/src/body.ts | 4 ++++ modules/@angular/http/test/static_request_spec.ts | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/modules/@angular/http/src/body.ts b/modules/@angular/http/src/body.ts index babd1e59c7..02375a73e5 100644 --- a/modules/@angular/http/src/body.ts +++ b/modules/@angular/http/src/body.ts @@ -49,6 +49,10 @@ export abstract class Body { return String.fromCharCode.apply(null, new Uint16Array(this._body)); } + if (this._body === null) { + return ''; + } + if (isJsObject(this._body)) { return Json.stringify(this._body); } diff --git a/modules/@angular/http/test/static_request_spec.ts b/modules/@angular/http/test/static_request_spec.ts index 9c0f4db0f6..5d8262d42a 100644 --- a/modules/@angular/http/test/static_request_spec.ts +++ b/modules/@angular/http/test/static_request_spec.ts @@ -77,5 +77,16 @@ export function main() { expect(req.detectContentType()).toEqual(ContentType.BLOB); }); }); + + it('should return empty string if no body is present', () => { + const req = new Request(new RequestOptions({ + url: 'test', + method: 'GET', + body: null, + headers: new Headers({'content-type': 'application/json'}) + })); + + expect(req.text()).toEqual(''); + }); }); }