Skip to content

Commit 25b5c3e

Browse files
Merge pull request #63 from thiagobustamante/master
Fix body parsing
2 parents 2a9b39a + 93d7d4d commit 25b5c3e

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/proxy/interceptors/requestBodyTransformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module.exports = function(config: JSONAtaExpression) {
1010
const result: any = {};
1111
try {
1212
let body = req.body;
13-
if (typeof body === 'string') {
14-
body = JSON.parse(body);
13+
if (typeof body === 'string' || Buffer.isBuffer(req.body)) {
14+
body = JSON.parse(body.toString());
1515
}
1616
result.body = expression.evaluate(body);
1717
} catch (e) {

src/proxy/interceptors/requestMustache.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ module.exports = function(config: MustacheConfig) {
2828
const result: any = {};
2929
try {
3030
let body = req.body;
31-
if (req.body && typeof req.body === 'string') {
32-
body = JSON.parse(req.body);
31+
if (req.body && (typeof req.body === 'string') || Buffer.isBuffer(req.body)) {
32+
body = JSON.parse(req.body.toString());
3333
}
3434
result.body = mustache.render(template, body || {});
3535
} catch (e) {

src/proxy/interceptors/requestXml.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module.exports = function(config: any) {
88
const result: any = {};
99
try {
1010
let body = req.body;
11-
if (req.body && typeof req.body === 'string') {
12-
body = JSON.parse(req.body);
11+
if (req.body && typeof req.body === 'string' || Buffer.isBuffer(req.body)) {
12+
body = JSON.parse(req.body.toString());
1313
}
1414
result.body = builder.buildObject(body);
1515
} catch (e) {

src/proxy/interceptors/responseBodyTransformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ module.exports = function(config: JSONAtaExpression) {
1010
return new Promise<ResponseInterceptorResult>((resolve, reject) => {
1111
try {
1212
let bodyData = body;
13-
if (typeof bodyData === 'string') {
14-
bodyData = JSON.parse(bodyData);
13+
if (typeof bodyData === 'string' || Buffer.isBuffer(bodyData)) {
14+
bodyData = JSON.parse(bodyData.toString());
1515
}
1616
const result = expression.evaluate(bodyData);
1717
resolve({ body: result });

0 commit comments

Comments
 (0)