fix(http): return empty string if no body is present (#10668)

This commit is contained in:
Daniel Leib 2016-08-12 06:40:18 +02:00 committed by vikerman
parent 2d520ae7e7
commit 7cd4741fcb
2 changed files with 15 additions and 0 deletions

View File

@ -49,6 +49,10 @@ export abstract class Body {
return String.fromCharCode.apply(null, new Uint16Array(<ArrayBuffer>this._body));
}
if (this._body === null) {
return '';
}
if (isJsObject(this._body)) {
return Json.stringify(this._body);
}

View File

@ -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('');
});
});
}