Fixes #922: Clear Content-Type when selecting 'No Body' (#1214)

* Clear Content-Type when selecting 'No Body'

* Remove CONTENT_TYPE_NO_BODY and simplify filter
This commit is contained in:
Timothy Lim 2018-10-20 22:24:27 +08:00 committed by Gregory Schier
parent 605cb90753
commit 2b3591f6e4
2 changed files with 5 additions and 3 deletions

View File

@ -119,7 +119,7 @@ describe('updateMimeType()', async () => {
expect(newRequest.headers).toEqual([{ name: 'content-tYPE', value: 'text/html' }]);
});
it('keeps content-type', async () => {
it('removes existing content-type when set to null (i.e. no body)', async () => {
const request = await models.request.create({
name: 'My Request',
parentId: 'fld_1',
@ -129,7 +129,7 @@ describe('updateMimeType()', async () => {
const newRequest = await models.request.updateMimeType(request, null);
expect(newRequest.body).toEqual({});
expect(newRequest.headers).toEqual([{ name: 'content-tYPE', value: 'application/json' }]);
expect(newRequest.headers).toEqual([]);
});
it('uses saved body when provided', async () => {

View File

@ -282,7 +282,9 @@ export function updateMimeType(
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
const hasBody = typeof mimeType === 'string';
if (!hasBody || mimeType === CONTENT_TYPE_OTHER) {
if (!hasBody) {
headers = headers.filter(h => h !== contentTypeHeader);
} else if (mimeType === CONTENT_TYPE_OTHER) {
// Leave headers alone
} else if (mimeType && contentTypeHeader && !leaveContentTypeAlone) {
contentTypeHeader.value = contentTypeHeaderValue;