minimalistic-server 0.0.33 → 0.0.34
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 +24 -6
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1616,7 +1616,7 @@ export class FileResponse extends Response {
|
|
|
1616
1616
|
if (requestedFragment) {
|
|
1617
1617
|
return {
|
|
1618
1618
|
...data.headers,
|
|
1619
|
-
'Accept-Ranges':'bytes',
|
|
1619
|
+
'Accept-Ranges': 'bytes',
|
|
1620
1620
|
'Content-Range': `bytes ${requestedFragment.offset}-${requestedFragment.offset + requestedFragment.size - 1}/${data.size}`,
|
|
1621
1621
|
'Content-Length': `${requestedFragment.size}`,
|
|
1622
1622
|
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
|
@@ -1862,6 +1862,7 @@ ${urlPath ? `<a href="/${parentUrlPath}">Up</a><hr>` : ''}
|
|
|
1862
1862
|
export class JsonResponse extends Response {
|
|
1863
1863
|
#object;
|
|
1864
1864
|
#code;
|
|
1865
|
+
#cachedBuffer = null;
|
|
1865
1866
|
|
|
1866
1867
|
constructor(object = {}, code = 200, cookies = null) {
|
|
1867
1868
|
super();
|
|
@@ -1875,11 +1876,18 @@ export class JsonResponse extends Response {
|
|
|
1875
1876
|
}
|
|
1876
1877
|
|
|
1877
1878
|
getHeaders() {
|
|
1878
|
-
return this.getMergedWithOtherHeaders({
|
|
1879
|
+
return this.getMergedWithOtherHeaders({
|
|
1880
|
+
'Content-Type': 'application/json',
|
|
1881
|
+
'Content-Length': `${this.getBody().length}`,
|
|
1882
|
+
});
|
|
1879
1883
|
}
|
|
1880
1884
|
|
|
1881
1885
|
getBody() {
|
|
1882
|
-
|
|
1886
|
+
if (!this.#cachedBuffer) {
|
|
1887
|
+
this.#cachedBuffer = Buffer.from(JSON.stringify(this.#object), 'utf8');
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
return this.#cachedBuffer;
|
|
1883
1891
|
}
|
|
1884
1892
|
|
|
1885
1893
|
getObject() {
|
|
@@ -1887,6 +1895,7 @@ export class JsonResponse extends Response {
|
|
|
1887
1895
|
}
|
|
1888
1896
|
|
|
1889
1897
|
setObject(object) {
|
|
1898
|
+
this.#cachedBuffer = null;
|
|
1890
1899
|
this.#object = object;
|
|
1891
1900
|
}
|
|
1892
1901
|
}
|
|
@@ -1894,6 +1903,7 @@ export class JsonResponse extends Response {
|
|
|
1894
1903
|
export class HTMLResponse extends Response {
|
|
1895
1904
|
#string;
|
|
1896
1905
|
#code;
|
|
1906
|
+
#cachedBuffer = null;
|
|
1897
1907
|
|
|
1898
1908
|
constructor(string = '', code = 200, cookies = null) {
|
|
1899
1909
|
super();
|
|
@@ -1907,11 +1917,18 @@ export class HTMLResponse extends Response {
|
|
|
1907
1917
|
}
|
|
1908
1918
|
|
|
1909
1919
|
getHeaders() {
|
|
1910
|
-
return this.getMergedWithOtherHeaders({
|
|
1920
|
+
return this.getMergedWithOtherHeaders({
|
|
1921
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
1922
|
+
'Content-Length': `${this.getBody().length}`,
|
|
1923
|
+
});
|
|
1911
1924
|
}
|
|
1912
1925
|
|
|
1913
1926
|
getBody() {
|
|
1914
|
-
|
|
1927
|
+
if (!this.#cachedBuffer) {
|
|
1928
|
+
this.#cachedBuffer = Buffer.from(this.#string, 'utf8');
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
return this.#cachedBuffer;
|
|
1915
1932
|
}
|
|
1916
1933
|
|
|
1917
1934
|
getString() {
|
|
@@ -1919,6 +1936,7 @@ export class HTMLResponse extends Response {
|
|
|
1919
1936
|
}
|
|
1920
1937
|
|
|
1921
1938
|
setString(string) {
|
|
1939
|
+
this.#cachedBuffer = null;
|
|
1922
1940
|
this.#string = string;
|
|
1923
1941
|
}
|
|
1924
1942
|
}
|
|
@@ -2319,7 +2337,7 @@ async function handleRequest(req, routes, staticFileDirectories, handleNotFoundE
|
|
|
2319
2337
|
}
|
|
2320
2338
|
|
|
2321
2339
|
try {
|
|
2322
|
-
return await Promise.all([response.getCode(requestHeaders), response.getHeaders(requestHeaders), responseBodyIsIncluded ? response.getBody(requestHeaders): '', false]);
|
|
2340
|
+
return await Promise.all([response.getCode(requestHeaders), response.getHeaders(requestHeaders), responseBodyIsIncluded ? response.getBody(requestHeaders) : '', false]);
|
|
2323
2341
|
} catch (error) {
|
|
2324
2342
|
safePrint(error, true);
|
|
2325
2343
|
|