Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #242 from cnpm/gzip
Browse files Browse the repository at this point in the history
gzip support. fix #241
  • Loading branch information
dead-horse committed Mar 3, 2014
2 parents 7e3129c + ff1bfd5 commit 869d568
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"humanize-number": "0.0.2",
"koa": "0.5.0",
"koa-markdown": "0.0.2",
"koa-middlewares": "0.0.6",
"koa-middlewares": "0.0.7",
"logfilestream": "0.1.0",
"marked": "0.3.1",
"microtime": "0.5.1",
Expand All @@ -42,7 +42,7 @@
"qn": "0.2.0",
"ready": "0.1.1",
"semver": "2.2.1",
"thunkify-wrap": "0.0.1",
"thunkify-wrap": "0.0.3",
"urllib": "0.5.5",
"utility": "0.1.10"
},
Expand Down
1 change: 1 addition & 0 deletions servers/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ app.use(middlewares.bodyParser({jsonLimit: config.jsonLimit}));
app.use(auth());
app.use(notFound);

app.use(middlewares.gzip());
app.use(middlewares.fresh());
app.use(middlewares.etag());

Expand Down
4 changes: 4 additions & 0 deletions servers/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ app.use(session);
app.use(middlewares.bodyParser());
app.use(notFound);

app.use(middlewares.gzip());
app.use(middlewares.fresh());
app.use(middlewares.etag());

var viewDir = path.join(rootdir, 'view', 'web');
var docDir = path.join(rootdir, 'docs', 'web');

Expand Down
20 changes: 20 additions & 0 deletions test/controllers/registry/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,26 @@ describe('controllers/registry/module.test.js', function () {
});
});

it('should return module info and gzip when accept-encoding=gzip', function (done) {
request(app)
.get('/cnpmjs.org')
.set('accept-encoding', 'gzip')
.expect('content-encoding', 'gzip')
.expect(200, function (err, res) {
// console.log(res.headers)
should.not.exist(err);
// should have etag
res.headers.should.have.property('etag');
etag = res.headers.etag;
res.body.should.have.keys('_id', '_rev', 'name', 'description',
'versions', 'dist-tags', 'readme', 'maintainers',
'time', 'author', 'repository', '_attachments');
res.body.name.should.equal('cnpmjs.org');
res.body.versions[Object.keys(res.body.versions)[0]].dist.tarball.should.include('/cnpmjs.org/download');
done();
});
});

it('should 304 when etag match', function (done) {
request(app)
.get('/cnpmjs.org')
Expand Down
7 changes: 6 additions & 1 deletion test/controllers/web/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,14 @@ describe('controllers/web/package.test.js', function () {
request(app)
.get('/package/cutter')
.expect(200)
.expect('content-encoding', 'gzip')
.expect(/<div id="package">/)
.expect(/<th>Maintainers<\/th>/)
.expect(/<th>Version<\/th>/, done);
.expect(/<th>Version<\/th>/, function (err, res) {
should.not.exist(err);
res.should.have.header('etag');
done();
});
});

it('should get 404', function (done) {
Expand Down

0 comments on commit 869d568

Please sign in to comment.