minimalistic-server 0.0.56 → 0.0.57
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/index.mjs +30 -8
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1630,9 +1630,11 @@ export class Response {
|
|
|
1630
1630
|
cookieStrings.push(cookieString);
|
|
1631
1631
|
}
|
|
1632
1632
|
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1633
|
+
if (cookieStrings.length) {
|
|
1634
|
+
headers = {
|
|
1635
|
+
...headers,
|
|
1636
|
+
'Set-Cookie': cookieStrings,
|
|
1637
|
+
}
|
|
1636
1638
|
}
|
|
1637
1639
|
}
|
|
1638
1640
|
|
|
@@ -1699,6 +1701,7 @@ export class FileResponse extends Response {
|
|
|
1699
1701
|
#urlPathForDirectory = null;
|
|
1700
1702
|
|
|
1701
1703
|
#blocked = false;
|
|
1704
|
+
#proxiedResponse = null;
|
|
1702
1705
|
|
|
1703
1706
|
constructor(filePath, code = 200, contentType = null, cookies = null) {
|
|
1704
1707
|
super();
|
|
@@ -1709,6 +1712,10 @@ export class FileResponse extends Response {
|
|
|
1709
1712
|
}
|
|
1710
1713
|
|
|
1711
1714
|
async getCode(headers = null) {
|
|
1715
|
+
if (this.#proxiedResponse) {
|
|
1716
|
+
return await this.#proxiedResponse.code(headers);
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1712
1719
|
const requestedFragment = await this.#getFragmentRequest(headers);
|
|
1713
1720
|
const data = await this.#retreiveData();
|
|
1714
1721
|
|
|
@@ -1720,6 +1727,11 @@ export class FileResponse extends Response {
|
|
|
1720
1727
|
}
|
|
1721
1728
|
|
|
1722
1729
|
async getHeaders(headers = null) {
|
|
1730
|
+
if (this.#proxiedResponse) {
|
|
1731
|
+
const resultingHeaders = await this.#proxiedResponse.getHeaders(headers);
|
|
1732
|
+
return this.getMergedWithOtherHeaders(resultingHeaders);
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1723
1735
|
const requestedFragment = await this.#getFragmentRequest(headers);
|
|
1724
1736
|
const data = await this.#retreiveData();
|
|
1725
1737
|
|
|
@@ -1744,6 +1756,10 @@ export class FileResponse extends Response {
|
|
|
1744
1756
|
}
|
|
1745
1757
|
|
|
1746
1758
|
async getBody(headers = null) {
|
|
1759
|
+
if (this.#proxiedResponse) {
|
|
1760
|
+
return await this.#proxiedResponse.getBody(headers);
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1747
1763
|
const requestedFragment = await this.#getFragmentRequest(headers);
|
|
1748
1764
|
const data = await this.#retreiveData();
|
|
1749
1765
|
|
|
@@ -1754,23 +1770,29 @@ export class FileResponse extends Response {
|
|
|
1754
1770
|
return data.body;
|
|
1755
1771
|
}
|
|
1756
1772
|
|
|
1773
|
+
getProxy() {
|
|
1774
|
+
const proxy = new FileResponse(this.#filePath, this.#code, this.#contentType, this.getCookies());
|
|
1775
|
+
proxy.#proxiedResponse = this;
|
|
1776
|
+
return proxy;
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1757
1779
|
getFilePath() {
|
|
1758
1780
|
return this.#filePath;
|
|
1759
1781
|
}
|
|
1760
1782
|
|
|
1761
1783
|
setFilePath(filePath) {
|
|
1762
1784
|
this.#filePath = filePath;
|
|
1763
|
-
this.#dataPromise = null;
|
|
1785
|
+
this.#dataPromise = this.#proxiedResponse = null;
|
|
1764
1786
|
}
|
|
1765
1787
|
|
|
1766
1788
|
setNotFoundErrorCustomResponseHandler(handler) {
|
|
1767
1789
|
this.#makeNotFoundResponse = handler;
|
|
1768
|
-
this.#dataPromise = null;
|
|
1790
|
+
this.#dataPromise = this.#proxiedResponse = null;
|
|
1769
1791
|
}
|
|
1770
1792
|
|
|
1771
1793
|
setUrlPathForDirectory(urlPathForDirectory) {
|
|
1772
1794
|
this.#urlPathForDirectory = urlPathForDirectory;
|
|
1773
|
-
this.#dataPromise = null;
|
|
1795
|
+
this.#dataPromise = this.#proxiedResponse = null;
|
|
1774
1796
|
}
|
|
1775
1797
|
|
|
1776
1798
|
#isStreamableFileFormat(isDirectory = false) {
|
|
@@ -1979,7 +2001,7 @@ ${urlPath ? `<a href="/${parentUrlPath}">Up</a><hr>` : ''}
|
|
|
1979
2001
|
|
|
1980
2002
|
block() {
|
|
1981
2003
|
this.#blocked = true;
|
|
1982
|
-
this.#dataPromise = null;
|
|
2004
|
+
this.#dataPromise = this.#proxiedResponse = null;
|
|
1983
2005
|
}
|
|
1984
2006
|
|
|
1985
2007
|
isBlocked() {
|
|
@@ -2443,7 +2465,7 @@ async function handleRequest(req, routes, staticFileDirectories, handleNotFoundE
|
|
|
2443
2465
|
}
|
|
2444
2466
|
}
|
|
2445
2467
|
|
|
2446
|
-
return resp;
|
|
2468
|
+
return resp.getProxy();
|
|
2447
2469
|
};
|
|
2448
2470
|
|
|
2449
2471
|
routeHandler = wrapInMiddlewares(routeHandler, staticFileOrDirectory.preMiddlewares, staticFileOrDirectory.postMiddlewares);
|