Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(common): add right ContentType for boolean values with HttpClient request body(#38924) #41885

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/common/http/src/request.ts
Expand Up @@ -322,9 +322,9 @@ export class HttpRequest<T> {
if (this.body instanceof HttpParams) {
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' ||
Array.isArray(this.body)) {
typeof this.body === 'boolean') {
return 'application/json';
}
// No type could be inferred.
Expand Down
4 changes: 4 additions & 0 deletions packages/common/http/test/request_spec.ts
Expand Up @@ -129,6 +129,10 @@ const TEST_STRING = `I'm a body!`;
const req = baseReq.clone({body: {data: 'test data'}});
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', () => {
const baseReq = new HttpRequest('POST', '/test', null);
Expand Down