mirror of
https://github.com/Kong/insomnia.git
synced 2026-10-22 06:45:08 -04:00
Add JSON Content-Type on import if it doesn't include it
This commit is contained in:
1 parent
4d1a9113bb
commit
8baf4a482c
1 file changed
+17
-1
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user