mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Add JSON Content-Type on import if it doesn't include it
This commit is contained in:
parent
4d1a9113bb
commit
8baf4a482c
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user