This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Current CDN almost support auto gzip text base content mirrors. e.g.: http://registry.qiniudn.com/npm It can save ~650kb through gzip 700kb json content to 38kb.
- Loading branch information
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var zlib = require('zlib') | ||
var tap = require('tap') | ||
var server = require('./fixtures/server.js') | ||
var RC = require('../') | ||
var pkg = { | ||
_id: 'some-package-gzip@1.2.3', | ||
name: 'some-package-gzip', | ||
version: '1.2.3' | ||
} | ||
|
||
zlib.gzip(JSON.stringify(pkg), function (err, pkgGzip) { | ||
var client = new RC({ | ||
cache: __dirname + '/fixtures/cache' | ||
, 'fetch-retries': 1 | ||
, 'fetch-retry-mintimeout': 10 | ||
, 'fetch-retry-maxtimeout': 100 | ||
, registry: 'http://localhost:' + server.port }) | ||
|
||
tap.test('request gzip package content', function (t) { | ||
server.expect('GET', '/some-package-gzip/1.2.3', function (req, res) { | ||
res.statusCode = 200 | ||
res.setHeader('Content-Encoding', 'gzip'); | ||
res.setHeader('Content-Type', 'application/json'); | ||
res.end(pkgGzip) | ||
}) | ||
|
||
client.get('/some-package-gzip/1.2.3', function (er, data, raw, res) { | ||
if (er) throw er | ||
t.deepEqual(data, pkg) | ||
t.end() | ||
}) | ||
}) | ||
|
||
tap.test('request wrong gzip package content', function (t) { | ||
server.expect('GET', '/some-package-gzip-error/1.2.3', function (req, res) { | ||
res.statusCode = 200 | ||
res.setHeader('Content-Encoding', 'gzip') | ||
res.setHeader('Content-Type', 'application/json') | ||
res.end(new Buffer('wrong gzip content')) | ||
}) | ||
|
||
client.get('/some-package-gzip-error/1.2.3', function (er, data, raw, res) { | ||
t.ok(er) | ||
t.end() | ||
}) | ||
}) | ||
}); |