mirror of
https://github.com/Kong/insomnia.git
synced 2026-05-19 06:12:37 -04:00
Autodetect XML if no content-type (Closes #368)
This commit is contained in:
@@ -185,12 +185,19 @@ class ResponseViewer extends PureComponent {
|
||||
const body = iconv.decode(bodyBuffer, charset);
|
||||
|
||||
let mode = contentType;
|
||||
try {
|
||||
// FEATURE: Detect JSON even without content-type
|
||||
contentType.indexOf('json') === -1 && JSON.parse(body);
|
||||
mode = 'application/json';
|
||||
} catch (e) {
|
||||
// Nothing
|
||||
|
||||
// Try to detect content-types if there isn't one
|
||||
if (!mode) {
|
||||
if (body.match(/^\s*<\?xml version="\d\.\d".*\?>/)) {
|
||||
mode = 'application/xml';
|
||||
} else {
|
||||
try {
|
||||
JSON.parse(body);
|
||||
mode = 'application/json';
|
||||
} catch (e) {
|
||||
// Nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user