Permalink
Browse files

Merge pull request #11 from dougwilson/feature/ignore-head-requests

Skip compression on HEAD requests.
  • Loading branch information...
2 parents 1a544e5 + 0b9c614 commit 1a5a7b9461c9f68b8a60339a66a50c570b63a648 @nateps committed Apr 2, 2012
Showing with 9 additions and 4 deletions.
  1. +1 −1 lib/gzip.js
  2. +4 −1 test/gzip.test.js
  3. +4 −2 test/helpers/index.js
View
@@ -64,7 +64,7 @@ exports = module.exports = function gzip(options) {
type = res.getHeader('content-type') || '';
encoding = res.getHeader('content-encoding');
- if (code !== 200 || !~accept.indexOf('gzip') ||
+ if (req.method === 'HEAD' || code !== 200 || !~accept.indexOf('gzip') ||
!matchType.test(type) || encoding ||
(~ua.indexOf('MSIE 6') && !~ua.indexOf('SV1'))) {
res.write = write;
View
@@ -91,6 +91,9 @@ module.exports = {
'gzip test compressable: multiple Accept-Encoding types': testCompressed(
css, cssPath, { 'Accept-Encoding': 'deflate, gzip, sdch' }, cssBody, matchCss
),
+ 'gzip test uncompressable: HEAD request': testUncompressed(
+ css, cssPath, { 'Accept-Encoding': 'gzip' }, '', matchCss, 'HEAD'
+ ),
'gzip test compressable: specify --best flag': testCompressed(
best, htmlPath, { 'Accept-Encoding': 'gzip' }, htmlBody, matchHtml
@@ -148,4 +151,4 @@ module.exports = {
'gzip test compressable: writeHead, end': testCompressed(
writeHeadEnd, htmlPath, { 'Accept-Encoding': 'gzip' }, htmlBody, matchHtml
),
-}
+}
View
@@ -14,10 +14,11 @@ function wrapTest(func, numCallbacks) {
}
}
-exports.testUncompressed = function(app, url, headers, resBody, resType) {
+exports.testUncompressed = function(app, url, headers, resBody, resType, method) {
return wrapTest(function(done) {
assert.response(app, {
url: url,
+ method: method ? method : 'GET',
headers: headers
}, {
status: 200,
@@ -31,10 +32,11 @@ exports.testUncompressed = function(app, url, headers, resBody, resType) {
});
}
-exports.testCompressed = function(app, url, headers, resBody, resType) {
+exports.testCompressed = function(app, url, headers, resBody, resType, method) {
return wrapTest(function(done) {
assert.response(app, {
url: url,
+ method: method ? method : 'GET',
headers: headers,
encoding: 'binary'
}, {

0 comments on commit 1a5a7b9

Please sign in to comment.