|
3 | 3 | var assert = require('node:assert')
|
4 | 4 | var AsyncLocalStorage = require('node:async_hooks').AsyncLocalStorage
|
5 | 5 | var http = require('node:http')
|
| 6 | +const zlib = require('node:zlib') |
6 | 7 | var request = require('supertest')
|
7 | 8 |
|
8 | 9 | var bodyParser = require('..')
|
9 | 10 |
|
| 11 | +const hasZstandardSupport = 'createZstdDecompress' in zlib |
| 12 | +const zstandardit = hasZstandardSupport ? it : it.skip |
| 13 | +const nozstandardit = !hasZstandardSupport ? it : it.skip |
| 14 | + |
10 | 15 | describe('bodyParser.json()', function () {
|
11 | 16 | it('should parse JSON', function (done) {
|
12 | 17 | request(createServer())
|
@@ -686,6 +691,24 @@ describe('bodyParser.json()', function () {
|
686 | 691 | test.expect(200, '{"name":"论"}', done)
|
687 | 692 | })
|
688 | 693 |
|
| 694 | + zstandardit('should support zstandard encoding', function (done) { |
| 695 | + const server = createServer({ experimentalZstd: true, limit: '1kb' }) |
| 696 | + var test = request(server).post('/') |
| 697 | + test.set('Content-Encoding', 'zstd') |
| 698 | + test.set('Content-Type', 'application/json') |
| 699 | + test.write(Buffer.from('28b52ffd200e7100007b226e616d65223a22e8aeba227d', 'hex')) |
| 700 | + test.expect(200, '{"name":"论"}', done) |
| 701 | + }) |
| 702 | + |
| 703 | + nozstandardit('should throw 415 if there\'s no zstandard support', function (done) { |
| 704 | + const server = createServer({ experimentalZstd: true, limit: '1kb' }) |
| 705 | + var test = request(server).post('/') |
| 706 | + test.set('Content-Encoding', 'zstd') |
| 707 | + test.set('Content-Type', 'application/json') |
| 708 | + test.write(Buffer.from('28b52ffd200e7100007b226e616d65223a22e8aeba227d', 'hex')) |
| 709 | + test.expect(415, '[encoding.unsupported] unsupported content encoding "zstd"', done) |
| 710 | + }) |
| 711 | + |
689 | 712 | it('should be case-insensitive', function (done) {
|
690 | 713 | var test = request(this.server).post('/')
|
691 | 714 | test.set('Content-Encoding', 'GZIP')
|
|
0 commit comments