@readme/httpsnippet 10.1.1 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/{chunk-532RKFLR.js → chunk-452Q5GGQ.js} +53 -254
- package/dist/chunk-452Q5GGQ.js.map +1 -0
- package/dist/index.cjs +93 -294
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/targets/index.cjs +52 -253
- package/dist/targets/index.cjs.map +1 -1
- package/dist/targets/index.js +1 -1
- package/package.json +5 -6
- package/dist/chunk-532RKFLR.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var url = require('url');
|
|
4
4
|
var qs = require('qs');
|
|
5
|
-
var
|
|
5
|
+
var stringifyObject7 = require('stringify-object');
|
|
6
6
|
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
8
|
|
|
9
|
-
var
|
|
9
|
+
var stringifyObject7__default = /*#__PURE__*/_interopDefault(stringifyObject7);
|
|
10
10
|
|
|
11
11
|
// src/index.ts
|
|
12
12
|
|
|
@@ -978,7 +978,7 @@ var axios = {
|
|
|
978
978
|
requestOptions.data = postData.text;
|
|
979
979
|
}
|
|
980
980
|
}
|
|
981
|
-
const optionString =
|
|
981
|
+
const optionString = stringifyObject7__default.default(requestOptions, {
|
|
982
982
|
indent: " ",
|
|
983
983
|
inlineCharacterLimit: 80
|
|
984
984
|
}).replace('"[form]"', "form");
|
|
@@ -986,12 +986,8 @@ var axios = {
|
|
|
986
986
|
blank();
|
|
987
987
|
push("axios");
|
|
988
988
|
push(".request(options)", 1);
|
|
989
|
-
push(".then(
|
|
990
|
-
push("console.
|
|
991
|
-
push("})", 1);
|
|
992
|
-
push(".catch(function (error) {", 1);
|
|
993
|
-
push("console.error(error);", 2);
|
|
994
|
-
push("});", 1);
|
|
989
|
+
push(".then(res => console.log(res.data))", 1);
|
|
990
|
+
push(".catch(err => console.error(err));", 1);
|
|
995
991
|
return join();
|
|
996
992
|
}
|
|
997
993
|
};
|
|
@@ -1051,7 +1047,7 @@ var fetch = {
|
|
|
1051
1047
|
delete options.headers;
|
|
1052
1048
|
}
|
|
1053
1049
|
push(
|
|
1054
|
-
`const options = ${
|
|
1050
|
+
`const options = ${stringifyObject7__default.default(options, {
|
|
1055
1051
|
indent: opts.indent,
|
|
1056
1052
|
inlineCharacterLimit: 80,
|
|
1057
1053
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult
|
|
@@ -1075,8 +1071,8 @@ var fetch = {
|
|
|
1075
1071
|
blank();
|
|
1076
1072
|
}
|
|
1077
1073
|
push(`fetch('${fullUrl}', options)`);
|
|
1078
|
-
push(".then(
|
|
1079
|
-
push(".then(
|
|
1074
|
+
push(".then(res => res.json())", 1);
|
|
1075
|
+
push(".then(res => console.log(res))", 1);
|
|
1080
1076
|
push(".catch(err => console.error(err));", 1);
|
|
1081
1077
|
return join();
|
|
1082
1078
|
}
|
|
@@ -1137,11 +1133,11 @@ var jquery = {
|
|
|
1137
1133
|
settings.data = postData.text;
|
|
1138
1134
|
}
|
|
1139
1135
|
}
|
|
1140
|
-
const stringifiedSettings =
|
|
1136
|
+
const stringifiedSettings = stringifyObject7__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
|
|
1141
1137
|
push(`const settings = ${stringifiedSettings};`);
|
|
1142
1138
|
blank();
|
|
1143
|
-
push("$.ajax(settings).done(
|
|
1144
|
-
push("console.log(
|
|
1139
|
+
push("$.ajax(settings).done(res => {");
|
|
1140
|
+
push("console.log(res);", 1);
|
|
1145
1141
|
push("});");
|
|
1146
1142
|
return join();
|
|
1147
1143
|
}
|
|
@@ -1164,7 +1160,7 @@ var xhr = {
|
|
|
1164
1160
|
switch (postData.mimeType) {
|
|
1165
1161
|
case "application/json":
|
|
1166
1162
|
push(
|
|
1167
|
-
`const data = JSON.stringify(${
|
|
1163
|
+
`const data = JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
|
|
1168
1164
|
indent: opts.indent
|
|
1169
1165
|
})});`
|
|
1170
1166
|
);
|
|
@@ -1218,7 +1214,7 @@ var javascript = {
|
|
|
1218
1214
|
info: {
|
|
1219
1215
|
key: "javascript",
|
|
1220
1216
|
title: "JavaScript",
|
|
1221
|
-
default: "
|
|
1217
|
+
default: "fetch"
|
|
1222
1218
|
},
|
|
1223
1219
|
clientsById: {
|
|
1224
1220
|
xhr,
|
|
@@ -1357,7 +1353,7 @@ var axios2 = {
|
|
|
1357
1353
|
title: "Axios",
|
|
1358
1354
|
link: "https://github.com/axios/axios",
|
|
1359
1355
|
description: "Promise based HTTP client for the browser and node.js",
|
|
1360
|
-
extname: ".
|
|
1356
|
+
extname: ".js",
|
|
1361
1357
|
installation: "npm install axios --save"
|
|
1362
1358
|
},
|
|
1363
1359
|
convert: ({ method, fullUrl, allHeaders, postData }, options) => {
|
|
@@ -1366,7 +1362,8 @@ var axios2 = {
|
|
|
1366
1362
|
...options
|
|
1367
1363
|
};
|
|
1368
1364
|
const { blank, join, push, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
|
|
1369
|
-
push("
|
|
1365
|
+
push("import axios from 'axios';");
|
|
1366
|
+
blank();
|
|
1370
1367
|
const reqOpts = {
|
|
1371
1368
|
method,
|
|
1372
1369
|
url: fullUrl
|
|
@@ -1377,8 +1374,6 @@ var axios2 = {
|
|
|
1377
1374
|
switch (postData.mimeType) {
|
|
1378
1375
|
case "application/x-www-form-urlencoded":
|
|
1379
1376
|
if (postData.params) {
|
|
1380
|
-
push("const { URLSearchParams } = require('url');");
|
|
1381
|
-
blank();
|
|
1382
1377
|
push("const encodedParams = new URLSearchParams();");
|
|
1383
1378
|
postData.params.forEach((param) => {
|
|
1384
1379
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
@@ -1389,39 +1384,32 @@ var axios2 = {
|
|
|
1389
1384
|
}
|
|
1390
1385
|
break;
|
|
1391
1386
|
case "application/json":
|
|
1392
|
-
blank();
|
|
1393
1387
|
if (postData.jsonObj) {
|
|
1394
1388
|
reqOpts.data = postData.jsonObj;
|
|
1395
1389
|
}
|
|
1396
1390
|
break;
|
|
1397
1391
|
default:
|
|
1398
|
-
blank();
|
|
1399
1392
|
if (postData.text) {
|
|
1400
1393
|
reqOpts.data = postData.text;
|
|
1401
1394
|
}
|
|
1402
1395
|
}
|
|
1403
|
-
const stringifiedOptions =
|
|
1396
|
+
const stringifiedOptions = stringifyObject7__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
|
|
1404
1397
|
push(`const options = ${stringifiedOptions};`);
|
|
1405
1398
|
blank();
|
|
1406
1399
|
push("axios");
|
|
1407
1400
|
push(".request(options)", 1);
|
|
1408
|
-
push(".then(
|
|
1409
|
-
push("console.
|
|
1410
|
-
push("})", 1);
|
|
1411
|
-
push(".catch(function (error) {", 1);
|
|
1412
|
-
push("console.error(error);", 2);
|
|
1413
|
-
push("});", 1);
|
|
1401
|
+
push(".then(res => console.log(res.data))", 1);
|
|
1402
|
+
push(".catch(err => console.error(err));", 1);
|
|
1414
1403
|
return join();
|
|
1415
1404
|
}
|
|
1416
1405
|
};
|
|
1417
1406
|
var fetch2 = {
|
|
1418
1407
|
info: {
|
|
1419
1408
|
key: "fetch",
|
|
1420
|
-
title: "
|
|
1421
|
-
link: "https://
|
|
1422
|
-
description: "
|
|
1423
|
-
extname: ".
|
|
1424
|
-
installation: "npm install node-fetch@2 --save"
|
|
1409
|
+
title: "fetch",
|
|
1410
|
+
link: "https://nodejs.org/docs/latest/api/globals.html#fetch",
|
|
1411
|
+
description: "Perform asynchronous HTTP requests with the Fetch API",
|
|
1412
|
+
extname: ".js"
|
|
1425
1413
|
},
|
|
1426
1414
|
convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
|
|
1427
1415
|
const opts = {
|
|
@@ -1430,7 +1418,6 @@ var fetch2 = {
|
|
|
1430
1418
|
};
|
|
1431
1419
|
let includeFS = false;
|
|
1432
1420
|
const { blank, push, join, unshift } = new CodeBuilder({ indent: opts.indent });
|
|
1433
|
-
push("const fetch = require('node-fetch');");
|
|
1434
1421
|
const url = fullUrl;
|
|
1435
1422
|
const reqOpts = {
|
|
1436
1423
|
method
|
|
@@ -1440,13 +1427,12 @@ var fetch2 = {
|
|
|
1440
1427
|
}
|
|
1441
1428
|
switch (postData.mimeType) {
|
|
1442
1429
|
case "application/x-www-form-urlencoded":
|
|
1443
|
-
unshift("const { URLSearchParams } = require('url');");
|
|
1444
1430
|
push("const encodedParams = new URLSearchParams();");
|
|
1445
|
-
blank();
|
|
1446
1431
|
postData.params?.forEach((param) => {
|
|
1447
1432
|
push(`encodedParams.set('${param.name}', '${param.value}');`);
|
|
1448
1433
|
});
|
|
1449
1434
|
reqOpts.body = "encodedParams";
|
|
1435
|
+
blank();
|
|
1450
1436
|
break;
|
|
1451
1437
|
case "application/json":
|
|
1452
1438
|
if (postData.jsonObj) {
|
|
@@ -1461,9 +1447,7 @@ var fetch2 = {
|
|
|
1461
1447
|
if (contentTypeHeader) {
|
|
1462
1448
|
delete headersObj[contentTypeHeader];
|
|
1463
1449
|
}
|
|
1464
|
-
unshift("const FormData = require('form-data');");
|
|
1465
1450
|
push("const formData = new FormData();");
|
|
1466
|
-
blank();
|
|
1467
1451
|
postData.params.forEach((param) => {
|
|
1468
1452
|
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
1469
1453
|
push(`formData.append('${param.name}', '${param.value}');`);
|
|
@@ -1471,9 +1455,13 @@ var fetch2 = {
|
|
|
1471
1455
|
}
|
|
1472
1456
|
if (param.fileName) {
|
|
1473
1457
|
includeFS = true;
|
|
1474
|
-
push(
|
|
1458
|
+
push(
|
|
1459
|
+
`formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`
|
|
1460
|
+
);
|
|
1475
1461
|
}
|
|
1476
1462
|
});
|
|
1463
|
+
reqOpts.body = "formData";
|
|
1464
|
+
blank();
|
|
1477
1465
|
break;
|
|
1478
1466
|
default:
|
|
1479
1467
|
if (postData.text) {
|
|
@@ -1489,12 +1477,11 @@ var fetch2 = {
|
|
|
1489
1477
|
reqOpts.headers.cookie = cookiesString;
|
|
1490
1478
|
}
|
|
1491
1479
|
}
|
|
1492
|
-
blank();
|
|
1493
1480
|
push(`const url = '${url}';`);
|
|
1494
1481
|
if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
|
|
1495
1482
|
delete reqOpts.headers;
|
|
1496
1483
|
}
|
|
1497
|
-
const stringifiedOptions =
|
|
1484
|
+
const stringifiedOptions = stringifyObject7__default.default(reqOpts, {
|
|
1498
1485
|
indent: " ",
|
|
1499
1486
|
inlineCharacterLimit: 80,
|
|
1500
1487
|
// The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
|
|
@@ -1510,17 +1497,13 @@ var fetch2 = {
|
|
|
1510
1497
|
push(`const options = ${stringifiedOptions};`);
|
|
1511
1498
|
blank();
|
|
1512
1499
|
if (includeFS) {
|
|
1513
|
-
unshift("
|
|
1514
|
-
}
|
|
1515
|
-
if (postData.params && postData.mimeType === "multipart/form-data") {
|
|
1516
|
-
push("options.body = formData;");
|
|
1517
|
-
blank();
|
|
1500
|
+
unshift("import fs from 'fs';\n");
|
|
1518
1501
|
}
|
|
1519
1502
|
push("fetch(url, options)");
|
|
1520
1503
|
push(".then(res => res.json())", 1);
|
|
1521
1504
|
push(".then(json => console.log(json))", 1);
|
|
1522
|
-
push(".catch(err => console.error(
|
|
1523
|
-
return join().replace(/'encodedParams'/, "encodedParams").replace(/
|
|
1505
|
+
push(".catch(err => console.error(err));", 1);
|
|
1506
|
+
return join().replace(/'encodedParams'/, "encodedParams").replace(/'formData'/, "formData");
|
|
1524
1507
|
}
|
|
1525
1508
|
};
|
|
1526
1509
|
var native3 = {
|
|
@@ -1543,7 +1526,7 @@ var native3 = {
|
|
|
1543
1526
|
};
|
|
1544
1527
|
push(`const http = require('${uriObj.protocol?.replace(":", "")}');`);
|
|
1545
1528
|
blank();
|
|
1546
|
-
push(`const options = ${
|
|
1529
|
+
push(`const options = ${stringifyObject7__default.default(reqOpts, { indent })};`);
|
|
1547
1530
|
blank();
|
|
1548
1531
|
push("const req = http.request(options, function (res) {");
|
|
1549
1532
|
push("const chunks = [];", 1);
|
|
@@ -1563,7 +1546,7 @@ var native3 = {
|
|
|
1563
1546
|
if (postData.paramsObj) {
|
|
1564
1547
|
unshift("const qs = require('querystring');");
|
|
1565
1548
|
push(
|
|
1566
|
-
`req.write(qs.stringify(${
|
|
1549
|
+
`req.write(qs.stringify(${stringifyObject7__default.default(postData.paramsObj, {
|
|
1567
1550
|
indent: " ",
|
|
1568
1551
|
inlineCharacterLimit: 80
|
|
1569
1552
|
})}));`
|
|
@@ -1573,7 +1556,7 @@ var native3 = {
|
|
|
1573
1556
|
case "application/json":
|
|
1574
1557
|
if (postData.jsonObj) {
|
|
1575
1558
|
push(
|
|
1576
|
-
`req.write(JSON.stringify(${
|
|
1559
|
+
`req.write(JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
|
|
1577
1560
|
indent: " ",
|
|
1578
1561
|
inlineCharacterLimit: 80
|
|
1579
1562
|
})}));`
|
|
@@ -1582,208 +1565,24 @@ var native3 = {
|
|
|
1582
1565
|
break;
|
|
1583
1566
|
default:
|
|
1584
1567
|
if (postData.text) {
|
|
1585
|
-
push(`req.write(${
|
|
1568
|
+
push(`req.write(${stringifyObject7__default.default(postData.text, { indent })});`);
|
|
1586
1569
|
}
|
|
1587
1570
|
}
|
|
1588
1571
|
push("req.end();");
|
|
1589
1572
|
return join();
|
|
1590
1573
|
}
|
|
1591
1574
|
};
|
|
1592
|
-
var request = {
|
|
1593
|
-
info: {
|
|
1594
|
-
key: "request",
|
|
1595
|
-
title: "Request",
|
|
1596
|
-
link: "https://github.com/request/request",
|
|
1597
|
-
description: "Simplified HTTP request client",
|
|
1598
|
-
extname: ".cjs",
|
|
1599
|
-
installation: "npm install request --save"
|
|
1600
|
-
},
|
|
1601
|
-
convert: ({ method, url, fullUrl, postData, headersObj, cookies }, options) => {
|
|
1602
|
-
const opts = {
|
|
1603
|
-
indent: " ",
|
|
1604
|
-
...options
|
|
1605
|
-
};
|
|
1606
|
-
let includeFS = false;
|
|
1607
|
-
const { push, blank, join, unshift, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
|
|
1608
|
-
push("const request = require('request');");
|
|
1609
|
-
blank();
|
|
1610
|
-
const reqOpts = {
|
|
1611
|
-
method,
|
|
1612
|
-
url: fullUrl
|
|
1613
|
-
};
|
|
1614
|
-
if (Object.keys(headersObj).length) {
|
|
1615
|
-
reqOpts.headers = headersObj;
|
|
1616
|
-
}
|
|
1617
|
-
switch (postData.mimeType) {
|
|
1618
|
-
case "application/x-www-form-urlencoded":
|
|
1619
|
-
reqOpts.form = postData.paramsObj;
|
|
1620
|
-
break;
|
|
1621
|
-
case "application/json":
|
|
1622
|
-
if (postData.jsonObj) {
|
|
1623
|
-
reqOpts.body = postData.jsonObj;
|
|
1624
|
-
reqOpts.json = true;
|
|
1625
|
-
}
|
|
1626
|
-
break;
|
|
1627
|
-
case "multipart/form-data":
|
|
1628
|
-
if (!postData.params) {
|
|
1629
|
-
break;
|
|
1630
|
-
}
|
|
1631
|
-
reqOpts.formData = {};
|
|
1632
|
-
postData.params.forEach((param) => {
|
|
1633
|
-
if (!param.fileName && !param.fileName && !param.contentType) {
|
|
1634
|
-
reqOpts.formData[param.name] = param.value;
|
|
1635
|
-
return;
|
|
1636
|
-
}
|
|
1637
|
-
let attachment = {};
|
|
1638
|
-
if (param.fileName) {
|
|
1639
|
-
includeFS = true;
|
|
1640
|
-
attachment = {
|
|
1641
|
-
value: `fs.createReadStream(${param.fileName})`,
|
|
1642
|
-
options: {
|
|
1643
|
-
filename: param.fileName,
|
|
1644
|
-
contentType: param.contentType ? param.contentType : null
|
|
1645
|
-
}
|
|
1646
|
-
};
|
|
1647
|
-
} else if (param.value) {
|
|
1648
|
-
attachment.value = param.value;
|
|
1649
|
-
}
|
|
1650
|
-
reqOpts.formData[param.name] = attachment;
|
|
1651
|
-
});
|
|
1652
|
-
addPostProcessor((code) => code.replace(/'fs\.createReadStream\((.*)\)'/, "fs.createReadStream('$1')"));
|
|
1653
|
-
break;
|
|
1654
|
-
default:
|
|
1655
|
-
if (postData.text) {
|
|
1656
|
-
reqOpts.body = postData.text;
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
if (cookies.length) {
|
|
1660
|
-
reqOpts.jar = "JAR";
|
|
1661
|
-
push("const jar = request.jar();");
|
|
1662
|
-
cookies.forEach(({ name, value }) => {
|
|
1663
|
-
push(`jar.setCookie(request.cookie('${encodeURIComponent(name)}=${encodeURIComponent(value)}'), '${url}');`);
|
|
1664
|
-
});
|
|
1665
|
-
blank();
|
|
1666
|
-
addPostProcessor((code) => code.replace(/'JAR'/, "jar"));
|
|
1667
|
-
}
|
|
1668
|
-
if (includeFS) {
|
|
1669
|
-
unshift("const fs = require('fs');");
|
|
1670
|
-
}
|
|
1671
|
-
push(`const options = ${stringifyObject9__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 })};`);
|
|
1672
|
-
blank();
|
|
1673
|
-
push("request(options, function (error, response, body) {");
|
|
1674
|
-
push("if (error) throw new Error(error);", 1);
|
|
1675
|
-
blank();
|
|
1676
|
-
push("console.log(body);", 1);
|
|
1677
|
-
push("});");
|
|
1678
|
-
return join();
|
|
1679
|
-
}
|
|
1680
|
-
};
|
|
1681
|
-
var unirest2 = {
|
|
1682
|
-
info: {
|
|
1683
|
-
key: "unirest",
|
|
1684
|
-
title: "Unirest",
|
|
1685
|
-
link: "http://unirest.io/nodejs.html",
|
|
1686
|
-
description: "Lightweight HTTP Request Client Library",
|
|
1687
|
-
extname: ".cjs"
|
|
1688
|
-
},
|
|
1689
|
-
convert: ({ method, url, cookies, queryObj, postData, headersObj }, options) => {
|
|
1690
|
-
const opts = {
|
|
1691
|
-
indent: " ",
|
|
1692
|
-
...options
|
|
1693
|
-
};
|
|
1694
|
-
let includeFS = false;
|
|
1695
|
-
const { addPostProcessor, blank, join, push, unshift } = new CodeBuilder({
|
|
1696
|
-
indent: opts.indent
|
|
1697
|
-
});
|
|
1698
|
-
push("const unirest = require('unirest');");
|
|
1699
|
-
blank();
|
|
1700
|
-
push(`const req = unirest('${method}', '${url}');`);
|
|
1701
|
-
blank();
|
|
1702
|
-
if (cookies.length) {
|
|
1703
|
-
push("const CookieJar = unirest.jar();");
|
|
1704
|
-
cookies.forEach((cookie) => {
|
|
1705
|
-
push(`CookieJar.add('${encodeURIComponent(cookie.name)}=${encodeURIComponent(cookie.value)}', '${url}');`);
|
|
1706
|
-
});
|
|
1707
|
-
push("req.jar(CookieJar);");
|
|
1708
|
-
blank();
|
|
1709
|
-
}
|
|
1710
|
-
if (Object.keys(queryObj).length) {
|
|
1711
|
-
push(`req.query(${stringifyObject9__default.default(queryObj, { indent: opts.indent })});`);
|
|
1712
|
-
blank();
|
|
1713
|
-
}
|
|
1714
|
-
if (Object.keys(headersObj).length) {
|
|
1715
|
-
push(`req.headers(${stringifyObject9__default.default(headersObj, { indent: opts.indent })});`);
|
|
1716
|
-
blank();
|
|
1717
|
-
}
|
|
1718
|
-
switch (postData.mimeType) {
|
|
1719
|
-
case "application/x-www-form-urlencoded":
|
|
1720
|
-
if (postData.paramsObj) {
|
|
1721
|
-
push(`req.form(${stringifyObject9__default.default(postData.paramsObj, { indent: opts.indent })});`);
|
|
1722
|
-
blank();
|
|
1723
|
-
}
|
|
1724
|
-
break;
|
|
1725
|
-
case "application/json":
|
|
1726
|
-
if (postData.jsonObj) {
|
|
1727
|
-
push("req.type('json');");
|
|
1728
|
-
push(`req.send(${stringifyObject9__default.default(postData.jsonObj, { indent: opts.indent })});`);
|
|
1729
|
-
blank();
|
|
1730
|
-
}
|
|
1731
|
-
break;
|
|
1732
|
-
case "multipart/form-data": {
|
|
1733
|
-
if (!postData.params) {
|
|
1734
|
-
break;
|
|
1735
|
-
}
|
|
1736
|
-
const multipart = [];
|
|
1737
|
-
postData.params.forEach((param) => {
|
|
1738
|
-
const part = {};
|
|
1739
|
-
if (param.fileName && !param.value) {
|
|
1740
|
-
includeFS = true;
|
|
1741
|
-
part.body = `fs.createReadStream('${param.fileName}')`;
|
|
1742
|
-
addPostProcessor((code) => code.replace(/'fs\.createReadStream\(\\'(.+)\\'\)'/, "fs.createReadStream('$1')"));
|
|
1743
|
-
} else if (param.value) {
|
|
1744
|
-
part.body = param.value;
|
|
1745
|
-
}
|
|
1746
|
-
if (part.body) {
|
|
1747
|
-
if (param.contentType) {
|
|
1748
|
-
part["content-type"] = param.contentType;
|
|
1749
|
-
}
|
|
1750
|
-
multipart.push(part);
|
|
1751
|
-
}
|
|
1752
|
-
});
|
|
1753
|
-
push(`req.multipart(${stringifyObject9__default.default(multipart, { indent: opts.indent })});`);
|
|
1754
|
-
blank();
|
|
1755
|
-
break;
|
|
1756
|
-
}
|
|
1757
|
-
default:
|
|
1758
|
-
if (postData.text) {
|
|
1759
|
-
push(`req.send(${stringifyObject9__default.default(postData.text, { indent: opts.indent })});`);
|
|
1760
|
-
blank();
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
if (includeFS) {
|
|
1764
|
-
unshift("const fs = require('fs');");
|
|
1765
|
-
}
|
|
1766
|
-
push("req.end(function (res) {");
|
|
1767
|
-
push("if (res.error) throw new Error(res.error);", 1);
|
|
1768
|
-
blank();
|
|
1769
|
-
push("console.log(res.body);", 1);
|
|
1770
|
-
push("});");
|
|
1771
|
-
return join();
|
|
1772
|
-
}
|
|
1773
|
-
};
|
|
1774
1575
|
|
|
1775
1576
|
// src/targets/node/target.ts
|
|
1776
1577
|
var node = {
|
|
1777
1578
|
info: {
|
|
1778
1579
|
key: "node",
|
|
1779
1580
|
title: "Node.js",
|
|
1780
|
-
default: "
|
|
1581
|
+
default: "fetch",
|
|
1781
1582
|
cli: "node %s"
|
|
1782
1583
|
},
|
|
1783
1584
|
clientsById: {
|
|
1784
1585
|
native: native3,
|
|
1785
|
-
request,
|
|
1786
|
-
unirest: unirest2,
|
|
1787
1586
|
axios: axios2,
|
|
1788
1587
|
fetch: fetch2
|
|
1789
1588
|
}
|
|
@@ -2734,22 +2533,22 @@ var requests = {
|
|
|
2734
2533
|
push("}");
|
|
2735
2534
|
blank();
|
|
2736
2535
|
}
|
|
2737
|
-
let
|
|
2536
|
+
let request = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
|
|
2738
2537
|
if (hasPayload) {
|
|
2739
2538
|
if (jsonPayload) {
|
|
2740
|
-
|
|
2539
|
+
request += ", json=payload";
|
|
2741
2540
|
} else {
|
|
2742
|
-
|
|
2541
|
+
request += ", data=payload";
|
|
2743
2542
|
}
|
|
2744
2543
|
}
|
|
2745
2544
|
if (hasFiles) {
|
|
2746
|
-
|
|
2545
|
+
request += ", files=files";
|
|
2747
2546
|
}
|
|
2748
2547
|
if (headerCount > 0) {
|
|
2749
|
-
|
|
2548
|
+
request += ", headers=headers";
|
|
2750
2549
|
}
|
|
2751
|
-
|
|
2752
|
-
push(
|
|
2550
|
+
request += ")";
|
|
2551
|
+
push(request);
|
|
2753
2552
|
blank();
|
|
2754
2553
|
push("print(response.text)");
|
|
2755
2554
|
return join();
|
|
@@ -2834,22 +2633,22 @@ var httr = {
|
|
|
2834
2633
|
const setContentType = `content_type("${escapeForDoubleQuotes(postData.mimeType)}")`;
|
|
2835
2634
|
const otherHeaders = Object.entries(allHeaders).filter(([key]) => !["cookie", "accept", "content-type"].includes(key.toLowerCase())).map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`).join(", ");
|
|
2836
2635
|
const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : void 0;
|
|
2837
|
-
let
|
|
2636
|
+
let request = `response <- VERB("${method}", url`;
|
|
2838
2637
|
if (payload) {
|
|
2839
|
-
|
|
2638
|
+
request += ", body = payload";
|
|
2840
2639
|
}
|
|
2841
2640
|
if (queryString.length) {
|
|
2842
|
-
|
|
2641
|
+
request += ", query = queryString";
|
|
2843
2642
|
}
|
|
2844
2643
|
const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(", ");
|
|
2845
2644
|
if (headerAdditions) {
|
|
2846
|
-
|
|
2645
|
+
request += `, ${headerAdditions}`;
|
|
2847
2646
|
}
|
|
2848
2647
|
if (postData.text || postData.jsonObj || postData.params) {
|
|
2849
|
-
|
|
2648
|
+
request += ", encode = encode";
|
|
2850
2649
|
}
|
|
2851
|
-
|
|
2852
|
-
push(
|
|
2650
|
+
request += ")";
|
|
2651
|
+
push(request);
|
|
2853
2652
|
blank();
|
|
2854
2653
|
push('content(response, "text")');
|
|
2855
2654
|
return join();
|
|
@@ -3574,7 +3373,7 @@ var HTTPSnippet = class {
|
|
|
3574
3373
|
}
|
|
3575
3374
|
init() {
|
|
3576
3375
|
this.initCalled = true;
|
|
3577
|
-
this.requests = this.entries.map(({ request
|
|
3376
|
+
this.requests = this.entries.map(({ request }) => {
|
|
3578
3377
|
const req = {
|
|
3579
3378
|
bodySize: 0,
|
|
3580
3379
|
headersSize: 0,
|
|
@@ -3583,9 +3382,9 @@ var HTTPSnippet = class {
|
|
|
3583
3382
|
httpVersion: "HTTP/1.1",
|
|
3584
3383
|
queryString: [],
|
|
3585
3384
|
postData: {
|
|
3586
|
-
mimeType:
|
|
3385
|
+
mimeType: request.postData?.mimeType || "application/octet-stream"
|
|
3587
3386
|
},
|
|
3588
|
-
...
|
|
3387
|
+
...request
|
|
3589
3388
|
};
|
|
3590
3389
|
if (req.postData && !req.postData.mimeType) {
|
|
3591
3390
|
req.postData.mimeType = "application/octet-stream";
|
|
@@ -3595,7 +3394,7 @@ var HTTPSnippet = class {
|
|
|
3595
3394
|
return this;
|
|
3596
3395
|
}
|
|
3597
3396
|
prepare(harRequest, options) {
|
|
3598
|
-
const
|
|
3397
|
+
const request = {
|
|
3599
3398
|
...harRequest,
|
|
3600
3399
|
fullUrl: "",
|
|
3601
3400
|
uriObj: {},
|
|
@@ -3604,21 +3403,21 @@ var HTTPSnippet = class {
|
|
|
3604
3403
|
cookiesObj: {},
|
|
3605
3404
|
allHeaders: {}
|
|
3606
3405
|
};
|
|
3607
|
-
if (
|
|
3608
|
-
|
|
3406
|
+
if (request.queryString && request.queryString.length) {
|
|
3407
|
+
request.queryObj = request.queryString.reduce(reducer, {});
|
|
3609
3408
|
}
|
|
3610
|
-
if (
|
|
3409
|
+
if (request.headers && request.headers.length) {
|
|
3611
3410
|
const http2VersionRegex = /^HTTP\/2/;
|
|
3612
|
-
|
|
3613
|
-
const headerName = http2VersionRegex.exec(
|
|
3411
|
+
request.headersObj = request.headers.reduce((accumulator, { name, value }) => {
|
|
3412
|
+
const headerName = http2VersionRegex.exec(request.httpVersion) ? name.toLocaleLowerCase() : name;
|
|
3614
3413
|
return {
|
|
3615
3414
|
...accumulator,
|
|
3616
3415
|
[headerName]: value
|
|
3617
3416
|
};
|
|
3618
3417
|
}, {});
|
|
3619
3418
|
}
|
|
3620
|
-
if (
|
|
3621
|
-
|
|
3419
|
+
if (request.cookies && request.cookies.length) {
|
|
3420
|
+
request.cookiesObj = request.cookies.reduceRight(
|
|
3622
3421
|
(accumulator, { name, value }) => ({
|
|
3623
3422
|
...accumulator,
|
|
3624
3423
|
[name]: value
|
|
@@ -3626,30 +3425,30 @@ var HTTPSnippet = class {
|
|
|
3626
3425
|
{}
|
|
3627
3426
|
);
|
|
3628
3427
|
}
|
|
3629
|
-
const cookies =
|
|
3428
|
+
const cookies = request.cookies?.map(({ name, value }) => {
|
|
3630
3429
|
if (options.harIsAlreadyEncoded) {
|
|
3631
3430
|
return `${name}=${value}`;
|
|
3632
3431
|
}
|
|
3633
3432
|
return `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
|
|
3634
3433
|
});
|
|
3635
3434
|
if (cookies?.length) {
|
|
3636
|
-
|
|
3435
|
+
request.allHeaders.cookie = cookies.join("; ");
|
|
3637
3436
|
}
|
|
3638
|
-
switch (
|
|
3437
|
+
switch (request.postData.mimeType) {
|
|
3639
3438
|
case "multipart/mixed":
|
|
3640
3439
|
case "multipart/related":
|
|
3641
3440
|
case "multipart/form-data":
|
|
3642
3441
|
case "multipart/alternative":
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
if (
|
|
3442
|
+
request.postData.text = "";
|
|
3443
|
+
request.postData.mimeType = "multipart/form-data";
|
|
3444
|
+
if (request.postData?.params) {
|
|
3646
3445
|
const boundary = "---011000010111000001101001";
|
|
3647
3446
|
const carriage = `${boundary}--`;
|
|
3648
3447
|
const rn = "\r\n";
|
|
3649
3448
|
const escape2 = (str) => str.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
|
|
3650
3449
|
const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, "\r\n");
|
|
3651
3450
|
const payload = [`--${boundary}`];
|
|
3652
|
-
|
|
3451
|
+
request.postData?.params.forEach((param, i) => {
|
|
3653
3452
|
const name = param.name;
|
|
3654
3453
|
const value = param.value || "";
|
|
3655
3454
|
const filename = param.fileName || null;
|
|
@@ -3664,62 +3463,62 @@ var HTTPSnippet = class {
|
|
|
3664
3463
|
}
|
|
3665
3464
|
payload.push("");
|
|
3666
3465
|
payload.push(normalizeLinefeeds(value));
|
|
3667
|
-
if (i !==
|
|
3466
|
+
if (i !== request.postData.params.length - 1) {
|
|
3668
3467
|
payload.push(`--${boundary}`);
|
|
3669
3468
|
}
|
|
3670
3469
|
});
|
|
3671
3470
|
payload.push(`--${carriage}`);
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
const contentTypeHeader = getHeaderName(
|
|
3675
|
-
|
|
3471
|
+
request.postData.boundary = boundary;
|
|
3472
|
+
request.postData.text = payload.join(rn);
|
|
3473
|
+
const contentTypeHeader = getHeaderName(request.headersObj, "content-type") || "content-type";
|
|
3474
|
+
request.headersObj[contentTypeHeader] = `multipart/form-data; boundary=${boundary}`;
|
|
3676
3475
|
}
|
|
3677
3476
|
break;
|
|
3678
3477
|
case "application/x-www-form-urlencoded":
|
|
3679
|
-
if (!
|
|
3680
|
-
|
|
3478
|
+
if (!request.postData.params) {
|
|
3479
|
+
request.postData.text = "";
|
|
3681
3480
|
} else {
|
|
3682
|
-
|
|
3683
|
-
|
|
3481
|
+
request.postData.paramsObj = request.postData.params.reduce(reducer, {});
|
|
3482
|
+
request.postData.text = qs.stringify(request.postData.paramsObj);
|
|
3684
3483
|
}
|
|
3685
3484
|
break;
|
|
3686
3485
|
case "text/json":
|
|
3687
3486
|
case "text/x-json":
|
|
3688
3487
|
case "application/json":
|
|
3689
3488
|
case "application/x-json":
|
|
3690
|
-
|
|
3691
|
-
if (
|
|
3489
|
+
request.postData.mimeType = "application/json";
|
|
3490
|
+
if (request.postData.text) {
|
|
3692
3491
|
try {
|
|
3693
|
-
|
|
3492
|
+
request.postData.jsonObj = JSON.parse(request.postData.text);
|
|
3694
3493
|
} catch (e) {
|
|
3695
|
-
|
|
3494
|
+
request.postData.mimeType = "text/plain";
|
|
3696
3495
|
}
|
|
3697
3496
|
}
|
|
3698
3497
|
break;
|
|
3699
3498
|
}
|
|
3700
3499
|
const allHeaders = {
|
|
3701
|
-
...
|
|
3702
|
-
...
|
|
3500
|
+
...request.allHeaders,
|
|
3501
|
+
...request.headersObj
|
|
3703
3502
|
};
|
|
3704
|
-
const urlWithParsedQuery = url.parse(
|
|
3705
|
-
|
|
3706
|
-
...
|
|
3503
|
+
const urlWithParsedQuery = url.parse(request.url, true, true);
|
|
3504
|
+
request.queryObj = {
|
|
3505
|
+
...request.queryObj,
|
|
3707
3506
|
...urlWithParsedQuery.query
|
|
3708
3507
|
};
|
|
3709
3508
|
let search;
|
|
3710
3509
|
if (options.harIsAlreadyEncoded) {
|
|
3711
|
-
search = qs.stringify(
|
|
3510
|
+
search = qs.stringify(request.queryObj, {
|
|
3712
3511
|
encode: false,
|
|
3713
3512
|
indices: false
|
|
3714
3513
|
});
|
|
3715
3514
|
} else {
|
|
3716
|
-
search = qs.stringify(
|
|
3515
|
+
search = qs.stringify(request.queryObj, {
|
|
3717
3516
|
indices: false
|
|
3718
3517
|
});
|
|
3719
3518
|
}
|
|
3720
3519
|
const uriObj = {
|
|
3721
3520
|
...urlWithParsedQuery,
|
|
3722
|
-
query:
|
|
3521
|
+
query: request.queryObj,
|
|
3723
3522
|
search,
|
|
3724
3523
|
path: search ? `${urlWithParsedQuery.pathname}?${search}` : urlWithParsedQuery.pathname
|
|
3725
3524
|
};
|
|
@@ -3733,7 +3532,7 @@ var HTTPSnippet = class {
|
|
|
3733
3532
|
...uriObj
|
|
3734
3533
|
});
|
|
3735
3534
|
return {
|
|
3736
|
-
...
|
|
3535
|
+
...request,
|
|
3737
3536
|
allHeaders,
|
|
3738
3537
|
fullUrl,
|
|
3739
3538
|
url: url$1,
|
|
@@ -3752,7 +3551,7 @@ var HTTPSnippet = class {
|
|
|
3752
3551
|
return false;
|
|
3753
3552
|
}
|
|
3754
3553
|
const { convert } = target.clientsById[clientId || target.info.default];
|
|
3755
|
-
const results = this.requests.map((
|
|
3554
|
+
const results = this.requests.map((request) => convert(request, options));
|
|
3756
3555
|
return results;
|
|
3757
3556
|
}
|
|
3758
3557
|
};
|