@readme/httpsnippet 10.1.0 → 10.1.1

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/dist/index.cjs CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  var url = require('url');
4
4
  var qs = require('qs');
5
- var stringifyObject7 = require('stringify-object');
5
+ var stringifyObject9 = require('stringify-object');
6
6
 
7
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
8
 
9
- var stringifyObject7__default = /*#__PURE__*/_interopDefault(stringifyObject7);
9
+ var stringifyObject9__default = /*#__PURE__*/_interopDefault(stringifyObject9);
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 = stringifyObject7__default.default(requestOptions, {
981
+ const optionString = stringifyObject9__default.default(requestOptions, {
982
982
  indent: " ",
983
983
  inlineCharacterLimit: 80
984
984
  }).replace('"[form]"', "form");
@@ -986,8 +986,12 @@ var axios = {
986
986
  blank();
987
987
  push("axios");
988
988
  push(".request(options)", 1);
989
- push(".then(res => console.log(res.data))", 1);
990
- push(".catch(err => console.error(err));", 1);
989
+ push(".then(function (response) {", 1);
990
+ push("console.log(response.data);", 2);
991
+ push("})", 1);
992
+ push(".catch(function (error) {", 1);
993
+ push("console.error(error);", 2);
994
+ push("});", 1);
991
995
  return join();
992
996
  }
993
997
  };
@@ -1047,7 +1051,7 @@ var fetch = {
1047
1051
  delete options.headers;
1048
1052
  }
1049
1053
  push(
1050
- `const options = ${stringifyObject7__default.default(options, {
1054
+ `const options = ${stringifyObject9__default.default(options, {
1051
1055
  indent: opts.indent,
1052
1056
  inlineCharacterLimit: 80,
1053
1057
  // The Fetch API body only accepts string parameters, but stringified JSON can be difficult
@@ -1071,8 +1075,8 @@ var fetch = {
1071
1075
  blank();
1072
1076
  }
1073
1077
  push(`fetch('${fullUrl}', options)`);
1074
- push(".then(res => res.json())", 1);
1075
- push(".then(res => console.log(res))", 1);
1078
+ push(".then(response => response.json())", 1);
1079
+ push(".then(response => console.log(response))", 1);
1076
1080
  push(".catch(err => console.error(err));", 1);
1077
1081
  return join();
1078
1082
  }
@@ -1133,11 +1137,11 @@ var jquery = {
1133
1137
  settings.data = postData.text;
1134
1138
  }
1135
1139
  }
1136
- const stringifiedSettings = stringifyObject7__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
1140
+ const stringifiedSettings = stringifyObject9__default.default(settings, { indent: opts.indent }).replace("'[form]'", "form");
1137
1141
  push(`const settings = ${stringifiedSettings};`);
1138
1142
  blank();
1139
- push("$.ajax(settings).done(res => {");
1140
- push("console.log(res);", 1);
1143
+ push("$.ajax(settings).done(function (response) {");
1144
+ push("console.log(response);", 1);
1141
1145
  push("});");
1142
1146
  return join();
1143
1147
  }
@@ -1160,7 +1164,7 @@ var xhr = {
1160
1164
  switch (postData.mimeType) {
1161
1165
  case "application/json":
1162
1166
  push(
1163
- `const data = JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
1167
+ `const data = JSON.stringify(${stringifyObject9__default.default(postData.jsonObj, {
1164
1168
  indent: opts.indent
1165
1169
  })});`
1166
1170
  );
@@ -1214,7 +1218,7 @@ var javascript = {
1214
1218
  info: {
1215
1219
  key: "javascript",
1216
1220
  title: "JavaScript",
1217
- default: "fetch"
1221
+ default: "xhr"
1218
1222
  },
1219
1223
  clientsById: {
1220
1224
  xhr,
@@ -1353,7 +1357,7 @@ var axios2 = {
1353
1357
  title: "Axios",
1354
1358
  link: "https://github.com/axios/axios",
1355
1359
  description: "Promise based HTTP client for the browser and node.js",
1356
- extname: ".js",
1360
+ extname: ".cjs",
1357
1361
  installation: "npm install axios --save"
1358
1362
  },
1359
1363
  convert: ({ method, fullUrl, allHeaders, postData }, options) => {
@@ -1362,8 +1366,7 @@ var axios2 = {
1362
1366
  ...options
1363
1367
  };
1364
1368
  const { blank, join, push, addPostProcessor } = new CodeBuilder({ indent: opts.indent });
1365
- push("import axios from 'axios';");
1366
- blank();
1369
+ push("const axios = require('axios');");
1367
1370
  const reqOpts = {
1368
1371
  method,
1369
1372
  url: fullUrl
@@ -1374,6 +1377,8 @@ var axios2 = {
1374
1377
  switch (postData.mimeType) {
1375
1378
  case "application/x-www-form-urlencoded":
1376
1379
  if (postData.params) {
1380
+ push("const { URLSearchParams } = require('url');");
1381
+ blank();
1377
1382
  push("const encodedParams = new URLSearchParams();");
1378
1383
  postData.params.forEach((param) => {
1379
1384
  push(`encodedParams.set('${param.name}', '${param.value}');`);
@@ -1384,32 +1389,39 @@ var axios2 = {
1384
1389
  }
1385
1390
  break;
1386
1391
  case "application/json":
1392
+ blank();
1387
1393
  if (postData.jsonObj) {
1388
1394
  reqOpts.data = postData.jsonObj;
1389
1395
  }
1390
1396
  break;
1391
1397
  default:
1398
+ blank();
1392
1399
  if (postData.text) {
1393
1400
  reqOpts.data = postData.text;
1394
1401
  }
1395
1402
  }
1396
- const stringifiedOptions = stringifyObject7__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
1403
+ const stringifiedOptions = stringifyObject9__default.default(reqOpts, { indent: " ", inlineCharacterLimit: 80 });
1397
1404
  push(`const options = ${stringifiedOptions};`);
1398
1405
  blank();
1399
1406
  push("axios");
1400
1407
  push(".request(options)", 1);
1401
- push(".then(res => console.log(res.data))", 1);
1402
- push(".catch(err => console.error(err));", 1);
1408
+ push(".then(function (response) {", 1);
1409
+ push("console.log(response.data);", 2);
1410
+ push("})", 1);
1411
+ push(".catch(function (error) {", 1);
1412
+ push("console.error(error);", 2);
1413
+ push("});", 1);
1403
1414
  return join();
1404
1415
  }
1405
1416
  };
1406
1417
  var fetch2 = {
1407
1418
  info: {
1408
1419
  key: "fetch",
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"
1420
+ title: "Fetch",
1421
+ link: "https://github.com/bitinn/node-fetch",
1422
+ description: "Simplified HTTP node-fetch client",
1423
+ extname: ".cjs",
1424
+ installation: "npm install node-fetch@2 --save"
1413
1425
  },
1414
1426
  convert: ({ method, fullUrl, postData, headersObj, cookies }, options) => {
1415
1427
  const opts = {
@@ -1418,6 +1430,7 @@ var fetch2 = {
1418
1430
  };
1419
1431
  let includeFS = false;
1420
1432
  const { blank, push, join, unshift } = new CodeBuilder({ indent: opts.indent });
1433
+ push("const fetch = require('node-fetch');");
1421
1434
  const url = fullUrl;
1422
1435
  const reqOpts = {
1423
1436
  method
@@ -1427,12 +1440,13 @@ var fetch2 = {
1427
1440
  }
1428
1441
  switch (postData.mimeType) {
1429
1442
  case "application/x-www-form-urlencoded":
1443
+ unshift("const { URLSearchParams } = require('url');");
1430
1444
  push("const encodedParams = new URLSearchParams();");
1445
+ blank();
1431
1446
  postData.params?.forEach((param) => {
1432
1447
  push(`encodedParams.set('${param.name}', '${param.value}');`);
1433
1448
  });
1434
1449
  reqOpts.body = "encodedParams";
1435
- blank();
1436
1450
  break;
1437
1451
  case "application/json":
1438
1452
  if (postData.jsonObj) {
@@ -1447,7 +1461,9 @@ var fetch2 = {
1447
1461
  if (contentTypeHeader) {
1448
1462
  delete headersObj[contentTypeHeader];
1449
1463
  }
1464
+ unshift("const FormData = require('form-data');");
1450
1465
  push("const formData = new FormData();");
1466
+ blank();
1451
1467
  postData.params.forEach((param) => {
1452
1468
  if (!param.fileName && !param.fileName && !param.contentType) {
1453
1469
  push(`formData.append('${param.name}', '${param.value}');`);
@@ -1455,13 +1471,9 @@ var fetch2 = {
1455
1471
  }
1456
1472
  if (param.fileName) {
1457
1473
  includeFS = true;
1458
- push(
1459
- `formData.append('${param.name}', await new Response(fs.createReadStream('${param.fileName}')).blob());`
1460
- );
1474
+ push(`formData.append('${param.name}', fs.createReadStream('${param.fileName}'));`);
1461
1475
  }
1462
1476
  });
1463
- reqOpts.body = "formData";
1464
- blank();
1465
1477
  break;
1466
1478
  default:
1467
1479
  if (postData.text) {
@@ -1477,11 +1489,12 @@ var fetch2 = {
1477
1489
  reqOpts.headers.cookie = cookiesString;
1478
1490
  }
1479
1491
  }
1492
+ blank();
1480
1493
  push(`const url = '${url}';`);
1481
1494
  if (reqOpts.headers && !Object.keys(reqOpts.headers).length) {
1482
1495
  delete reqOpts.headers;
1483
1496
  }
1484
- const stringifiedOptions = stringifyObject7__default.default(reqOpts, {
1497
+ const stringifiedOptions = stringifyObject9__default.default(reqOpts, {
1485
1498
  indent: " ",
1486
1499
  inlineCharacterLimit: 80,
1487
1500
  // The Fetch API body only accepts string parameters, but stringified JSON can be difficult to
@@ -1497,13 +1510,17 @@ var fetch2 = {
1497
1510
  push(`const options = ${stringifiedOptions};`);
1498
1511
  blank();
1499
1512
  if (includeFS) {
1500
- unshift("import fs from 'fs';\n");
1513
+ unshift("const fs = require('fs');");
1514
+ }
1515
+ if (postData.params && postData.mimeType === "multipart/form-data") {
1516
+ push("options.body = formData;");
1517
+ blank();
1501
1518
  }
1502
1519
  push("fetch(url, options)");
1503
1520
  push(".then(res => res.json())", 1);
1504
1521
  push(".then(json => console.log(json))", 1);
1505
- push(".catch(err => console.error(err));", 1);
1506
- return join().replace(/'encodedParams'/, "encodedParams").replace(/'formData'/, "formData");
1522
+ push(".catch(err => console.error('error:' + err));", 1);
1523
+ return join().replace(/'encodedParams'/, "encodedParams").replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
1507
1524
  }
1508
1525
  };
1509
1526
  var native3 = {
@@ -1526,7 +1543,7 @@ var native3 = {
1526
1543
  };
1527
1544
  push(`const http = require('${uriObj.protocol?.replace(":", "")}');`);
1528
1545
  blank();
1529
- push(`const options = ${stringifyObject7__default.default(reqOpts, { indent })};`);
1546
+ push(`const options = ${stringifyObject9__default.default(reqOpts, { indent })};`);
1530
1547
  blank();
1531
1548
  push("const req = http.request(options, function (res) {");
1532
1549
  push("const chunks = [];", 1);
@@ -1546,7 +1563,7 @@ var native3 = {
1546
1563
  if (postData.paramsObj) {
1547
1564
  unshift("const qs = require('querystring');");
1548
1565
  push(
1549
- `req.write(qs.stringify(${stringifyObject7__default.default(postData.paramsObj, {
1566
+ `req.write(qs.stringify(${stringifyObject9__default.default(postData.paramsObj, {
1550
1567
  indent: " ",
1551
1568
  inlineCharacterLimit: 80
1552
1569
  })}));`
@@ -1556,7 +1573,7 @@ var native3 = {
1556
1573
  case "application/json":
1557
1574
  if (postData.jsonObj) {
1558
1575
  push(
1559
- `req.write(JSON.stringify(${stringifyObject7__default.default(postData.jsonObj, {
1576
+ `req.write(JSON.stringify(${stringifyObject9__default.default(postData.jsonObj, {
1560
1577
  indent: " ",
1561
1578
  inlineCharacterLimit: 80
1562
1579
  })}));`
@@ -1565,24 +1582,208 @@ var native3 = {
1565
1582
  break;
1566
1583
  default:
1567
1584
  if (postData.text) {
1568
- push(`req.write(${stringifyObject7__default.default(postData.text, { indent })});`);
1585
+ push(`req.write(${stringifyObject9__default.default(postData.text, { indent })});`);
1569
1586
  }
1570
1587
  }
1571
1588
  push("req.end();");
1572
1589
  return join();
1573
1590
  }
1574
1591
  };
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
+ };
1575
1774
 
1576
1775
  // src/targets/node/target.ts
1577
1776
  var node = {
1578
1777
  info: {
1579
1778
  key: "node",
1580
1779
  title: "Node.js",
1581
- default: "fetch",
1780
+ default: "native",
1582
1781
  cli: "node %s"
1583
1782
  },
1584
1783
  clientsById: {
1585
1784
  native: native3,
1785
+ request,
1786
+ unirest: unirest2,
1586
1787
  axios: axios2,
1587
1788
  fetch: fetch2
1588
1789
  }
@@ -2533,22 +2734,22 @@ var requests = {
2533
2734
  push("}");
2534
2735
  blank();
2535
2736
  }
2536
- let request = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
2737
+ let request2 = builtInMethods.includes(method) ? `response = requests.${method.toLowerCase()}(url` : `response = requests.request("${method}", url`;
2537
2738
  if (hasPayload) {
2538
2739
  if (jsonPayload) {
2539
- request += ", json=payload";
2740
+ request2 += ", json=payload";
2540
2741
  } else {
2541
- request += ", data=payload";
2742
+ request2 += ", data=payload";
2542
2743
  }
2543
2744
  }
2544
2745
  if (hasFiles) {
2545
- request += ", files=files";
2746
+ request2 += ", files=files";
2546
2747
  }
2547
2748
  if (headerCount > 0) {
2548
- request += ", headers=headers";
2749
+ request2 += ", headers=headers";
2549
2750
  }
2550
- request += ")";
2551
- push(request);
2751
+ request2 += ")";
2752
+ push(request2);
2552
2753
  blank();
2553
2754
  push("print(response.text)");
2554
2755
  return join();
@@ -2633,22 +2834,22 @@ var httr = {
2633
2834
  const setContentType = `content_type("${escapeForDoubleQuotes(postData.mimeType)}")`;
2634
2835
  const otherHeaders = Object.entries(allHeaders).filter(([key]) => !["cookie", "accept", "content-type"].includes(key.toLowerCase())).map(([key, value]) => `'${key}' = '${escapeForSingleQuotes(value)}'`).join(", ");
2635
2836
  const setHeaders = otherHeaders ? `add_headers(${otherHeaders})` : void 0;
2636
- let request = `response <- VERB("${method}", url`;
2837
+ let request2 = `response <- VERB("${method}", url`;
2637
2838
  if (payload) {
2638
- request += ", body = payload";
2839
+ request2 += ", body = payload";
2639
2840
  }
2640
2841
  if (queryString.length) {
2641
- request += ", query = queryString";
2842
+ request2 += ", query = queryString";
2642
2843
  }
2643
2844
  const headerAdditions = [setHeaders, setContentType, setAccept, setCookies].filter((x) => !!x).join(", ");
2644
2845
  if (headerAdditions) {
2645
- request += `, ${headerAdditions}`;
2846
+ request2 += `, ${headerAdditions}`;
2646
2847
  }
2647
2848
  if (postData.text || postData.jsonObj || postData.params) {
2648
- request += ", encode = encode";
2849
+ request2 += ", encode = encode";
2649
2850
  }
2650
- request += ")";
2651
- push(request);
2851
+ request2 += ")";
2852
+ push(request2);
2652
2853
  blank();
2653
2854
  push('content(response, "text")');
2654
2855
  return join();
@@ -3373,7 +3574,7 @@ var HTTPSnippet = class {
3373
3574
  }
3374
3575
  init() {
3375
3576
  this.initCalled = true;
3376
- this.requests = this.entries.map(({ request }) => {
3577
+ this.requests = this.entries.map(({ request: request2 }) => {
3377
3578
  const req = {
3378
3579
  bodySize: 0,
3379
3580
  headersSize: 0,
@@ -3382,9 +3583,9 @@ var HTTPSnippet = class {
3382
3583
  httpVersion: "HTTP/1.1",
3383
3584
  queryString: [],
3384
3585
  postData: {
3385
- mimeType: request.postData?.mimeType || "application/octet-stream"
3586
+ mimeType: request2.postData?.mimeType || "application/octet-stream"
3386
3587
  },
3387
- ...request
3588
+ ...request2
3388
3589
  };
3389
3590
  if (req.postData && !req.postData.mimeType) {
3390
3591
  req.postData.mimeType = "application/octet-stream";
@@ -3394,7 +3595,7 @@ var HTTPSnippet = class {
3394
3595
  return this;
3395
3596
  }
3396
3597
  prepare(harRequest, options) {
3397
- const request = {
3598
+ const request2 = {
3398
3599
  ...harRequest,
3399
3600
  fullUrl: "",
3400
3601
  uriObj: {},
@@ -3403,21 +3604,21 @@ var HTTPSnippet = class {
3403
3604
  cookiesObj: {},
3404
3605
  allHeaders: {}
3405
3606
  };
3406
- if (request.queryString && request.queryString.length) {
3407
- request.queryObj = request.queryString.reduce(reducer, {});
3607
+ if (request2.queryString && request2.queryString.length) {
3608
+ request2.queryObj = request2.queryString.reduce(reducer, {});
3408
3609
  }
3409
- if (request.headers && request.headers.length) {
3610
+ if (request2.headers && request2.headers.length) {
3410
3611
  const http2VersionRegex = /^HTTP\/2/;
3411
- request.headersObj = request.headers.reduce((accumulator, { name, value }) => {
3412
- const headerName = http2VersionRegex.exec(request.httpVersion) ? name.toLocaleLowerCase() : name;
3612
+ request2.headersObj = request2.headers.reduce((accumulator, { name, value }) => {
3613
+ const headerName = http2VersionRegex.exec(request2.httpVersion) ? name.toLocaleLowerCase() : name;
3413
3614
  return {
3414
3615
  ...accumulator,
3415
3616
  [headerName]: value
3416
3617
  };
3417
3618
  }, {});
3418
3619
  }
3419
- if (request.cookies && request.cookies.length) {
3420
- request.cookiesObj = request.cookies.reduceRight(
3620
+ if (request2.cookies && request2.cookies.length) {
3621
+ request2.cookiesObj = request2.cookies.reduceRight(
3421
3622
  (accumulator, { name, value }) => ({
3422
3623
  ...accumulator,
3423
3624
  [name]: value
@@ -3425,30 +3626,30 @@ var HTTPSnippet = class {
3425
3626
  {}
3426
3627
  );
3427
3628
  }
3428
- const cookies = request.cookies?.map(({ name, value }) => {
3629
+ const cookies = request2.cookies?.map(({ name, value }) => {
3429
3630
  if (options.harIsAlreadyEncoded) {
3430
3631
  return `${name}=${value}`;
3431
3632
  }
3432
3633
  return `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
3433
3634
  });
3434
3635
  if (cookies?.length) {
3435
- request.allHeaders.cookie = cookies.join("; ");
3636
+ request2.allHeaders.cookie = cookies.join("; ");
3436
3637
  }
3437
- switch (request.postData.mimeType) {
3638
+ switch (request2.postData.mimeType) {
3438
3639
  case "multipart/mixed":
3439
3640
  case "multipart/related":
3440
3641
  case "multipart/form-data":
3441
3642
  case "multipart/alternative":
3442
- request.postData.text = "";
3443
- request.postData.mimeType = "multipart/form-data";
3444
- if (request.postData?.params) {
3643
+ request2.postData.text = "";
3644
+ request2.postData.mimeType = "multipart/form-data";
3645
+ if (request2.postData?.params) {
3445
3646
  const boundary = "---011000010111000001101001";
3446
3647
  const carriage = `${boundary}--`;
3447
3648
  const rn = "\r\n";
3448
3649
  const escape2 = (str) => str.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
3449
3650
  const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, "\r\n");
3450
3651
  const payload = [`--${boundary}`];
3451
- request.postData?.params.forEach((param, i) => {
3652
+ request2.postData?.params.forEach((param, i) => {
3452
3653
  const name = param.name;
3453
3654
  const value = param.value || "";
3454
3655
  const filename = param.fileName || null;
@@ -3463,62 +3664,62 @@ var HTTPSnippet = class {
3463
3664
  }
3464
3665
  payload.push("");
3465
3666
  payload.push(normalizeLinefeeds(value));
3466
- if (i !== request.postData.params.length - 1) {
3667
+ if (i !== request2.postData.params.length - 1) {
3467
3668
  payload.push(`--${boundary}`);
3468
3669
  }
3469
3670
  });
3470
3671
  payload.push(`--${carriage}`);
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}`;
3672
+ request2.postData.boundary = boundary;
3673
+ request2.postData.text = payload.join(rn);
3674
+ const contentTypeHeader = getHeaderName(request2.headersObj, "content-type") || "content-type";
3675
+ request2.headersObj[contentTypeHeader] = `multipart/form-data; boundary=${boundary}`;
3475
3676
  }
3476
3677
  break;
3477
3678
  case "application/x-www-form-urlencoded":
3478
- if (!request.postData.params) {
3479
- request.postData.text = "";
3679
+ if (!request2.postData.params) {
3680
+ request2.postData.text = "";
3480
3681
  } else {
3481
- request.postData.paramsObj = request.postData.params.reduce(reducer, {});
3482
- request.postData.text = qs.stringify(request.postData.paramsObj);
3682
+ request2.postData.paramsObj = request2.postData.params.reduce(reducer, {});
3683
+ request2.postData.text = qs.stringify(request2.postData.paramsObj);
3483
3684
  }
3484
3685
  break;
3485
3686
  case "text/json":
3486
3687
  case "text/x-json":
3487
3688
  case "application/json":
3488
3689
  case "application/x-json":
3489
- request.postData.mimeType = "application/json";
3490
- if (request.postData.text) {
3690
+ request2.postData.mimeType = "application/json";
3691
+ if (request2.postData.text) {
3491
3692
  try {
3492
- request.postData.jsonObj = JSON.parse(request.postData.text);
3693
+ request2.postData.jsonObj = JSON.parse(request2.postData.text);
3493
3694
  } catch (e) {
3494
- request.postData.mimeType = "text/plain";
3695
+ request2.postData.mimeType = "text/plain";
3495
3696
  }
3496
3697
  }
3497
3698
  break;
3498
3699
  }
3499
3700
  const allHeaders = {
3500
- ...request.allHeaders,
3501
- ...request.headersObj
3701
+ ...request2.allHeaders,
3702
+ ...request2.headersObj
3502
3703
  };
3503
- const urlWithParsedQuery = url.parse(request.url, true, true);
3504
- request.queryObj = {
3505
- ...request.queryObj,
3704
+ const urlWithParsedQuery = url.parse(request2.url, true, true);
3705
+ request2.queryObj = {
3706
+ ...request2.queryObj,
3506
3707
  ...urlWithParsedQuery.query
3507
3708
  };
3508
3709
  let search;
3509
3710
  if (options.harIsAlreadyEncoded) {
3510
- search = qs.stringify(request.queryObj, {
3711
+ search = qs.stringify(request2.queryObj, {
3511
3712
  encode: false,
3512
3713
  indices: false
3513
3714
  });
3514
3715
  } else {
3515
- search = qs.stringify(request.queryObj, {
3716
+ search = qs.stringify(request2.queryObj, {
3516
3717
  indices: false
3517
3718
  });
3518
3719
  }
3519
3720
  const uriObj = {
3520
3721
  ...urlWithParsedQuery,
3521
- query: request.queryObj,
3722
+ query: request2.queryObj,
3522
3723
  search,
3523
3724
  path: search ? `${urlWithParsedQuery.pathname}?${search}` : urlWithParsedQuery.pathname
3524
3725
  };
@@ -3532,7 +3733,7 @@ var HTTPSnippet = class {
3532
3733
  ...uriObj
3533
3734
  });
3534
3735
  return {
3535
- ...request,
3736
+ ...request2,
3536
3737
  allHeaders,
3537
3738
  fullUrl,
3538
3739
  url: url$1,
@@ -3551,7 +3752,7 @@ var HTTPSnippet = class {
3551
3752
  return false;
3552
3753
  }
3553
3754
  const { convert } = target.clientsById[clientId || target.info.default];
3554
- const results = this.requests.map((request) => convert(request, options));
3755
+ const results = this.requests.map((request2) => convert(request2, options));
3555
3756
  return results;
3556
3757
  }
3557
3758
  };