Add JSON Content-Type on import if it doesn't include it

This commit is contained in:
Gregory Schier 2019-12-11 11:58:12 -05:00
parent 4d1a9113bb
commit 8baf4a482c

View File

@ -179,7 +179,23 @@ export async function importRaw(
continue;
}
const existingDoc = await model.getById(resource._id);
// Try adding Content-Type JSON if no Content-Type exists
if (
model.type === models.request.type &&
resource.body &&
typeof resource.body.text === 'string' &&
Array.isArray(resource.headers) &&
!resource.headers.find(h => h.name.toLowerCase() === 'content-type')
) {
try {
JSON.parse(resource.body.text);
resource.headers.push({ name: 'Content-Type', value: 'application/json' });
} catch (err) {
// Not JSON
}
}
const existingDoc = await db.get(model.type, resource._id);
let newDoc: BaseModel;
if (existingDoc) {
newDoc = await db.docUpdate(existingDoc, resource);