mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-11 05:42:22 +00:00
refactor(server): drop the null and String paths from gzipBody
This commit is contained in:
1 parent
09bf01630b
commit
caad795fa2
2 files changed
+1
-4
No files matched your search
@@ -54,8 +54,7 @@ export function acceptsGzip(request) {
|
|||||||
* @returns {Promise<Buffer|null>}
|
* @returns {Promise<Buffer|null>}
|
||||||
*/
|
*/
|
||||||
export async function gzipBody(body) {
|
export async function gzipBody(body) {
|
||||||
if (body == null) return null;
|
const raw = Buffer.isBuffer(body) ? body : Buffer.from(body);
|
||||||
const raw = Buffer.isBuffer(body) ? body : Buffer.from(String(body));
|
|
||||||
if (raw.byteLength < MIN_COMPRESSED_BYTES) return null;
|
if (raw.byteLength < MIN_COMPRESSED_BYTES) return null;
|
||||||
const compressed = await gzipAsync(raw);
|
const compressed = await gzipAsync(raw);
|
||||||
return compressed.byteLength < raw.byteLength ? compressed : null;
|
return compressed.byteLength < raw.byteLength ? compressed : null;
|
||||||
|
|||||||
@@ -81,8 +81,6 @@ test('accept-encoding is read the way clients actually write it', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('a body is only compressed when compression pays for itself', async () => {
|
test('a body is only compressed when compression pays for itself', async () => {
|
||||||
assert.equal(await gzipBody(null), null);
|
|
||||||
assert.equal(await gzipBody(undefined), null);
|
|
||||||
assert.equal(await gzipBody(''), null);
|
assert.equal(await gzipBody(''), null);
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await gzipBody('{"states":[]}'),
|
await gzipBody('{"states":[]}'),
|
||||||
|
|||||||
Reference in new issue
Block a user