fix(common): accept falsy values as HTTP bodies (#19958)

Previously, HttpClient used the overly clever test "body || null"
to determine when a body parameter was provided. This breaks when
the valid bodies '0' or 'false' are provided.

This change tests directly against 'undefined' to detect the presence
of the body parameter, and thus correctly allows falsy values through.

Fixes #19825.
Fixes #19195.

PR Close #19958
This commit is contained in:
Alex Rickabaugh
2017-10-25 15:55:36 -07:00
committed by Miško Hevery
parent eaaae2edf4
commit 15a54df7d3
5 changed files with 27 additions and 3 deletions

View File

@ -371,7 +371,7 @@ export class HttpClient {
}
// Construct the request.
req = new HttpRequest(first, url !, options.body || null, {
req = new HttpRequest(first, url !, (options.body !== undefined ? options.body : null), {
headers,
params,
reportProgress: options.reportProgress,

View File

@ -171,7 +171,7 @@ export class HttpRequest<T> {
// the body argument is to use a known no-body method like GET.
if (mightHaveBody(this.method) || !!fourth) {
// Body is the third argument, options are the fourth.
this.body = third as T || null;
this.body = (third !== undefined) ? third as T : null;
options = fourth;
} else {
// No body required, options are the third argument. The body stays null.

View File

@ -262,7 +262,7 @@ export class HttpResponse<T> extends HttpResponseBase {
body?: T | null, headers?: HttpHeaders; status?: number; statusText?: string; url?: string;
} = {}) {
super(init);
this.body = init.body || null;
this.body = init.body !== undefined ? init.body : null;
}
readonly type: HttpEventType.Response = HttpEventType.Response;