mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-25 21:55:49 +00:00
fix: remove json bigint from cli
This commit is contained in:
@@ -37,7 +37,6 @@
|
||||
"fs-extra": "^10.1.0",
|
||||
"http-proxy-agent": "^7.0.0",
|
||||
"https-proxy-agent": "^7.0.2",
|
||||
"json-bigint": "^1.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"qs": "^6.11.0",
|
||||
"socks-proxy-agent": "^8.0.2",
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const { get, each, filter } = require('lodash');
|
||||
const fs = require('fs');
|
||||
var JSONbig = require('json-bigint');
|
||||
const decomment = require('decomment');
|
||||
const crypto = require('node:crypto');
|
||||
|
||||
@@ -31,7 +30,8 @@ const prepareRequest = (request, collectionRoot) => {
|
||||
method: request.method,
|
||||
url: request.url,
|
||||
headers: headers,
|
||||
pathParams: request?.params?.filter((param) => param.type === 'path')
|
||||
pathParams: request?.params?.filter((param) => param.type === 'path'),
|
||||
responseType: 'arraybuffer'
|
||||
};
|
||||
|
||||
const collectionAuth = get(collectionRoot, 'request.auth');
|
||||
@@ -96,16 +96,10 @@ const prepareRequest = (request, collectionRoot) => {
|
||||
if (!contentTypeDefined) {
|
||||
axiosRequest.headers['content-type'] = 'application/json';
|
||||
}
|
||||
let jsonBody;
|
||||
try {
|
||||
jsonBody = decomment(request?.body?.json);
|
||||
axiosRequest.data = decomment(request?.body?.json);
|
||||
} catch (error) {
|
||||
jsonBody = request?.body?.json;
|
||||
}
|
||||
try {
|
||||
axiosRequest.data = JSONbig.parse(jsonBody);
|
||||
} catch (error) {
|
||||
axiosRequest.data = jsonBody;
|
||||
axiosRequest.data = request?.body?.json;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ const { makeAxiosInstance } = require('../utils/axios-instance');
|
||||
const { addAwsV4Interceptor, resolveAwsV4Credentials } = require('./awsv4auth-helper');
|
||||
const { shouldUseProxy, PatchedHttpsProxyAgent } = require('../utils/proxy-util');
|
||||
const path = require('path');
|
||||
const { createFormData } = require('../utils/common');
|
||||
const { createFormData, parseDataFromResponse } = require('../utils/common');
|
||||
const protocolRegex = /^([-+\w]{1,25})(:?\/\/|:)/;
|
||||
|
||||
const onConsoleLog = (type, args) => {
|
||||
@@ -217,11 +217,16 @@ const runSingleRequest = async function (
|
||||
/** @type {import('axios').AxiosResponse} */
|
||||
response = await axiosInstance(request);
|
||||
|
||||
const { data } = parseDataFromResponse(response, request.__brunoDisableParsingResponseJson);
|
||||
response.data = data;
|
||||
|
||||
// Prevents the duration on leaking to the actual result
|
||||
responseTime = response.headers.get('request-duration');
|
||||
response.headers.delete('request-duration');
|
||||
} catch (err) {
|
||||
if (err?.response) {
|
||||
const { data } = parseDataFromResponse(err?.response);
|
||||
err.response.data = data;
|
||||
response = err.response;
|
||||
|
||||
// Prevents the duration on leaking to the actual result
|
||||
|
||||
@@ -2,6 +2,7 @@ const fs = require('fs');
|
||||
const FormData = require('form-data');
|
||||
const { forOwn } = require('lodash');
|
||||
const path = require('path');
|
||||
const iconv = require('iconv-lite');
|
||||
|
||||
const lpad = (str, width) => {
|
||||
let paddedStr = str;
|
||||
@@ -43,9 +44,35 @@ const createFormData = (datas, collectionPath) => {
|
||||
return form;
|
||||
};
|
||||
|
||||
const parseDataFromResponse = (response, disableParsingResponseJson = false) => {
|
||||
// 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;
|
||||
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
|
||||
// https://gist.github.com/antic183/619f42b559b78028d1fe9e7ae8a1352d
|
||||
data = data.replace(/^\uFEFF/, '');
|
||||
if (!disableParsingResponseJson) {
|
||||
data = JSON.parse(data);
|
||||
}
|
||||
} catch { }
|
||||
|
||||
return { data, dataBuffer };
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
lpad,
|
||||
rpad,
|
||||
createFormData
|
||||
createFormData,
|
||||
parseDataFromResponse
|
||||
};
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
meta {
|
||||
name: echo bigint
|
||||
type: http
|
||||
seq: 6
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{host}}/api/echo/json
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
foo: bar
|
||||
}
|
||||
|
||||
auth:basic {
|
||||
username: asd
|
||||
password: j
|
||||
}
|
||||
|
||||
auth:bearer {
|
||||
token:
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"hello": 990531470713421825,
|
||||
"decimal": 1.0,
|
||||
"decimal2": 1.00,
|
||||
"decimal3": 1.00200,
|
||||
"decimal4": 0.00
|
||||
}
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
}
|
||||
|
||||
tests {
|
||||
// todo: add tests once lossless json echo server is ready
|
||||
}
|
||||
Reference in New Issue
Block a user