Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content-Length: 0 for statically servered, gzipped content #20

Open
ericclemmons opened this issue Jan 14, 2013 · 0 comments
Open

Content-Length: 0 for statically servered, gzipped content #20

ericclemmons opened this issue Jan 14, 2013 · 0 comments

Comments

@ericclemmons
Copy link

(This issue first arose here: ericclemmons/genesis-skeleton#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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant