fix(#2767): Fix serilization issues of bigint in json body

This commit is contained in:
Anoop M D 2024-08-07 20:00:41 +05:30
parent 72c3aaa5ba
commit e0858d1c99
5 changed files with 69 additions and 22 deletions

View File

@ -17,8 +17,6 @@ const Timeline = ({ request, response }) => {
});
});
let requestData = safeStringifyJSON(request.data);
return (
<StyledWrapper className="pb-4 w-full">
<div>
@ -33,9 +31,9 @@ const Timeline = ({ request, response }) => {
);
})}
{requestData ? (
{request.data ? (
<pre className="line request">
<span className="arrow">{'>'}</span> data {requestData}
<span className="arrow">{'>'}</span> data <pre>{request.data}</pre>
</pre>
) : null}
</div>

View File

@ -59,14 +59,6 @@ const interpolateVars = (request, envVars = {}, runtimeVariables = {}, processEn
const contentType = getContentType(request.headers);
if (contentType.includes('json')) {
if (typeof request.data === 'object') {
try {
let parsed = JSON.stringify(request.data);
parsed = _interpolate(parsed);
request.data = JSON.parse(parsed);
} catch (err) {}
}
if (typeof request.data === 'string') {
if (request.data.length) {
request.data = _interpolate(request.data);

View File

@ -1,7 +1,6 @@
const os = require('os');
const { get, each, filter, extend, compact } = require('lodash');
const decomment = require('decomment');
var JSONbig = require('json-bigint');
const FormData = require('form-data');
const fs = require('fs');
const path = require('path');
@ -342,16 +341,10 @@ const prepareRequest = (item, collection) => {
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;
}
}

View File

@ -56,11 +56,31 @@ class BrunoRequest {
this.req.headers[name] = value;
}
getBody() {
/**
* Get the body of the request
*
* @param {*} options
* @param {boolean} options.raw - If true, return the raw body without parsing it
* @returns
*/
getBody(options = {}) {
let headers = this.req.headers;
const contentType = headers?.['Content-Type'] || headers?.['content-type'] || '';
const hasJSONContentType = contentType.includes('json');
if (hasJSONContentType && !options.raw) {
return JSON.parse(this.req.data);
}
return this.req.data;
}
setBody(data) {
if (typeof data === 'object') {
this.req.data = JSON.stringify(data);
return;
}
this.req.data = data;
}

View File

@ -0,0 +1,44 @@
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
}
}
body:text {
{
"hello": 990531470713421825
}
}
assert {
res.status: eq 200
}
script:pre-request {
bru.setVar("foo", "foo-world-2");
}