Skip to content

Commit

Permalink
fix: remove brotli support check (#542)
Browse files Browse the repository at this point in the history
with the minimum supported node version set to v18 we can remove the brotli support check as it was added in v11.7.0 and v10.16.0
  • Loading branch information
Phillip9587 authored Oct 17, 2024
1 parent f316637 commit cd985a8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 63 deletions.
14 changes: 3 additions & 11 deletions lib/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ var zlib = require('zlib')

module.exports = read

/**
* @const
* whether current node version has brotli support
*/
var hasBrotliSupport = 'createBrotliDecompress' in zlib

/**
* Read a request into a buffer and parse.
*
Expand Down Expand Up @@ -181,11 +175,9 @@ function contentstream (req, debug, inflate) {
stream.length = length
break
case 'br':
if (hasBrotliSupport) {
stream = zlib.createBrotliDecompress()
debug('brotli decompress body')
req.pipe(stream)
}
stream = zlib.createBrotliDecompress()
debug('brotli decompress body')
req.pipe(stream)
break
}

Expand Down
14 changes: 1 addition & 13 deletions test/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
? describe
: describe.skip

var hasBrotliSupport = 'createBrotliDecompress' in require('zlib')
var brotlit = hasBrotliSupport ? it : it.skip
var nobrotlit = !hasBrotliSupport ? it : it.skip

describe('bodyParser.json()', function () {
it('should parse JSON', function (done) {
request(createServer())
Expand Down Expand Up @@ -687,22 +683,14 @@ describe('bodyParser.json()', function () {
test.expect(200, '{"name":"论"}', done)
})

brotlit('should support brotli encoding', function (done) {
it('should support brotli encoding', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'br')
test.set('Content-Type', 'application/json')
test.write(Buffer.from('8b06807b226e616d65223a22e8aeba227d03', 'hex'))
test.expect(200, '{"name":"论"}', done)
})

nobrotlit('should throw 415 if there\'s no brotli support', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'br')
test.set('Content-Type', 'application/json')
test.write(Buffer.from('8b06807b226e616d65223a22e8aeba227d03', 'hex'))
test.expect(415, 'unsupported content encoding "br"', done)
})

it('should be case-insensitive', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'GZIP')
Expand Down
14 changes: 1 addition & 13 deletions test/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
? describe
: describe.skip

var hasBrotliSupport = 'createBrotliDecompress' in require('zlib')
var brotlit = hasBrotliSupport ? it : it.skip
var nobrotlit = !hasBrotliSupport ? it : it.skip

describe('bodyParser.raw()', function () {
before(function () {
this.server = createServer()
Expand Down Expand Up @@ -459,22 +455,14 @@ describe('bodyParser.raw()', function () {
test.expect(200, 'buf:6e616d653de8aeba', done)
})

brotlit('should support brotli encoding', function (done) {
it('should support brotli encoding', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'br')
test.set('Content-Type', 'application/octet-stream')
test.write(Buffer.from('8b03806e616d653de8aeba03', 'hex'))
test.expect(200, 'buf:6e616d653de8aeba', done)
})

nobrotlit('should throw 415 if there\'s no brotli support', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'br')
test.set('Content-Type', 'application/octet-stream')
test.write(Buffer.from('8b03806e616d653de8aeba03', 'hex'))
test.expect(415, 'unsupported content encoding "br"', done)
})

it('should be case-insensitive', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'GZIP')
Expand Down
14 changes: 1 addition & 13 deletions test/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
? describe
: describe.skip

var hasBrotliSupport = 'createBrotliDecompress' in require('zlib')
var brotlit = hasBrotliSupport ? it : it.skip
var nobrotlit = !hasBrotliSupport ? it : it.skip

describe('bodyParser.text()', function () {
before(function () {
this.server = createServer()
Expand Down Expand Up @@ -529,22 +525,14 @@ describe('bodyParser.text()', function () {
test.expect(200, '"name is 论"', done)
})

brotlit('should support brotli encoding', function (done) {
it('should support brotli encoding', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'br')
test.set('Content-Type', 'text/plain')
test.write(Buffer.from('0b05806e616d6520697320e8aeba03', 'hex'))
test.expect(200, '"name is 论"', done)
})

nobrotlit('should throw 415 if there\'s no brotli support', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'br')
test.set('Content-Type', 'text/plain')
test.write(Buffer.from('0b05806e616d6520697320e8aeba03', 'hex'))
test.expect(415, 'unsupported content encoding "br"', done)
})

it('should be case-insensitive', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'GZIP')
Expand Down
14 changes: 1 addition & 13 deletions test/urlencoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ var describeAsyncHooks = typeof asyncHooks.AsyncLocalStorage === 'function'
? describe
: describe.skip

var hasBrotliSupport = 'createBrotliDecompress' in require('zlib')
var brotlit = hasBrotliSupport ? it : it.skip
var nobrotlit = !hasBrotliSupport ? it : it.skip

describe('bodyParser.urlencoded()', function () {
before(function () {
this.server = createServer()
Expand Down Expand Up @@ -907,22 +903,14 @@ describe('bodyParser.urlencoded()', function () {
test.expect(200, '{"name":"论"}', done)
})

brotlit('should support brotli encoding', function (done) {
it('should support brotli encoding', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'br')
test.set('Content-Type', 'application/x-www-form-urlencoded')
test.write(Buffer.from('8b03806e616d653de8aeba03', 'hex'))
test.expect(200, '{"name":"论"}', done)
})

nobrotlit('should throw 415 if there\'s no brotli support', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'br')
test.set('Content-Type', 'application/x-www-form-urlencoded')
test.write(Buffer.from('789ccb4bcc4db57db16e17001068042f', 'hex'))
test.expect(415, 'unsupported content encoding "br"', done)
})

it('should be case-insensitive', function (done) {
var test = request(this.server).post('/')
test.set('Content-Encoding', 'GZIP')
Expand Down

0 comments on commit cd985a8

Please sign in to comment.