@jaredwray/mockhttp 0.7.0 → 0.9.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/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ type HttpBinOptions = {
7
7
  requestInspection?: boolean;
8
8
  responseInspection?: boolean;
9
9
  statusCodes?: boolean;
10
+ responseFormats?: boolean;
10
11
  cookies?: boolean;
11
12
  anything?: boolean;
12
13
  auth?: boolean;
@@ -155,6 +156,7 @@ declare class MockHttp extends Hookified {
155
156
  * @param fastifyInstance - the server instance to register the routes on.
156
157
  */
157
158
  registerResponseInspectionRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
159
+ registerResponseFormatRoutes(fastifyInstance?: FastifyInstance): Promise<void>;
158
160
  /**
159
161
  * Register the redirect routes.
160
162
  * @param fastifyInstance - the server instance to register the routes on.
package/dist/index.js CHANGED
@@ -36,7 +36,6 @@ var anythingSchema = {
36
36
  "Anything"
37
37
  ],
38
38
  response: {
39
- // eslint-disable-next-line @typescript-eslint/naming-convention
40
39
  200: {
41
40
  type: "object",
42
41
  properties: {
@@ -190,7 +189,6 @@ var basicAuthSchema = {
190
189
  ]
191
190
  },
192
191
  response: {
193
- // eslint-disable-next-line @typescript-eslint/naming-convention
194
192
  200: {
195
193
  type: "object",
196
194
  properties: {
@@ -206,7 +204,6 @@ var basicAuthSchema = {
206
204
  "user"
207
205
  ]
208
206
  },
209
- // eslint-disable-next-line @typescript-eslint/naming-convention
210
207
  401: {
211
208
  type: "object",
212
209
  properties: {
@@ -271,7 +268,6 @@ var bearerAuthSchema = {
271
268
  }
272
269
  },
273
270
  response: {
274
- // eslint-disable-next-line @typescript-eslint/naming-convention
275
271
  200: {
276
272
  type: "object",
277
273
  properties: {
@@ -287,7 +283,6 @@ var bearerAuthSchema = {
287
283
  "token"
288
284
  ]
289
285
  },
290
- // eslint-disable-next-line @typescript-eslint/naming-convention
291
286
  401: {
292
287
  type: "object",
293
288
  properties: {
@@ -426,7 +421,6 @@ var digestAuthSchema = {
426
421
  algorithm: {
427
422
  type: "string"
428
423
  },
429
- // eslint-disable-next-line @typescript-eslint/naming-convention
430
424
  stale_after: {
431
425
  type: "string"
432
426
  }
@@ -599,7 +593,6 @@ var cookiesDeleteSchema = {
599
593
  additionalProperties: false
600
594
  },
601
595
  response: {
602
- // eslint-disable-next-line @typescript-eslint/naming-convention
603
596
  204: {
604
597
  type: "null"
605
598
  }
@@ -624,7 +617,6 @@ var getCookiesRouteSchema = {
624
617
  "Cookies"
625
618
  ],
626
619
  response: {
627
- // eslint-disable-next-line @typescript-eslint/naming-convention
628
620
  200: {
629
621
  type: "object",
630
622
  properties: {
@@ -679,7 +671,6 @@ var postCookieRouteSchema = {
679
671
  additionalProperties: false
680
672
  },
681
673
  response: {
682
- // eslint-disable-next-line @typescript-eslint/naming-convention
683
674
  200: {
684
675
  type: "object",
685
676
  properties: {
@@ -728,7 +719,6 @@ var deleteSchema = {
728
719
  description: "The body of the DELETE request"
729
720
  },
730
721
  response: {
731
- // eslint-disable-next-line @typescript-eslint/naming-convention
732
722
  200: {
733
723
  type: "object",
734
724
  properties: {
@@ -783,7 +773,6 @@ var getSchema = {
783
773
  description: "Headers sent in the request"
784
774
  },
785
775
  response: {
786
- // eslint-disable-next-line @typescript-eslint/naming-convention
787
776
  200: {
788
777
  type: "object",
789
778
  properties: {
@@ -833,7 +822,6 @@ var patchSchema = {
833
822
  description: "The body of the PATCH request"
834
823
  },
835
824
  response: {
836
- // eslint-disable-next-line @typescript-eslint/naming-convention
837
825
  200: {
838
826
  type: "object",
839
827
  properties: {
@@ -881,7 +869,6 @@ var postSchema = {
881
869
  description: "The body of the POST request"
882
870
  },
883
871
  response: {
884
- // eslint-disable-next-line @typescript-eslint/naming-convention
885
872
  200: {
886
873
  type: "object",
887
874
  properties: {
@@ -929,7 +916,6 @@ var putSchema = {
929
916
  description: "The body of the PUT request"
930
917
  },
931
918
  response: {
932
- // eslint-disable-next-line @typescript-eslint/naming-convention
933
919
  200: {
934
920
  type: "object",
935
921
  properties: {
@@ -1071,7 +1057,6 @@ var absoluteRedirectSchema = {
1071
1057
  ]
1072
1058
  },
1073
1059
  response: {
1074
- // eslint-disable-next-line @typescript-eslint/naming-convention
1075
1060
  302: {
1076
1061
  type: "string"
1077
1062
  }
@@ -1116,7 +1101,6 @@ var redirectToSchema = {
1116
1101
  format: "uri",
1117
1102
  description: "The URL to redirect to"
1118
1103
  },
1119
- // eslint-disable-next-line @typescript-eslint/naming-convention
1120
1104
  status_code: {
1121
1105
  type: "string",
1122
1106
  pattern: "^[1-5][0-9][0-9]$",
@@ -1182,7 +1166,6 @@ var relativeRedirectSchema = {
1182
1166
  ]
1183
1167
  },
1184
1168
  response: {
1185
- // eslint-disable-next-line @typescript-eslint/naming-convention
1186
1169
  302: {
1187
1170
  type: "string"
1188
1171
  }
@@ -1218,7 +1201,6 @@ var headersSchema = {
1218
1201
  "Request Inspection"
1219
1202
  ],
1220
1203
  response: {
1221
- // eslint-disable-next-line @typescript-eslint/naming-convention
1222
1204
  200: {
1223
1205
  type: "object",
1224
1206
  properties: {
@@ -1254,7 +1236,6 @@ var ipSchema = {
1254
1236
  "Request Inspection"
1255
1237
  ],
1256
1238
  response: {
1257
- // eslint-disable-next-line @typescript-eslint/naming-convention
1258
1239
  200: {
1259
1240
  type: "object",
1260
1241
  properties: {
@@ -1290,7 +1271,6 @@ var userAgentSchema = {
1290
1271
  "Request Inspection"
1291
1272
  ],
1292
1273
  response: {
1293
- // eslint-disable-next-line @typescript-eslint/naming-convention
1294
1274
  200: {
1295
1275
  type: "object",
1296
1276
  properties: {
@@ -1316,6 +1296,733 @@ var userAgentRoute = /* @__PURE__ */ __name((fastify) => {
1316
1296
  });
1317
1297
  }, "userAgentRoute");
1318
1298
 
1299
+ // src/routes/response-formats/index.ts
1300
+ import { brotliCompressSync, deflateSync, gzipSync } from "zlib";
1301
+ var plainSchema = {
1302
+ description: "Returns random plain text content",
1303
+ tags: [
1304
+ "Response Formats"
1305
+ ],
1306
+ response: {
1307
+ 200: {
1308
+ type: "string",
1309
+ description: "Random plain text content"
1310
+ }
1311
+ }
1312
+ };
1313
+ var textSchema = {
1314
+ description: "Returns random text content",
1315
+ tags: [
1316
+ "Response Formats"
1317
+ ],
1318
+ response: {
1319
+ 200: {
1320
+ type: "string",
1321
+ description: "Random text content"
1322
+ }
1323
+ }
1324
+ };
1325
+ var htmlSchema = {
1326
+ description: "Returns random HTML content",
1327
+ tags: [
1328
+ "Response Formats"
1329
+ ],
1330
+ response: {
1331
+ 200: {
1332
+ type: "string",
1333
+ description: "Random HTML content"
1334
+ }
1335
+ }
1336
+ };
1337
+ var xmlSchema = {
1338
+ description: "Returns random XML content",
1339
+ tags: [
1340
+ "Response Formats"
1341
+ ],
1342
+ response: {
1343
+ 200: {
1344
+ type: "string",
1345
+ description: "Random XML content"
1346
+ }
1347
+ }
1348
+ };
1349
+ var jsonSchema = {
1350
+ description: "Returns random JSON content",
1351
+ tags: [
1352
+ "Response Formats"
1353
+ ],
1354
+ response: {
1355
+ 200: {
1356
+ type: "object",
1357
+ description: "Random JSON content",
1358
+ additionalProperties: true
1359
+ }
1360
+ }
1361
+ };
1362
+ var denySchema = {
1363
+ description: "Returns page denied by robots.txt rules",
1364
+ tags: [
1365
+ "Response Formats"
1366
+ ],
1367
+ response: {
1368
+ 403: {
1369
+ type: "string",
1370
+ description: "Page denied by robots.txt rules"
1371
+ }
1372
+ }
1373
+ };
1374
+ var gzipSchema = {
1375
+ description: "Returns GZip-encoded data",
1376
+ tags: [
1377
+ "Response Formats"
1378
+ ],
1379
+ response: {
1380
+ 200: {
1381
+ type: "string",
1382
+ description: "GZip-encoded content"
1383
+ }
1384
+ }
1385
+ };
1386
+ var deflateSchema = {
1387
+ description: "Returns Deflate-encoded data",
1388
+ tags: [
1389
+ "Response Formats"
1390
+ ],
1391
+ response: {
1392
+ 200: {
1393
+ type: "string",
1394
+ description: "Deflate-encoded content"
1395
+ }
1396
+ }
1397
+ };
1398
+ var brotliSchema = {
1399
+ description: "Returns Brotli-encoded data",
1400
+ tags: [
1401
+ "Response Formats"
1402
+ ],
1403
+ response: {
1404
+ 200: {
1405
+ type: "string",
1406
+ description: "Brotli-encoded content"
1407
+ }
1408
+ }
1409
+ };
1410
+ var randomTexts = [
1411
+ "The quick brown fox jumps over the lazy dog.",
1412
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
1413
+ "To be or not to be, that is the question.",
1414
+ "All work and no play makes Jack a dull boy.",
1415
+ "The only way to do great work is to love what you do.",
1416
+ "In the beginning was the Word, and the Word was with God.",
1417
+ "Once upon a time in a galaxy far, far away...",
1418
+ "It was the best of times, it was the worst of times.",
1419
+ "The journey of a thousand miles begins with a single step.",
1420
+ "Knowledge is power. France is bacon."
1421
+ ];
1422
+ var randomHtmlContent = [
1423
+ `<!DOCTYPE html>
1424
+ <html lang="en">
1425
+ <head>
1426
+ <title>Sample Page</title>
1427
+ </head>
1428
+ <body>
1429
+ <h1>Welcome to MockHTTP</h1>
1430
+ <p>This is a sample HTML page with random content.</p>
1431
+ </body>
1432
+ </html>`,
1433
+ `<!DOCTYPE html>
1434
+ <html>
1435
+ <head>
1436
+ <meta charset="UTF-8">
1437
+ <title>Test Document</title>
1438
+ </head>
1439
+ <body>
1440
+ <header>
1441
+ <h1>Test Page</h1>
1442
+ <nav>
1443
+ <ul>
1444
+ <li><a href="#">Home</a></li>
1445
+ <li><a href="#">About</a></li>
1446
+ <li><a href="#">Contact</a></li>
1447
+ </ul>
1448
+ </nav>
1449
+ </header>
1450
+ <main>
1451
+ <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
1452
+ </main>
1453
+ </body>
1454
+ </html>`,
1455
+ `<!DOCTYPE html>
1456
+ <html lang="en">
1457
+ <head>
1458
+ <title>Article Page</title>
1459
+ <style>
1460
+ body { font-family: Arial, sans-serif; }
1461
+ article { max-width: 800px; margin: 0 auto; }
1462
+ </style>
1463
+ </head>
1464
+ <body>
1465
+ <article>
1466
+ <h1>The Journey Begins</h1>
1467
+ <p>Once upon a time in a digital world...</p>
1468
+ <blockquote>
1469
+ "The only way to do great work is to love what you do."
1470
+ </blockquote>
1471
+ </article>
1472
+ </body>
1473
+ </html>`,
1474
+ `<!DOCTYPE html>
1475
+ <html>
1476
+ <head>
1477
+ <title>Form Example</title>
1478
+ </head>
1479
+ <body>
1480
+ <h2>Contact Form</h2>
1481
+ <form action="/submit" method="post">
1482
+ <label for="name">Name:</label>
1483
+ <input type="text" id="name" name="name" required>
1484
+ <br>
1485
+ <label for="email">Email:</label>
1486
+ <input type="email" id="email" name="email" required>
1487
+ <br>
1488
+ <button type="submit">Submit</button>
1489
+ </form>
1490
+ </body>
1491
+ </html>`,
1492
+ `<!DOCTYPE html>
1493
+ <html lang="en">
1494
+ <head>
1495
+ <meta charset="UTF-8">
1496
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
1497
+ <title>Responsive Page</title>
1498
+ </head>
1499
+ <body>
1500
+ <div class="container">
1501
+ <h1>Responsive Design</h1>
1502
+ <p>This page adapts to different screen sizes.</p>
1503
+ <img src="placeholder.jpg" alt="Placeholder" style="max-width: 100%; height: auto;">
1504
+ </div>
1505
+ </body>
1506
+ </html>`
1507
+ ];
1508
+ var randomXmlContent = [
1509
+ `<?xml version="1.0" encoding="UTF-8"?>
1510
+ <root>
1511
+ <message>Hello from MockHTTP</message>
1512
+ <timestamp>${(/* @__PURE__ */ new Date()).toISOString()}</timestamp>
1513
+ <status>success</status>
1514
+ </root>`,
1515
+ `<?xml version="1.0" encoding="UTF-8"?>
1516
+ <book>
1517
+ <title>The Great Gatsby</title>
1518
+ <author>F. Scott Fitzgerald</author>
1519
+ <year>1925</year>
1520
+ <publisher>Charles Scribner's Sons</publisher>
1521
+ <isbn>978-0-7432-7356-5</isbn>
1522
+ </book>`,
1523
+ `<?xml version="1.0" encoding="UTF-8"?>
1524
+ <users>
1525
+ <user id="1">
1526
+ <name>John Doe</name>
1527
+ <email>john@example.com</email>
1528
+ <role>admin</role>
1529
+ </user>
1530
+ <user id="2">
1531
+ <name>Jane Smith</name>
1532
+ <email>jane@example.com</email>
1533
+ <role>user</role>
1534
+ </user>
1535
+ </users>`,
1536
+ `<?xml version="1.0" encoding="UTF-8"?>
1537
+ <product>
1538
+ <id>12345</id>
1539
+ <name>Wireless Mouse</name>
1540
+ <description>Ergonomic wireless mouse with 3-year battery life</description>
1541
+ <price currency="USD">29.99</price>
1542
+ <stock>150</stock>
1543
+ <category>Electronics</category>
1544
+ </product>`,
1545
+ `<?xml version="1.0" encoding="UTF-8"?>
1546
+ <rss version="2.0">
1547
+ <channel>
1548
+ <title>Mock RSS Feed</title>
1549
+ <link>http://example.com/rss</link>
1550
+ <description>Sample RSS feed from MockHTTP</description>
1551
+ <item>
1552
+ <title>First Article</title>
1553
+ <link>http://example.com/article1</link>
1554
+ <description>This is the first article in our feed</description>
1555
+ <pubDate>${(/* @__PURE__ */ new Date()).toUTCString()}</pubDate>
1556
+ </item>
1557
+ </channel>
1558
+ </rss>`
1559
+ ];
1560
+ var randomJsonContent = [
1561
+ () => ({
1562
+ message: "Hello from MockHTTP",
1563
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1564
+ status: "success",
1565
+ code: 200
1566
+ }),
1567
+ () => ({
1568
+ user: {
1569
+ id: 1,
1570
+ name: "John Doe",
1571
+ email: "john@example.com",
1572
+ role: "admin",
1573
+ createdAt: "2024-01-15T10:30:00Z"
1574
+ },
1575
+ permissions: [
1576
+ "read",
1577
+ "write",
1578
+ "delete"
1579
+ ]
1580
+ }),
1581
+ () => ({
1582
+ products: [
1583
+ {
1584
+ id: 101,
1585
+ name: "Laptop",
1586
+ price: 999.99,
1587
+ stock: 50
1588
+ },
1589
+ {
1590
+ id: 102,
1591
+ name: "Mouse",
1592
+ price: 29.99,
1593
+ stock: 200
1594
+ }
1595
+ ],
1596
+ total: 2,
1597
+ page: 1
1598
+ }),
1599
+ () => ({
1600
+ config: {
1601
+ theme: "dark",
1602
+ language: "en",
1603
+ notifications: {
1604
+ email: true,
1605
+ push: false,
1606
+ sms: false
1607
+ },
1608
+ privacy: {
1609
+ profile: "public",
1610
+ activity: "friends"
1611
+ }
1612
+ }
1613
+ }),
1614
+ () => ({
1615
+ metrics: {
1616
+ cpu: 45.2,
1617
+ memory: 78.5,
1618
+ disk: 62.3,
1619
+ network: {
1620
+ inbound: "1.2MB/s",
1621
+ outbound: "0.8MB/s"
1622
+ },
1623
+ uptime: "15 days",
1624
+ services: [
1625
+ {
1626
+ name: "api",
1627
+ status: "healthy"
1628
+ },
1629
+ {
1630
+ name: "database",
1631
+ status: "healthy"
1632
+ },
1633
+ {
1634
+ name: "cache",
1635
+ status: "warning"
1636
+ }
1637
+ ]
1638
+ }
1639
+ })
1640
+ ];
1641
+ var responseFormatRoutes = /* @__PURE__ */ __name((fastify) => {
1642
+ const plainHandler = /* @__PURE__ */ __name(async (_request, reply) => {
1643
+ const randomIndex = Math.floor(Math.random() * randomTexts.length);
1644
+ const text = randomTexts[randomIndex];
1645
+ reply.type("text/plain");
1646
+ return text;
1647
+ }, "plainHandler");
1648
+ fastify.get("/plain", {
1649
+ schema: plainSchema
1650
+ }, plainHandler);
1651
+ fastify.post("/plain", {
1652
+ schema: plainSchema
1653
+ }, plainHandler);
1654
+ fastify.put("/plain", {
1655
+ schema: plainSchema
1656
+ }, plainHandler);
1657
+ fastify.patch("/plain", {
1658
+ schema: plainSchema
1659
+ }, plainHandler);
1660
+ fastify.delete("/plain", {
1661
+ schema: plainSchema
1662
+ }, plainHandler);
1663
+ const textHandler = /* @__PURE__ */ __name(async (_request, reply) => {
1664
+ const randomIndex = Math.floor(Math.random() * randomTexts.length);
1665
+ const text = randomTexts[randomIndex];
1666
+ reply.type("text/plain");
1667
+ return text;
1668
+ }, "textHandler");
1669
+ fastify.get("/text", {
1670
+ schema: textSchema
1671
+ }, textHandler);
1672
+ fastify.post("/text", {
1673
+ schema: textSchema
1674
+ }, textHandler);
1675
+ fastify.put("/text", {
1676
+ schema: textSchema
1677
+ }, textHandler);
1678
+ fastify.patch("/text", {
1679
+ schema: textSchema
1680
+ }, textHandler);
1681
+ fastify.delete("/text", {
1682
+ schema: textSchema
1683
+ }, textHandler);
1684
+ const htmlHandler = /* @__PURE__ */ __name(async (_request, reply) => {
1685
+ const randomIndex = Math.floor(Math.random() * randomHtmlContent.length);
1686
+ const html = randomHtmlContent[randomIndex];
1687
+ reply.type("text/html");
1688
+ return html;
1689
+ }, "htmlHandler");
1690
+ fastify.get("/html", {
1691
+ schema: htmlSchema
1692
+ }, htmlHandler);
1693
+ fastify.post("/html", {
1694
+ schema: htmlSchema
1695
+ }, htmlHandler);
1696
+ fastify.put("/html", {
1697
+ schema: htmlSchema
1698
+ }, htmlHandler);
1699
+ fastify.patch("/html", {
1700
+ schema: htmlSchema
1701
+ }, htmlHandler);
1702
+ fastify.delete("/html", {
1703
+ schema: htmlSchema
1704
+ }, htmlHandler);
1705
+ const xmlHandler = /* @__PURE__ */ __name(async (_request, reply) => {
1706
+ const randomIndex = Math.floor(Math.random() * randomXmlContent.length);
1707
+ const xml = randomXmlContent[randomIndex];
1708
+ reply.type("application/xml");
1709
+ return xml;
1710
+ }, "xmlHandler");
1711
+ fastify.get("/xml", {
1712
+ schema: xmlSchema
1713
+ }, xmlHandler);
1714
+ fastify.post("/xml", {
1715
+ schema: xmlSchema
1716
+ }, xmlHandler);
1717
+ fastify.put("/xml", {
1718
+ schema: xmlSchema
1719
+ }, xmlHandler);
1720
+ fastify.patch("/xml", {
1721
+ schema: xmlSchema
1722
+ }, xmlHandler);
1723
+ fastify.delete("/xml", {
1724
+ schema: xmlSchema
1725
+ }, xmlHandler);
1726
+ const jsonHandler = /* @__PURE__ */ __name(async (_request, reply) => {
1727
+ const randomIndex = Math.floor(Math.random() * randomJsonContent.length);
1728
+ const jsonGenerator = randomJsonContent[randomIndex];
1729
+ const json = jsonGenerator();
1730
+ reply.type("application/json");
1731
+ return json;
1732
+ }, "jsonHandler");
1733
+ fastify.get("/json", {
1734
+ schema: jsonSchema
1735
+ }, jsonHandler);
1736
+ fastify.post("/json", {
1737
+ schema: jsonSchema
1738
+ }, jsonHandler);
1739
+ fastify.put("/json", {
1740
+ schema: jsonSchema
1741
+ }, jsonHandler);
1742
+ fastify.patch("/json", {
1743
+ schema: jsonSchema
1744
+ }, jsonHandler);
1745
+ fastify.delete("/json", {
1746
+ schema: jsonSchema
1747
+ }, jsonHandler);
1748
+ const denyHandler = /* @__PURE__ */ __name(async (_request, reply) => {
1749
+ const denyMessages = [
1750
+ `<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
1751
+ <html><head>
1752
+ <title>403 Forbidden</title>
1753
+ </head><body>
1754
+ <h1>Forbidden</h1>
1755
+ <p>Access denied by robots.txt rules.</p>
1756
+ <p>The requested resource is disallowed by robots.txt.</p>
1757
+ </body></html>`,
1758
+ `<!DOCTYPE html>
1759
+ <html lang="en">
1760
+ <head>
1761
+ <meta charset="UTF-8">
1762
+ <title>403 - Access Denied</title>
1763
+ </head>
1764
+ <body>
1765
+ <h1>403 Forbidden</h1>
1766
+ <p>This page is blocked by robots.txt rules.</p>
1767
+ <p>User-agent: *<br>Disallow: ${_request.url}</p>
1768
+ </body>
1769
+ </html>`,
1770
+ `<!DOCTYPE html>
1771
+ <html>
1772
+ <head>
1773
+ <title>403 - Access Denied</title>
1774
+ <style>body { font-family: Arial, sans-serif; margin: 40px; }</style>
1775
+ </head>
1776
+ <body>
1777
+ <h2>403 - Access Denied by robots.txt</h2>
1778
+ <p>The robots.txt file prevents access to this resource.</p>
1779
+ <hr>
1780
+ <small>MockHTTP Server</small>
1781
+ </body>
1782
+ </html>`
1783
+ ];
1784
+ const randomIndex = Math.floor(Math.random() * denyMessages.length);
1785
+ const html = denyMessages[randomIndex];
1786
+ reply.code(403);
1787
+ reply.type("text/html");
1788
+ return html;
1789
+ }, "denyHandler");
1790
+ fastify.get("/deny", {
1791
+ schema: denySchema
1792
+ }, denyHandler);
1793
+ fastify.post("/deny", {
1794
+ schema: denySchema
1795
+ }, denyHandler);
1796
+ fastify.put("/deny", {
1797
+ schema: denySchema
1798
+ }, denyHandler);
1799
+ fastify.patch("/deny", {
1800
+ schema: denySchema
1801
+ }, denyHandler);
1802
+ fastify.delete("/deny", {
1803
+ schema: denySchema
1804
+ }, denyHandler);
1805
+ const gzipHandler = /* @__PURE__ */ __name(async (_request, reply) => {
1806
+ const sampleData = [
1807
+ {
1808
+ message: "This is GZip compressed data from MockHTTP",
1809
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1810
+ compression: "gzip",
1811
+ originalSize: 0,
1812
+ compressedSize: 0
1813
+ },
1814
+ {
1815
+ title: "Sample Document",
1816
+ content: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. ".repeat(50),
1817
+ metadata: {
1818
+ author: "MockHTTP Server",
1819
+ format: "gzip",
1820
+ version: "1.0"
1821
+ }
1822
+ },
1823
+ {
1824
+ data: Array.from({
1825
+ length: 100
1826
+ }, (_, i) => ({
1827
+ id: i + 1,
1828
+ value: `Item ${i + 1}`,
1829
+ description: `This is item number ${i + 1} in the dataset`
1830
+ })),
1831
+ info: "Large dataset compressed with GZip"
1832
+ }
1833
+ ];
1834
+ const randomIndex = Math.floor(Math.random() * sampleData.length);
1835
+ const data = sampleData[randomIndex];
1836
+ const jsonString = JSON.stringify(data);
1837
+ if (data.originalSize !== void 0) {
1838
+ data.originalSize = Buffer.byteLength(jsonString);
1839
+ }
1840
+ const compressed = gzipSync(jsonString);
1841
+ if (data.compressedSize !== void 0) {
1842
+ const updatedData = {
1843
+ ...data,
1844
+ compressedSize: compressed.length
1845
+ };
1846
+ const updatedJsonString = JSON.stringify(updatedData);
1847
+ const updatedCompressed = gzipSync(updatedJsonString);
1848
+ reply.header("Content-Encoding", "gzip");
1849
+ reply.header("Content-Type", "application/json");
1850
+ reply.type("application/octet-stream");
1851
+ return updatedCompressed;
1852
+ }
1853
+ reply.header("Content-Encoding", "gzip");
1854
+ reply.header("Content-Type", "application/json");
1855
+ reply.type("application/octet-stream");
1856
+ return compressed;
1857
+ }, "gzipHandler");
1858
+ fastify.get("/gzip", {
1859
+ schema: gzipSchema
1860
+ }, gzipHandler);
1861
+ fastify.post("/gzip", {
1862
+ schema: gzipSchema
1863
+ }, gzipHandler);
1864
+ fastify.put("/gzip", {
1865
+ schema: gzipSchema
1866
+ }, gzipHandler);
1867
+ fastify.patch("/gzip", {
1868
+ schema: gzipSchema
1869
+ }, gzipHandler);
1870
+ fastify.delete("/gzip", {
1871
+ schema: gzipSchema
1872
+ }, gzipHandler);
1873
+ const deflateHandler = /* @__PURE__ */ __name(async (_request, reply) => {
1874
+ const sampleData = [
1875
+ {
1876
+ message: "This is Deflate compressed data from MockHTTP",
1877
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1878
+ compression: "deflate",
1879
+ originalSize: 0,
1880
+ compressedSize: 0
1881
+ },
1882
+ {
1883
+ title: "Deflate Compressed Document",
1884
+ content: "The deflate algorithm is used for compression. ".repeat(40),
1885
+ details: {
1886
+ algorithm: "DEFLATE",
1887
+ method: "zlib deflate",
1888
+ server: "MockHTTP"
1889
+ }
1890
+ },
1891
+ {
1892
+ items: Array.from({
1893
+ length: 50
1894
+ }, (_, i) => ({
1895
+ index: i,
1896
+ name: `Entry ${i}`,
1897
+ data: `This is test data for entry number ${i}`,
1898
+ timestamp: new Date(Date.now() - i * 1e6).toISOString()
1899
+ })),
1900
+ metadata: {
1901
+ compression: "deflate",
1902
+ count: 50
1903
+ }
1904
+ }
1905
+ ];
1906
+ const randomIndex = Math.floor(Math.random() * sampleData.length);
1907
+ const data = sampleData[randomIndex];
1908
+ const jsonString = JSON.stringify(data);
1909
+ if (data.originalSize !== void 0) {
1910
+ data.originalSize = Buffer.byteLength(jsonString);
1911
+ }
1912
+ const compressed = deflateSync(jsonString);
1913
+ if (data.compressedSize !== void 0) {
1914
+ const updatedData = {
1915
+ ...data,
1916
+ compressedSize: compressed.length
1917
+ };
1918
+ const updatedJsonString = JSON.stringify(updatedData);
1919
+ const updatedCompressed = deflateSync(updatedJsonString);
1920
+ reply.header("Content-Encoding", "deflate");
1921
+ reply.header("Content-Type", "application/json");
1922
+ reply.type("application/octet-stream");
1923
+ return updatedCompressed;
1924
+ }
1925
+ reply.header("Content-Encoding", "deflate");
1926
+ reply.header("Content-Type", "application/json");
1927
+ reply.type("application/octet-stream");
1928
+ return compressed;
1929
+ }, "deflateHandler");
1930
+ fastify.get("/deflate", {
1931
+ schema: deflateSchema
1932
+ }, deflateHandler);
1933
+ fastify.post("/deflate", {
1934
+ schema: deflateSchema
1935
+ }, deflateHandler);
1936
+ fastify.put("/deflate", {
1937
+ schema: deflateSchema
1938
+ }, deflateHandler);
1939
+ fastify.patch("/deflate", {
1940
+ schema: deflateSchema
1941
+ }, deflateHandler);
1942
+ fastify.delete("/deflate", {
1943
+ schema: deflateSchema
1944
+ }, deflateHandler);
1945
+ const brotliHandler = /* @__PURE__ */ __name(async (_request, reply) => {
1946
+ const sampleData = [
1947
+ {
1948
+ message: "This is Brotli compressed data from MockHTTP",
1949
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
1950
+ compression: "br",
1951
+ algorithm: "Brotli",
1952
+ originalSize: 0,
1953
+ compressedSize: 0
1954
+ },
1955
+ {
1956
+ title: "Brotli Compression Example",
1957
+ description: "Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling.",
1958
+ content: "Brotli compression typically achieves 20-26% better compression ratios than gzip. ".repeat(10),
1959
+ metadata: {
1960
+ encoding: "br",
1961
+ quality: 11,
1962
+ server: "MockHTTP"
1963
+ }
1964
+ },
1965
+ {
1966
+ benchmark: {
1967
+ title: "Compression Benchmark Data",
1968
+ results: Array.from({
1969
+ length: 75
1970
+ }, (_, i) => ({
1971
+ id: `test-${i}`,
1972
+ name: `Benchmark Test ${i}`,
1973
+ value: Math.random() * 1e3,
1974
+ unit: "ms",
1975
+ timestamp: new Date(Date.now() - i * 6e4).toISOString()
1976
+ })),
1977
+ summary: {
1978
+ compression: "brotli",
1979
+ totalTests: 75,
1980
+ encoding: "br"
1981
+ }
1982
+ }
1983
+ }
1984
+ ];
1985
+ const randomIndex = Math.floor(Math.random() * sampleData.length);
1986
+ const data = sampleData[randomIndex];
1987
+ const jsonString = JSON.stringify(data);
1988
+ if (data.originalSize !== void 0) {
1989
+ data.originalSize = Buffer.byteLength(jsonString);
1990
+ }
1991
+ const compressed = brotliCompressSync(jsonString);
1992
+ if (data.compressedSize !== void 0) {
1993
+ const updatedData = {
1994
+ ...data,
1995
+ compressedSize: compressed.length
1996
+ };
1997
+ const updatedJsonString = JSON.stringify(updatedData);
1998
+ const updatedCompressed = brotliCompressSync(updatedJsonString);
1999
+ reply.header("Content-Encoding", "br");
2000
+ reply.header("Content-Type", "application/json");
2001
+ reply.type("application/octet-stream");
2002
+ return updatedCompressed;
2003
+ }
2004
+ reply.header("Content-Encoding", "br");
2005
+ reply.header("Content-Type", "application/json");
2006
+ reply.type("application/octet-stream");
2007
+ return compressed;
2008
+ }, "brotliHandler");
2009
+ fastify.get("/brotli", {
2010
+ schema: brotliSchema
2011
+ }, brotliHandler);
2012
+ fastify.post("/brotli", {
2013
+ schema: brotliSchema
2014
+ }, brotliHandler);
2015
+ fastify.put("/brotli", {
2016
+ schema: brotliSchema
2017
+ }, brotliHandler);
2018
+ fastify.patch("/brotli", {
2019
+ schema: brotliSchema
2020
+ }, brotliHandler);
2021
+ fastify.delete("/brotli", {
2022
+ schema: brotliSchema
2023
+ }, brotliHandler);
2024
+ }, "responseFormatRoutes");
2025
+
1319
2026
  // src/routes/response-inspection/cache.ts
1320
2027
  var cacheGetSchema = {
1321
2028
  description: "Handles cache validation and retrieval.",
@@ -1323,12 +2030,10 @@ var cacheGetSchema = {
1323
2030
  "Response Inspection"
1324
2031
  ],
1325
2032
  response: {
1326
- // eslint-disable-next-line @typescript-eslint/naming-convention
1327
2033
  200: {
1328
2034
  type: "string",
1329
2035
  description: "The cached content or resource."
1330
2036
  },
1331
- // eslint-disable-next-line @typescript-eslint/naming-convention
1332
2037
  304: {
1333
2038
  type: "null",
1334
2039
  description: "Indicates the resource has not been modified."
@@ -1353,7 +2058,6 @@ var cacheSetSchema = {
1353
2058
  ]
1354
2059
  },
1355
2060
  response: {
1356
- // eslint-disable-next-line @typescript-eslint/naming-convention
1357
2061
  200: {
1358
2062
  type: "string",
1359
2063
  description: "Confirmation message for setting cache."
@@ -1399,17 +2103,14 @@ var etagSchema = {
1399
2103
  ]
1400
2104
  },
1401
2105
  response: {
1402
- // eslint-disable-next-line @typescript-eslint/naming-convention
1403
2106
  200: {
1404
2107
  type: "string",
1405
2108
  description: "Resource content for matching ETag."
1406
2109
  },
1407
- // eslint-disable-next-line @typescript-eslint/naming-convention
1408
2110
  304: {
1409
2111
  type: "null",
1410
2112
  description: "Indicates the resource has not been modified."
1411
2113
  },
1412
- // eslint-disable-next-line @typescript-eslint/naming-convention
1413
2114
  412: {
1414
2115
  type: "null",
1415
2116
  description: "Indicates a precondition failed due to mismatched ETag."
@@ -1448,7 +2149,6 @@ var responseHeadersSchema = {
1448
2149
  description: "Freeform query string parameters to be added as response headers."
1449
2150
  },
1450
2151
  response: {
1451
- // eslint-disable-next-line @typescript-eslint/naming-convention
1452
2152
  200: {
1453
2153
  type: "object",
1454
2154
  additionalProperties: true,
@@ -1792,7 +2492,6 @@ var statusSchema = {
1792
2492
  }
1793
2493
  },
1794
2494
  response: {
1795
- // eslint-disable-next-line @typescript-eslint/naming-convention
1796
2495
  200: {
1797
2496
  type: "object",
1798
2497
  properties: {
@@ -1836,7 +2535,7 @@ import { fastifySwaggerUi } from "@fastify/swagger-ui";
1836
2535
  // package.json
1837
2536
  var package_default = {
1838
2537
  name: "@jaredwray/mockhttp",
1839
- version: "0.7.0",
2538
+ version: "0.9.0",
1840
2539
  description: "Mock Http - Easy way to mock http with httpbin replacement",
1841
2540
  type: "module",
1842
2541
  main: "dist/index.js",
@@ -1877,12 +2576,12 @@ var package_default = {
1877
2576
  homepage: "https://github.com/jaredwray/mockhttp#readme",
1878
2577
  devDependencies: {
1879
2578
  "@biomejs/biome": "^2.2.2",
1880
- "@swc/core": "^1.13.4",
2579
+ "@swc/core": "^1.13.5",
1881
2580
  "@types/html-escaper": "^3.0.4",
1882
2581
  "@vitest/coverage-v8": "^3.2.4",
1883
2582
  rimraf: "^6.0.1",
1884
2583
  tsup: "^8.5.0",
1885
- tsx: "^4.20.4",
2584
+ tsx: "^4.20.5",
1886
2585
  typescript: "^5.9.2",
1887
2586
  vitest: "^3.2.4"
1888
2587
  },
@@ -1892,7 +2591,7 @@ var package_default = {
1892
2591
  "@fastify/static": "^8.2.0",
1893
2592
  "@fastify/swagger": "^9.5.1",
1894
2593
  "@fastify/swagger-ui": "^5.2.3",
1895
- "@scalar/api-reference": "^1.34.4",
2594
+ "@scalar/api-reference": "^1.34.6",
1896
2595
  "detect-port": "^2.1.0",
1897
2596
  fastify: "^5.5.0",
1898
2597
  hookified: "^1.12.0",
@@ -1957,7 +2656,6 @@ var registerSwaggerUi = /* @__PURE__ */ __name(async (fastify) => {
1957
2656
  next();
1958
2657
  }
1959
2658
  },
1960
- // eslint-disable-next-line @typescript-eslint/naming-convention
1961
2659
  staticCSP: true,
1962
2660
  transformSpecification: /* @__PURE__ */ __name((swaggerObject, _request, _reply) => swaggerObject, "transformSpecification"),
1963
2661
  transformSpecificationClone: true
@@ -1979,12 +2677,12 @@ var MockHttp = class extends Hookified {
1979
2677
  redirects: true,
1980
2678
  requestInspection: true,
1981
2679
  responseInspection: true,
2680
+ responseFormats: true,
1982
2681
  statusCodes: true,
1983
2682
  cookies: true,
1984
2683
  anything: true,
1985
2684
  auth: true
1986
2685
  };
1987
- // eslint-disable-next-line new-cap
1988
2686
  _server = Fastify();
1989
2687
  constructor(options) {
1990
2688
  super(options?.hookOptions);
@@ -2122,7 +2820,7 @@ var MockHttp = class extends Hookified {
2122
2820
  if (this._apiDocs) {
2123
2821
  await this.registerApiDocs();
2124
2822
  }
2125
- const { httpMethods, redirects, requestInspection, responseInspection, statusCodes: statusCodes2, cookies, anything, auth } = this._httpBin;
2823
+ const { httpMethods, redirects, requestInspection, responseInspection, responseFormats, statusCodes: statusCodes2, cookies, anything, auth } = this._httpBin;
2126
2824
  if (httpMethods) {
2127
2825
  await this.registerHttpMethods();
2128
2826
  }
@@ -2135,6 +2833,9 @@ var MockHttp = class extends Hookified {
2135
2833
  if (responseInspection) {
2136
2834
  await this.registerResponseInspectionRoutes();
2137
2835
  }
2836
+ if (responseFormats) {
2837
+ await this.registerResponseFormatRoutes();
2838
+ }
2138
2839
  if (redirects) {
2139
2840
  await this.registerRedirectRoutes();
2140
2841
  }
@@ -2226,6 +2927,10 @@ var MockHttp = class extends Hookified {
2226
2927
  await fastify.register(etagRoutes);
2227
2928
  await fastify.register(responseHeadersRoutes);
2228
2929
  }
2930
+ async registerResponseFormatRoutes(fastifyInstance) {
2931
+ const fastify = fastifyInstance ?? this._server;
2932
+ await fastify.register(responseFormatRoutes);
2933
+ }
2229
2934
  /**
2230
2935
  * Register the redirect routes.
2231
2936
  * @param fastifyInstance - the server instance to register the routes on.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaredwray/mockhttp",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "Mock Http - Easy way to mock http with httpbin replacement",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -41,12 +41,12 @@
41
41
  "homepage": "https://github.com/jaredwray/mockhttp#readme",
42
42
  "devDependencies": {
43
43
  "@biomejs/biome": "^2.2.2",
44
- "@swc/core": "^1.13.4",
44
+ "@swc/core": "^1.13.5",
45
45
  "@types/html-escaper": "^3.0.4",
46
46
  "@vitest/coverage-v8": "^3.2.4",
47
47
  "rimraf": "^6.0.1",
48
48
  "tsup": "^8.5.0",
49
- "tsx": "^4.20.4",
49
+ "tsx": "^4.20.5",
50
50
  "typescript": "^5.9.2",
51
51
  "vitest": "^3.2.4"
52
52
  },
@@ -56,7 +56,7 @@
56
56
  "@fastify/static": "^8.2.0",
57
57
  "@fastify/swagger": "^9.5.1",
58
58
  "@fastify/swagger-ui": "^5.2.3",
59
- "@scalar/api-reference": "^1.34.4",
59
+ "@scalar/api-reference": "^1.34.6",
60
60
  "detect-port": "^2.1.0",
61
61
  "fastify": "^5.5.0",
62
62
  "hookified": "^1.12.0",