mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-02 02:49:48 +01:00
parent
470d162fb6
commit
3ded960938
@ -41,6 +41,7 @@
|
||||
"graphql": "^16.6.0",
|
||||
"http-proxy-agent": "^7.0.0",
|
||||
"https-proxy-agent": "^7.0.2",
|
||||
"iconv-lite": "^0.6.3",
|
||||
"is-valid-path": "^0.1.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"json-bigint": "^1.0.0",
|
||||
|
@ -37,6 +37,7 @@ const {
|
||||
transformPasswordCredentialsRequest
|
||||
} = require('./oauth2-helper');
|
||||
const Oauth2Store = require('../../store/oauth2');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
// override the default escape function to prevent escaping
|
||||
Mustache.escape = function (value) {
|
||||
@ -258,13 +259,18 @@ const configureRequest = async (
|
||||
};
|
||||
|
||||
const parseDataFromResponse = (response) => {
|
||||
const dataBuffer = Buffer.from(response.data);
|
||||
// Parse the charset from content type: https://stackoverflow.com/a/33192813
|
||||
const charsetMatch = /charset=([^()<>@,;:"/[\]?.=\s]*)/i.exec(response.headers['content-type'] || '');
|
||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#using_exec_with_regexp_literals
|
||||
const charsetValue = charsetMatch?.[1];
|
||||
const dataBuffer = Buffer.from(response.data);
|
||||
// Overwrite the original data for backwards compatibility
|
||||
let data = dataBuffer.toString(charsetValue || 'utf-8');
|
||||
let data;
|
||||
if (iconv.encodingExists(charsetValue)) {
|
||||
data = iconv.decode(dataBuffer, charsetValue);
|
||||
} else {
|
||||
data = iconv.decode(dataBuffer, 'utf-8');
|
||||
}
|
||||
// Try to parse response to JSON, this can quietly fail
|
||||
try {
|
||||
// Filter out ZWNBSP character
|
||||
|
@ -31,4 +31,10 @@ router.get('/bom-json-test', (req, res) => {
|
||||
return res.send(jsonWithBom);
|
||||
});
|
||||
|
||||
router.get('/iso-enc', (req, res) => {
|
||||
res.set('Content-Type', 'text/plain; charset=ISO-8859-1');
|
||||
const responseText = 'éçà';
|
||||
return res.send(Buffer.from(responseText, 'latin1'));
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
Loading…
Reference in New Issue
Block a user