Skip to content

Commit

Permalink
chore: address comments 📝
Browse files Browse the repository at this point in the history
  • Loading branch information
bricss committed Jun 12, 2024
1 parent ae83459 commit ab0b6d4
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 86 deletions.
7 changes: 0 additions & 7 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ Default value: '1024'.
Sets the minimum response payload size in bytes that is required for content encoding compression.
If the payload size is under the limit, no compression is performed.

##### <a name="server.options.compression.priority" /> `server.options.compression.priority`

Default value: `null`.

Sets the priority for content encoding compression algorithms in descending order,
e.g.: `['br', 'gzip', 'deflate']`.

#### <a name="server.options.debug" /> `server.options.debug`

Default value: `{ request: ['implementation'] }`.
Expand Down
6 changes: 0 additions & 6 deletions lib/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,4 @@ exports = module.exports = internals.Compression = class {
Hoek.assert(encoder !== undefined, `Unknown encoding ${encoding}`);
return encoder(request.route.settings.compression[encoding]);
}

setPriority(priority) {

this.encodings = [...new Set([...priority, ...this.encodings])];
this._updateCommons();
}
};
3 changes: 1 addition & 2 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ internals.server = Validate.object({
autoListen: Validate.boolean(),
cache: Validate.allow(null), // Validated elsewhere
compression: Validate.object({
minBytes: Validate.number().min(1).integer().default(1024),
priority: Validate.array().items(Validate.string().valid('gzip', 'deflate', 'br')).default(null)
minBytes: Validate.number().min(1).integer().default(1024)
})
.allow(false)
.default(),
Expand Down
4 changes: 0 additions & 4 deletions lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,6 @@ exports = module.exports = internals.Core = class {
this._debug();
this._initializeCache();

if (this.settings.compression.priority) {
this.compression.setPriority(this.settings.compression.priority);
}

if (this.settings.routes.validate.validator) {
this.validator = Validation.validator(this.settings.routes.validate.validator);
}
Expand Down
1 change: 0 additions & 1 deletion lib/types/server/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { SameSitePolicy } from './state';

export interface ServerOptionsCompression {
minBytes: number;
priority: string[];
}

/**
Expand Down
74 changes: 8 additions & 66 deletions test/transmit.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ describe('transmission', () => {
await server.stop();
});

it('returns a gzip response on a post request when accept-encoding: gzip;q=1, deflate;q=0.5 is requested', async () => {
it('returns a gzip response on a post request when accept-encoding: gzip;q=1, deflate;q=0.5, br;q=0.7 is requested', async () => {

const data = '{"test":"true"}';
const server = Hapi.server({ compression: { minBytes: 1 } });
Expand All @@ -898,12 +898,12 @@ describe('transmission', () => {

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', Buffer.from(data));
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'gzip;q=1, deflate;q=0.5' }, payload: data });
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'gzip;q=1, deflate;q=0.5, br;q=0.7' }, payload: data });
expect(payload.toString()).to.equal(zipped.toString());
await server.stop();
});

it('returns a gzip response on a get request when accept-encoding: gzip;q=1, deflate;q=0.5 is requested', async () => {
it('returns a gzip response on a get request when accept-encoding: gzip;q=1, deflate;q=0.5, br;q=0.7 is requested', async () => {

const data = '{"test":"true"}';
const server = Hapi.server({ compression: { minBytes: 1 } });
Expand All @@ -912,12 +912,12 @@ describe('transmission', () => {

const uri = 'http://localhost:' + server.info.port;
const zipped = await internals.compress('gzip', Buffer.from(data));
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'gzip;q=1, deflate;q=0.5' } });
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'gzip;q=1, deflate;q=0.5, br;q=0.7' } });
expect(payload.toString()).to.equal(zipped.toString());
await server.stop();
});

it('returns a deflate response on a post request when accept-encoding: deflate;q=1, gzip;q=0.5 is requested', async () => {
it('returns a deflate response on a post request when accept-encoding: deflate;q=1, gzip;q=0.5, br;q=0.7 is requested', async () => {

const data = '{"test":"true"}';
const server = Hapi.server({ compression: { minBytes: 1 } });
Expand All @@ -926,12 +926,12 @@ describe('transmission', () => {

const uri = 'http://localhost:' + server.info.port;
const deflated = await internals.compress('deflate', Buffer.from(data));
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'deflate;q=1, gzip;q=0.5' }, payload: data });
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'deflate;q=1, gzip;q=0.5, br;q=0.7' }, payload: data });
expect(payload.toString()).to.equal(deflated.toString());
await server.stop();
});

it('returns a deflate response on a get request when accept-encoding: deflate;q=1, gzip;q=0.5 is requested', async () => {
it('returns a deflate response on a get request when accept-encoding: deflate;q=1, gzip;q=0.5, br;q=0.7 is requested', async () => {

const data = '{"test":"true"}';
const server = Hapi.server({ compression: { minBytes: 1 } });
Expand All @@ -940,40 +940,11 @@ describe('transmission', () => {

const uri = 'http://localhost:' + server.info.port;
const deflated = await internals.compress('deflate', Buffer.from(data));
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'deflate;q=1, gzip;q=0.5' } });
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'deflate;q=1, gzip;q=0.5, br;q=0.7' } });
expect(payload.toString()).to.equal(deflated.toString());
await server.stop();
});


it('returns a br response on a post request when accept-encoding: gzip;q=1, deflate;q=0.5, br;q=1 is requested', async () => {

const data = '{"test":"true"}';
const server = Hapi.server({ compression: { minBytes: 1, priority: ['br'] } });
server.route({ method: 'POST', path: '/', handler: (request) => request.payload });
await server.start();

const uri = 'http://localhost:' + server.info.port;
const brotlied = await internals.compress('brotliCompress', Buffer.from(data));
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'gzip;q=1, deflate;q=0.5, br;q=1' }, payload: data });
expect(payload.toString()).to.equal(brotlied.toString());
await server.stop();
});

it('returns a br response on a get request when accept-encoding: gzip;q=1, deflate;q=0.5, br;q=1 is requested', async () => {

const data = '{"test":"true"}';
const server = Hapi.server({ compression: { minBytes: 1, priority: ['br'] } });
server.route({ method: 'GET', path: '/', handler: () => data });
await server.start();

const uri = 'http://localhost:' + server.info.port;
const brotlied = await internals.compress('brotliCompress', Buffer.from(data));
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'gzip;q=1, deflate;q=0.5, br;q=1' } });
expect(payload.toString()).to.equal(brotlied.toString());
await server.stop();
});

it('returns a gzip response on a post request when accept-encoding: deflate, gzip is requested', async () => {

const data = '{"test":"true"}';
Expand Down Expand Up @@ -1002,35 +973,6 @@ describe('transmission', () => {
await server.stop();
});


it('returns a br response on a post request when accept-encoding: gzip, deflate, br is requested', async () => {

const data = '{"test":"true"}';
const server = Hapi.server({ compression: { minBytes: 1, priority: ['br'] } });
server.route({ method: 'POST', path: '/', handler: (request) => request.payload });
await server.start();

const uri = 'http://localhost:' + server.info.port;
const brotlied = await internals.compress('brotliCompress', Buffer.from(data));
const { payload } = await Wreck.post(uri, { headers: { 'accept-encoding': 'gzip, deflate, br' }, payload: data });
expect(payload.toString()).to.equal(brotlied.toString());
await server.stop();
});

it('returns a br response on a get request when accept-encoding: gzip, deflate, br is requested', async () => {

const data = '{"test":"true"}';
const server = Hapi.server({ compression: { minBytes: 1, priority: ['br'] } });
server.route({ method: 'GET', path: '/', handler: () => data });
await server.start();

const uri = 'http://localhost:' + server.info.port;
const brotlied = await internals.compress('brotliCompress', Buffer.from(data));
const { payload } = await Wreck.get(uri, { headers: { 'accept-encoding': 'gzip, deflate, br' } });
expect(payload.toString()).to.equal(brotlied.toString());
await server.stop();
});

it('boom object reused does not affect encoding header.', async () => {

const error = Boom.badRequest();
Expand Down

0 comments on commit ab0b6d4

Please sign in to comment.