From f160f446fb4262e11dbf088f16eecfcbec6b52f5 Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Wed, 10 Jan 2018 18:48:49 +0100 Subject: [PATCH 01/18] Add failing tests for http2 --- test/compression.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/compression.js b/test/compression.js index 6975ea0b..77491f09 100644 --- a/test/compression.js +++ b/test/compression.js @@ -4,6 +4,7 @@ var Buffer = require('safe-buffer').Buffer var bytes = require('bytes') var crypto = require('crypto') var http = require('http') +var http2 = require('http2') var request = require('supertest') var zlib = require('zlib') @@ -305,6 +306,22 @@ describe('compression()', function () { .expect(200, done) }) + it('should work with http2 server', function (done) { + createHttp2Server({ threshold: 0 }, function (req, res) { + res.setHeader('Content-Type', 'text/plain') + res.end('hello, world') + }) + + var request = createHttp2Client().request({ + 'Accept-Encoding': 'gzip' + }) + request.on('response', (headers) => { + assert.equal(headers['content-encoding'], 'gzip') + done() + }) + request.end() + }) + describe('threshold', function () { it('should not compress responses below the threshold size', function (done) { var server = createServer({ threshold: '1kb' }, function (req, res) { @@ -674,6 +691,28 @@ function createServer (opts, fn) { }) } +function createHttp2Server (opts, fn) { + var _compression = compression(opts) + var server = http2.createServer(function (req, res) { + _compression(req, res, function (err) { + if (err) { + res.statusCode = err.status || 500 + res.end(err.message) + return + } + + fn(req, res) + }) + }) + server.listen(8443, '127.0.0.1') + return server +} + +function createHttp2Client () { + var client = http2.connect('http://127.0.0.1:8443') + return client +} + function shouldHaveBodyLength (length) { return function (res) { assert.strictEqual(res.text.length, length, 'should have body length of ' + length) From 2c8ed82b979c11d42b39ea9bbd53305c7491ec61 Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Wed, 10 Jan 2018 18:50:03 +0100 Subject: [PATCH 02/18] Add support for http2 The change just removes the usage of undocumented http API and instead uses the proper writeHead method --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1d089427..558c449b 100644 --- a/index.js +++ b/index.js @@ -81,7 +81,7 @@ function compression (options) { } if (!this._header) { - this._implicitHeader() + this.writeHead(this.statusCode) } return stream @@ -100,7 +100,7 @@ function compression (options) { length = chunkLength(chunk, encoding) } - this._implicitHeader() + this.writeHead(this.statusCode) } if (!stream) { From 8eae0062b97b57aeb424de49d0f1f5b056d7604b Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Wed, 10 Jan 2018 19:09:56 +0100 Subject: [PATCH 03/18] Remove arrow function in tests --- test/compression.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/compression.js b/test/compression.js index 77491f09..67161c04 100644 --- a/test/compression.js +++ b/test/compression.js @@ -312,11 +312,13 @@ describe('compression()', function () { res.end('hello, world') }) - var request = createHttp2Client().request({ + var client = createHttp2Client() + var request = client.request({ 'Accept-Encoding': 'gzip' }) - request.on('response', (headers) => { + request.on('response', function (headers) { assert.equal(headers['content-encoding'], 'gzip') + client.destroy() done() }) request.end() From 8c68bc1b5b1f6e2cf949c4f957886e9fea4ec8b9 Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Wed, 10 Jan 2018 19:58:51 +0100 Subject: [PATCH 04/18] Conditionally run http2 tests if http2 is available --- test/compression.js | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/test/compression.js b/test/compression.js index 67161c04..26d8f178 100644 --- a/test/compression.js +++ b/test/compression.js @@ -4,10 +4,17 @@ var Buffer = require('safe-buffer').Buffer var bytes = require('bytes') var crypto = require('crypto') var http = require('http') -var http2 = require('http2') var request = require('supertest') var zlib = require('zlib') +try { + var http2 = require('http2') +} catch (err) { + if (err) { + console.log('http2 tests disabled.') + } +} + var compression = require('..') describe('compression()', function () { @@ -306,23 +313,25 @@ describe('compression()', function () { .expect(200, done) }) - it('should work with http2 server', function (done) { - createHttp2Server({ threshold: 0 }, function (req, res) { - res.setHeader('Content-Type', 'text/plain') - res.end('hello, world') - }) + if (http2) { + it('should work with http2 server', function (done) { + createHttp2Server({ threshold: 0 }, function (req, res) { + res.setHeader('Content-Type', 'text/plain') + res.end('hello, world') + }) - var client = createHttp2Client() - var request = client.request({ - 'Accept-Encoding': 'gzip' - }) - request.on('response', function (headers) { - assert.equal(headers['content-encoding'], 'gzip') - client.destroy() - done() + var client = createHttp2Client() + var request = client.request({ + 'Accept-Encoding': 'gzip' + }) + request.on('response', function (headers) { + assert.equal(headers['content-encoding'], 'gzip') + client.destroy() + done() + }) + request.end() }) - request.end() - }) + } describe('threshold', function () { it('should not compress responses below the threshold size', function (done) { From 512291682e82e79a833568f17c3b844027884724 Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Mon, 15 Jan 2018 18:10:22 +0100 Subject: [PATCH 05/18] Fix port in tests to be assigned automatically --- test/compression.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/test/compression.js b/test/compression.js index 26d8f178..189c3da3 100644 --- a/test/compression.js +++ b/test/compression.js @@ -315,21 +315,22 @@ describe('compression()', function () { if (http2) { it('should work with http2 server', function (done) { - createHttp2Server({ threshold: 0 }, function (req, res) { + var server = createHttp2Server({ threshold: 0 }, function (req, res) { res.setHeader('Content-Type', 'text/plain') res.end('hello, world') }) - - var client = createHttp2Client() - var request = client.request({ - 'Accept-Encoding': 'gzip' - }) - request.on('response', function (headers) { - assert.equal(headers['content-encoding'], 'gzip') - client.destroy() - done() + server.on('listening', function () { + var client = createHttp2Client(server.address().port) + var request = client.request({ + 'Accept-Encoding': 'gzip' + }) + request.on('response', function (headers) { + assert.equal(headers['content-encoding'], 'gzip') + client.destroy() + done() + }) + request.end() }) - request.end() }) } @@ -715,12 +716,12 @@ function createHttp2Server (opts, fn) { fn(req, res) }) }) - server.listen(8443, '127.0.0.1') + server.listen(0, '127.0.0.1') return server } -function createHttp2Client () { - var client = http2.connect('http://127.0.0.1:8443') +function createHttp2Client (port) { + var client = http2.connect('http://127.0.0.1:' + port) return client } From 7b7f5065117007a576f48e0929dfe0ec8cf7dbb4 Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Mon, 15 Jan 2018 18:31:45 +0100 Subject: [PATCH 06/18] Change http2 test usage to describe.skip if no http2 available --- test/compression.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/compression.js b/test/compression.js index 189c3da3..1a9c8ce8 100644 --- a/test/compression.js +++ b/test/compression.js @@ -7,8 +7,10 @@ var http = require('http') var request = require('supertest') var zlib = require('zlib') +var describeHttp2 = describe.skip try { var http2 = require('http2') + describeHttp2 = describe } catch (err) { if (err) { console.log('http2 tests disabled.') @@ -313,7 +315,7 @@ describe('compression()', function () { .expect(200, done) }) - if (http2) { + describeHttp2('http2', function () { it('should work with http2 server', function (done) { var server = createHttp2Server({ threshold: 0 }, function (req, res) { res.setHeader('Content-Type', 'text/plain') @@ -332,7 +334,7 @@ describe('compression()', function () { request.end() }) }) - } + }) describe('threshold', function () { it('should not compress responses below the threshold size', function (done) { From 8ba81000a0a3bdc17eace8bb23e70dd317f10008 Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Mon, 15 Jan 2018 20:17:21 +0100 Subject: [PATCH 07/18] Fix closing the http2 connections to prevent possible exceptions --- test/compression.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/compression.js b/test/compression.js index 1a9c8ce8..34f3a47b 100644 --- a/test/compression.js +++ b/test/compression.js @@ -328,8 +328,11 @@ describe('compression()', function () { }) request.on('response', function (headers) { assert.equal(headers['content-encoding'], 'gzip') - client.destroy() - done() + client.close(function () { + server.close(function () { + done() + }) + }) }) request.end() }) From 8ea806d39b8a55cb585f2fe77a704ef359b164a5 Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Mon, 15 Jan 2018 20:39:33 +0100 Subject: [PATCH 08/18] Fix closing the request first, then the client, then the server --- test/compression.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/compression.js b/test/compression.js index 34f3a47b..7db204ec 100644 --- a/test/compression.js +++ b/test/compression.js @@ -328,9 +328,11 @@ describe('compression()', function () { }) request.on('response', function (headers) { assert.equal(headers['content-encoding'], 'gzip') - client.close(function () { - server.close(function () { - done() + request.close(http2.constants.NGHTTP2_NO_ERROR, function () { + client.close(function () { + server.close(function () { + done() + }) }) }) }) From a56205626d4c824b5034864f33cbb810151c8608 Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Mon, 15 Jan 2018 21:03:55 +0100 Subject: [PATCH 09/18] Fix closing for v8.x and v9.x --- test/compression.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/test/compression.js b/test/compression.js index 7db204ec..8b6b66e7 100644 --- a/test/compression.js +++ b/test/compression.js @@ -328,13 +328,7 @@ describe('compression()', function () { }) request.on('response', function (headers) { assert.equal(headers['content-encoding'], 'gzip') - request.close(http2.constants.NGHTTP2_NO_ERROR, function () { - client.close(function () { - server.close(function () { - done() - }) - }) - }) + closeHttp2(request, client, server, done) }) request.end() }) @@ -732,6 +726,28 @@ function createHttp2Client (port) { return client } +function closeHttp2 (request, client, server, callback) { + if (typeof client.shutdown === 'function') { + // this is the node v8.x way of closing the connections + request.destroy(http2.constants.NGHTTP2_NO_ERROR, function () { + client.shutdown({}, function () { + server.close(function () { + callback() + }) + }) + }) + } else { + // this is the node v9.x onwards (hopefully) way of closing the connections + request.close(http2.constants.NGHTTP2_NO_ERROR, function () { + client.close(function () { + server.close(function () { + callback() + }) + }) + }) + } +} + function shouldHaveBodyLength (length) { return function (res) { assert.strictEqual(res.text.length, length, 'should have body length of ' + length) From feddec11c722e7ceb697e8d185489b50b8189c5c Mon Sep 17 00:00:00 2001 From: Moritz Peters Date: Wed, 26 Sep 2018 16:24:38 +0200 Subject: [PATCH 10/18] fix tests not draining data for http2 requests, resulting in timeouts in node v10.4 onwards --- test/compression.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/test/compression.js b/test/compression.js index 8b6b66e7..effaccbf 100644 --- a/test/compression.js +++ b/test/compression.js @@ -328,6 +328,14 @@ describe('compression()', function () { }) request.on('response', function (headers) { assert.equal(headers['content-encoding'], 'gzip') + }) + request.on('error', function (error) { + console.error('An error event occurred on a http2 client request.', error) + }) + request.on('data', function (chunk) { + // no-op without which the request will stay open and cause a test timeout + }) + request.on('end', function () { closeHttp2(request, client, server, done) }) request.end() @@ -707,6 +715,12 @@ function createServer (opts, fn) { function createHttp2Server (opts, fn) { var _compression = compression(opts) var server = http2.createServer(function (req, res) { + req.on('error', function (error) { + console.error('An error event occurred on a http2 request.', error) + }) + res.on('error', function (error) { + console.error('An error event occurred on a http2 response.', error) + }) _compression(req, res, function (err) { if (err) { res.statusCode = err.status || 500 @@ -717,12 +731,21 @@ function createHttp2Server (opts, fn) { fn(req, res) }) }) + server.on('error', function (error) { + console.error('An error event occurred on the http2 server.', error) + }) + server.on('sessionError', function (error) { + console.error('A sessionError event occurred on the http2 server.', error) + }) server.listen(0, '127.0.0.1') return server } function createHttp2Client (port) { var client = http2.connect('http://127.0.0.1:' + port) + client.on('error', function (error) { + console.error('An error event occurred in the http2 client stream.', error) + }) return client } @@ -737,9 +760,14 @@ function closeHttp2 (request, client, server, callback) { }) }) } else { - // this is the node v9.x onwards (hopefully) way of closing the connections + // this is the node v9.x onwards way of closing the connections request.close(http2.constants.NGHTTP2_NO_ERROR, function () { client.close(function () { + // force existing connections to time out after 1ms. + // this is done to force the server to close in some cases where it wouldn't do it otherwise. + server.setTimeout(1, function () { + console.warn('An http2 connection timed out instead of being closed properly.') + }) server.close(function () { callback() }) From 5124eb066f10e7a107cfeba96c2e26865a3e1ef4 Mon Sep 17 00:00:00 2001 From: Ryan Wilson Date: Mon, 2 Mar 2020 11:03:12 -0800 Subject: [PATCH 11/18] =?UTF-8?q?fix:=20=F0=9F=90=9B=20assert.equal=20erro?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/compression.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/compression.js b/test/compression.js index effaccbf..379ef9e2 100644 --- a/test/compression.js +++ b/test/compression.js @@ -327,7 +327,7 @@ describe('compression()', function () { 'Accept-Encoding': 'gzip' }) request.on('response', function (headers) { - assert.equal(headers['content-encoding'], 'gzip') + assert.strictEqual(headers['content-encoding'], 'gzip') }) request.on('error', function (error) { console.error('An error event occurred on a http2 client request.', error) From 094316e248dfc65f5c9efb963a0c72b076eacdf0 Mon Sep 17 00:00:00 2001 From: Ryan Wilson Date: Mon, 2 Mar 2020 11:29:04 -0800 Subject: [PATCH 12/18] =?UTF-8?q?fix:=20=F0=9F=90=9B=20remove=20console.lo?= =?UTF-8?q?g's=20and=20timeout,=20let=20build=20fail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/compression.js | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/test/compression.js b/test/compression.js index 379ef9e2..877ddad7 100644 --- a/test/compression.js +++ b/test/compression.js @@ -329,9 +329,6 @@ describe('compression()', function () { request.on('response', function (headers) { assert.strictEqual(headers['content-encoding'], 'gzip') }) - request.on('error', function (error) { - console.error('An error event occurred on a http2 client request.', error) - }) request.on('data', function (chunk) { // no-op without which the request will stay open and cause a test timeout }) @@ -715,12 +712,6 @@ function createServer (opts, fn) { function createHttp2Server (opts, fn) { var _compression = compression(opts) var server = http2.createServer(function (req, res) { - req.on('error', function (error) { - console.error('An error event occurred on a http2 request.', error) - }) - res.on('error', function (error) { - console.error('An error event occurred on a http2 response.', error) - }) _compression(req, res, function (err) { if (err) { res.statusCode = err.status || 500 @@ -731,22 +722,12 @@ function createHttp2Server (opts, fn) { fn(req, res) }) }) - server.on('error', function (error) { - console.error('An error event occurred on the http2 server.', error) - }) - server.on('sessionError', function (error) { - console.error('A sessionError event occurred on the http2 server.', error) - }) server.listen(0, '127.0.0.1') return server } function createHttp2Client (port) { - var client = http2.connect('http://127.0.0.1:' + port) - client.on('error', function (error) { - console.error('An error event occurred in the http2 client stream.', error) - }) - return client + return http2.connect('http://127.0.0.1:' + port) } function closeHttp2 (request, client, server, callback) { @@ -765,9 +746,6 @@ function closeHttp2 (request, client, server, callback) { client.close(function () { // force existing connections to time out after 1ms. // this is done to force the server to close in some cases where it wouldn't do it otherwise. - server.setTimeout(1, function () { - console.warn('An http2 connection timed out instead of being closed properly.') - }) server.close(function () { callback() }) From d85e6e8bd73137844f9f2112622d91a4b52b8bc7 Mon Sep 17 00:00:00 2001 From: Ryan Wilson Date: Sat, 30 Jul 2022 12:20:39 -0700 Subject: [PATCH 13/18] Apply suggestions from code review Co-authored-by: Lam Wei Li --- test/compression.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/compression.js b/test/compression.js index 877ddad7..554477ea 100644 --- a/test/compression.js +++ b/test/compression.js @@ -329,11 +329,15 @@ describe('compression()', function () { request.on('response', function (headers) { assert.strictEqual(headers['content-encoding'], 'gzip') }) + var chunks = []; request.on('data', function (chunk) { - // no-op without which the request will stay open and cause a test timeout + chunks.push(chunk); }) request.on('end', function () { - closeHttp2(request, client, server, done) + zlib.gunzip(Buffer.concat(chunks), function(err, data) { + assert.strictEqual(data.toString(), 'hello, world') + closeHttp2(client, server, done) + }) }) request.end() }) @@ -730,19 +734,16 @@ function createHttp2Client (port) { return http2.connect('http://127.0.0.1:' + port) } -function closeHttp2 (request, client, server, callback) { +function closeHttp2 (client, server, callback) { if (typeof client.shutdown === 'function') { // this is the node v8.x way of closing the connections - request.destroy(http2.constants.NGHTTP2_NO_ERROR, function () { client.shutdown({}, function () { server.close(function () { callback() }) }) - }) } else { // this is the node v9.x onwards way of closing the connections - request.close(http2.constants.NGHTTP2_NO_ERROR, function () { client.close(function () { // force existing connections to time out after 1ms. // this is done to force the server to close in some cases where it wouldn't do it otherwise. @@ -750,7 +751,6 @@ function closeHttp2 (request, client, server, callback) { callback() }) }) - }) } } From d3016e20cf4d8adb68c579a45086bbd4b40a3a97 Mon Sep 17 00:00:00 2001 From: Ryan Wilson Date: Sat, 30 Jul 2022 12:37:09 -0700 Subject: [PATCH 14/18] fixed lint --- test/compression.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/compression.js b/test/compression.js index 554477ea..367656fc 100644 --- a/test/compression.js +++ b/test/compression.js @@ -329,12 +329,12 @@ describe('compression()', function () { request.on('response', function (headers) { assert.strictEqual(headers['content-encoding'], 'gzip') }) - var chunks = []; + var chunks = [] request.on('data', function (chunk) { - chunks.push(chunk); + chunks.push(chunk) }) request.on('end', function () { - zlib.gunzip(Buffer.concat(chunks), function(err, data) { + zlib.gunzip(Buffer.concat(chunks), function (err, data) { assert.strictEqual(data.toString(), 'hello, world') closeHttp2(client, server, done) }) @@ -737,20 +737,20 @@ function createHttp2Client (port) { function closeHttp2 (client, server, callback) { if (typeof client.shutdown === 'function') { // this is the node v8.x way of closing the connections - client.shutdown({}, function () { - server.close(function () { - callback() - }) + client.shutdown({}, function () { + server.close(function () { + callback() }) + }) } else { // this is the node v9.x onwards way of closing the connections - client.close(function () { - // force existing connections to time out after 1ms. - // this is done to force the server to close in some cases where it wouldn't do it otherwise. - server.close(function () { - callback() - }) + client.close(function () { + // force existing connections to time out after 1ms. + // this is done to force the server to close in some cases where it wouldn't do it otherwise. + server.close(function () { + callback() }) + }) } } From ebae4e9ff9d6c0949ace051d9569cde1566be6c2 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Tue, 2 Aug 2022 15:34:19 +0800 Subject: [PATCH 15/18] fix: an issue where test hangs when assertion fails in http2 as http2server is not closed --- test/compression.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/compression.js b/test/compression.js index 367656fc..81ac9937 100644 --- a/test/compression.js +++ b/test/compression.js @@ -334,9 +334,12 @@ describe('compression()', function () { chunks.push(chunk) }) request.on('end', function () { - zlib.gunzip(Buffer.concat(chunks), function (err, data) { - assert.strictEqual(data.toString(), 'hello, world') - closeHttp2(client, server, done) + closeHttp2(client, server, function () { + zlib.gunzip(Buffer.concat(chunks), function (err, data) { + assert.ok(!err) + assert.strictEqual(data.toString(), 'hello, world') + done() + }) }) }) request.end() From 78cac206cf4ac72b7a2785d97f239b8b8ccd2d9e Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Tue, 2 Aug 2022 15:01:37 +0800 Subject: [PATCH 16/18] refactor: use http2.constants instead of hard-coded strings in http2 test --- test/compression.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/compression.js b/test/compression.js index 81ac9937..e88befbc 100644 --- a/test/compression.js +++ b/test/compression.js @@ -318,16 +318,18 @@ describe('compression()', function () { describeHttp2('http2', function () { it('should work with http2 server', function (done) { var server = createHttp2Server({ threshold: 0 }, function (req, res) { - res.setHeader('Content-Type', 'text/plain') + res.setHeader(http2.constants.HTTP2_HEADER_CONTENT_TYPE, 'text/plain') res.end('hello, world') }) server.on('listening', function () { var client = createHttp2Client(server.address().port) var request = client.request({ - 'Accept-Encoding': 'gzip' + [http2.constants.HTTP2_HEADER_ACCEPT_ENCODING]: 'gzip' }) request.on('response', function (headers) { - assert.strictEqual(headers['content-encoding'], 'gzip') + assert.strictEqual(headers[http2.constants.HTTP2_HEADER_STATUS], 200) + assert.strictEqual(headers[http2.constants.HTTP2_HEADER_CONTENT_TYPE], 'text/plain') + assert.strictEqual(headers[http2.constants.HTTP2_HEADER_CONTENT_ENCODING], 'gzip') }) var chunks = [] request.on('data', function (chunk) { From 4c1d27b91b6b6d4f8bd6165ed73e1708cea5d8fa Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Tue, 2 Aug 2022 16:33:24 +0800 Subject: [PATCH 17/18] Node.js 0.8 compatible --- test/compression.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/compression.js b/test/compression.js index e88befbc..b6166eb1 100644 --- a/test/compression.js +++ b/test/compression.js @@ -323,9 +323,10 @@ describe('compression()', function () { }) server.on('listening', function () { var client = createHttp2Client(server.address().port) - var request = client.request({ - [http2.constants.HTTP2_HEADER_ACCEPT_ENCODING]: 'gzip' - }) + // using ES5 as Node.js <=4.0.0 does not have Computed Property Names + var reqHeaders = {} + reqHeaders[http2.constants.HTTP2_HEADER_ACCEPT_ENCODING] = 'gzip' + var request = client.request(reqHeaders) request.on('response', function (headers) { assert.strictEqual(headers[http2.constants.HTTP2_HEADER_STATUS], 200) assert.strictEqual(headers[http2.constants.HTTP2_HEADER_CONTENT_TYPE], 'text/plain') From c126f78844b155e387e66aaf46615aae57335413 Mon Sep 17 00:00:00 2001 From: Ryan Wilson Date: Sat, 9 Nov 2024 10:03:23 -0800 Subject: [PATCH 18/18] fix lint issue --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 2cc5a6b0..01b15bd5 100644 --- a/index.js +++ b/index.js @@ -81,7 +81,7 @@ function compression (options) { } if (!headersSent(res)) { - this.writeHead(this.statusCode) + this.writeHead(this.statusCode) } return stream