Skip to content

Commit 7b9f100

Browse files
committed
feat: betterment 💈
1 parent 66c4080 commit 7b9f100

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

‎lib/compression.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ exports = module.exports = internals.Compression = class {
134134

135135
enableZstdCompression(compressionOptions) {
136136

137+
Hoek.assert(!!Zlib.constants.ZSTD_CLEVEL_DEFAULT, 'Zstd is not supported by the engine');
137138
this.decoders.zstd = (options) => Zlib.createZstdDecompress({ ...options, ...compressionOptions });
138139
this.encoders.zstd = (options) => Zlib.createZstdCompress({ ...options, ...compressionOptions });
139140
this.setPriority(['zstd']);

‎test/common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const ChildProcess = require('child_process');
44
const Http = require('http');
55
const Net = require('net');
6+
const Zlib = require('zlib');
67

78
const internals = {};
89

@@ -30,3 +31,5 @@ internals.hasIPv6 = () => {
3031
exports.hasLsof = internals.hasLsof();
3132

3233
exports.hasIPv6 = internals.hasIPv6();
34+
35+
exports.hasZstd = !!Zlib.constants.ZSTD_CLEVEL_DEFAULT;

‎test/payload.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ const Code = require('@hapi/code');
1212
const Hapi = require('..');
1313
const Hoek = require('@hapi/hoek');
1414
const Lab = require('@hapi/lab');
15-
const Somever = require('@hapi/somever');
1615
const Wreck = require('@hapi/wreck');
1716

17+
const Common = require('./common');
18+
1819
const internals = {};
1920

2021

@@ -550,7 +551,7 @@ describe('Payload', () => {
550551
expect(res.result).to.equal(message);
551552
});
552553

553-
it('handles zstd payload', { skip: Somever.match(process.version, '<22.15.0') }, async () => {
554+
it('handles zstd payload', { skip: !Common.hasZstd }, async () => {
554555

555556
const message = { 'msg': 'This message is going to be zstded.' };
556557
const server = Hapi.server({ compression: { enableZstd: true } });

‎test/transmit.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const Hoek = require('@hapi/hoek');
1616
const Bounce = require('@hapi/bounce');
1717
const Inert = require('@hapi/inert');
1818
const Lab = require('@hapi/lab');
19-
const Somever = require('@hapi/somever');
2019
const Teamwork = require('@hapi/teamwork');
2120
const Wreck = require('@hapi/wreck');
2221

@@ -678,7 +677,7 @@ describe('transmission', () => {
678677
expect(res3.headers['last-modified']).to.equal(res2.headers['last-modified']);
679678
});
680679

681-
it('returns a zstded file in the response when the request accepts zstd', { skip: Somever.match(process.version, '<22.15.0') }, async () => {
680+
it('returns a zstded file in the response when the request accepts zstd', { skip: !Common.hasZstd }, async () => {
682681

683682
const server = Hapi.server({ compression: { enableZstd: true, minBytes: 1 }, routes: { files: { relativeTo: __dirname } } });
684683
await server.register(Inert);
@@ -809,7 +808,7 @@ describe('transmission', () => {
809808
expect(res.headers['content-length']).to.not.exist();
810809
});
811810

812-
it('returns a zstd response on a post request when accept-encoding: zstd is requested', { skip: Somever.match(process.version, '<22.15.0') }, async () => {
811+
it('returns a zstd response on a post request when accept-encoding: zstd is requested', { skip: !Common.hasZstd }, async () => {
813812

814813
const data = '{"test":"true"}';
815814

@@ -824,7 +823,7 @@ describe('transmission', () => {
824823
await server.stop();
825824
});
826825

827-
it('returns a zstd response on a get request when accept-encoding: zstd is requested', { skip: Somever.match(process.version, '<22.15.0') }, async () => {
826+
it('returns a zstd response on a get request when accept-encoding: zstd is requested', { skip: !Common.hasZstd }, async () => {
828827

829828
const data = '{"test":"true"}';
830829

@@ -1039,7 +1038,7 @@ describe('transmission', () => {
10391038
await server.stop();
10401039
});
10411040

1042-
it('returns a zstd response on a post request when accept-encoding: gzip;q=1, deflate;q=0.5, br;q=0.7; zstd;q=1 is requested', { skip: Somever.match(process.version, '<22.15.0') }, async () => {
1041+
it('returns a zstd response on a post request when accept-encoding: gzip;q=1, deflate;q=0.5, br;q=0.7; zstd;q=1 is requested', { skip: !Common.hasZstd }, async () => {
10431042

10441043
const data = '{"test":"true"}';
10451044
const server = Hapi.server({ compression: { enableZstd: true, minBytes: 1 } });
@@ -1053,7 +1052,7 @@ describe('transmission', () => {
10531052
await server.stop();
10541053
});
10551054

1056-
it('returns a zstd response on a get request when accept-encoding: gzip;q=1, deflate;q=0.5, br;q=0.7, zstd;q=1 is requested', { skip: Somever.match(process.version, '<22.15.0') }, async () => {
1055+
it('returns a zstd response on a get request when accept-encoding: gzip;q=1, deflate;q=0.5, br;q=0.7, zstd;q=1 is requested', { skip: !Common.hasZstd }, async () => {
10571056

10581057
const data = '{"test":"true"}';
10591058
const server = Hapi.server({ compression: { enableZstd: true, minBytes: 1 } });
@@ -1123,7 +1122,7 @@ describe('transmission', () => {
11231122
await server.stop();
11241123
});
11251124

1126-
it('returns a zstd response on a post request when accept-encoding: gzip, deflate, br, zstd is requested', { skip: Somever.match(process.version, '<22.15.0') }, async () => {
1125+
it('returns a zstd response on a post request when accept-encoding: gzip, deflate, br, zstd is requested', { skip: !Common.hasZstd }, async () => {
11271126

11281127
const data = '{"test":"true"}';
11291128
const server = Hapi.server({ compression: { enableZstd: true, minBytes: 1 } });
@@ -1137,7 +1136,7 @@ describe('transmission', () => {
11371136
await server.stop();
11381137
});
11391138

1140-
it('returns a zstd response on a get request when accept-encoding: gzip, deflate, br, zstd is requested', { skip: Somever.match(process.version, '<22.15.0') }, async () => {
1139+
it('returns a zstd response on a get request when accept-encoding: gzip, deflate, br, zstd is requested', { skip: !Common.hasZstd }, async () => {
11411140

11421141
const data = '{"test":"true"}';
11431142
const server = Hapi.server({ compression: { enableZstd: true, minBytes: 1 } });

0 commit comments

Comments
 (0)