grunt-reload
grunt-reload copied to clipboard
Content-Length: 0 for statically servered, gzipped content
(This issue first arose here: https://github.com/ericclemmons/genesis-skeleton/issues/18)
To replicate, create a simple ExpressJS app that serves content out of a public folder:
// app.js
var express = require('express');
var path = require('path');
var app = module.exports = express();
app.set('port', process.env.PORT || 3000);
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session());
app.use(express.compress()); // NOTE: compressing all content-type: text/*
app.use(express.static(path.join(__dirname, '/public')));
app.listen(app.get('port'), function() {
console.log("Express server listening on port " + app.get('port'));
});
With grunt-reload running, try to load a plain html file, such as index.html (the content doesn't matter):
$ curl --head http://localhost:8000/humans.html
HTTP/1.1 200 OK
x-powered-by: Express
vary: Accept-Encoding
accept-ranges: bytes
etag: "191-1356665181000"
date: Mon, 14 Jan 2013 22:09:26 GMT
cache-control: public, max-age=0
last-modified: Fri, 28 Dec 2012 03:26:21 GMT
content-type: text/html; charset=UTF-8
content-length: 0
set-cookie: connect.sid=s%3ACYVzuoN%2Fmg4%2BQVUBHHXc55bg.KZZWwQOStI%2FeSDpesgkqtHRsHVfXIacQFMuGTXjrO0Q; Path=/; HttpOnly
connection: close
Notice the content-length: 0?
Now, it works if you change reload.js lines 126-135 to the following:
res.writeHead = function (statusCode, headers) {
_writeHead.call(res, statusCode, headers);
};
$ curl --head http://localhost:8000/humans.html
HTTP/1.1 200 OK
x-powered-by: Express
vary: Accept-Encoding
accept-ranges: bytes
etag: "191-1356665181000"
date: Mon, 14 Jan 2013 22:11:08 GMT
cache-control: public, max-age=0
last-modified: Fri, 28 Dec 2012 03:26:21 GMT
content-type: text/html; charset=UTF-8
content-length: 191
set-cookie: connect.sid=s%3AOdf1n%2Fd1bsJfd4QJeBh3E%2B2Y.qtjC9je2ENHFgIQ0j7p4hhW%2BDjhMA3ZMwhlkW2WKW9U; Path=/; HttpOnly
connection: close
I'm not sure why the original code defers html & headers for HTML content, but creates an issue when working with gzipped content...