currently a boolean as body is seen as text/plain, where is should be seen as application/json, since it is valid JSON, like numbers. PR Close #41885
This commit is contained in:
parent
74da3724e4
commit
6e11febf60
@ -322,9 +322,9 @@ export class HttpRequest<T> {
|
|||||||
if (this.body instanceof HttpParams) {
|
if (this.body instanceof HttpParams) {
|
||||||
return 'application/x-www-form-urlencoded;charset=UTF-8';
|
return 'application/x-www-form-urlencoded;charset=UTF-8';
|
||||||
}
|
}
|
||||||
// Arrays, objects, and numbers will be encoded as JSON.
|
// Arrays, objects, boolean and numbers will be encoded as JSON.
|
||||||
if (typeof this.body === 'object' || typeof this.body === 'number' ||
|
if (typeof this.body === 'object' || typeof this.body === 'number' ||
|
||||||
Array.isArray(this.body)) {
|
typeof this.body === 'boolean') {
|
||||||
return 'application/json';
|
return 'application/json';
|
||||||
}
|
}
|
||||||
// No type could be inferred.
|
// No type could be inferred.
|
||||||
|
@ -129,6 +129,10 @@ const TEST_STRING = `I'm a body!`;
|
|||||||
const req = baseReq.clone({body: {data: 'test data'}});
|
const req = baseReq.clone({body: {data: 'test data'}});
|
||||||
expect(req.detectContentTypeHeader()).toBe('application/json');
|
expect(req.detectContentTypeHeader()).toBe('application/json');
|
||||||
});
|
});
|
||||||
|
it('handles boolean as json', () => {
|
||||||
|
const req = baseReq.clone({body: true});
|
||||||
|
expect(req.detectContentTypeHeader()).toBe('application/json');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('body serialization', () => {
|
describe('body serialization', () => {
|
||||||
const baseReq = new HttpRequest('POST', '/test', null);
|
const baseReq = new HttpRequest('POST', '/test', null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user