mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +01:00
implement fallback to search body language by content-type header
This commit is contained in:
parent
b53fcbb3d1
commit
71b18c8b21
@ -91,7 +91,10 @@ const importPostmanV2CollectionItem = (brunoParent, item) => {
|
||||
}
|
||||
|
||||
if (bodyMode === 'raw') {
|
||||
const language = get(i, 'request.body.options.raw.language');
|
||||
let language = get(i, 'request.body.options.raw.language');
|
||||
if (!language) {
|
||||
language = searchLanguageByHeader(i.request.header);
|
||||
}
|
||||
if (language === 'json') {
|
||||
brunoRequestItem.request.body.mode = 'json';
|
||||
brunoRequestItem.request.body.json = i.request.body.raw;
|
||||
@ -131,6 +134,21 @@ const importPostmanV2CollectionItem = (brunoParent, item) => {
|
||||
});
|
||||
};
|
||||
|
||||
const searchLanguageByHeader = (headers) => {
|
||||
let contentType;
|
||||
each(headers, (header) => {
|
||||
if (header.key.toLowerCase() === 'content-type' && !header.disabled) {
|
||||
if (typeof header.value == 'string' && /^[\w\-]+\/([\w\-]+\+)?json/.test(header.value)) {
|
||||
contentType = 'json';
|
||||
} else if (typeof header.value == 'string' && /^[\w\-]+\/([\w\-]+\+)?xml/.test(header.value)) {
|
||||
contentType = 'xml';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return contentType;
|
||||
};
|
||||
|
||||
const importPostmanV2Collection = (collection) => {
|
||||
const brunoCollection = {
|
||||
name: collection.info.name,
|
||||
|
Loading…
Reference in New Issue
Block a user