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

logger middleware throws "TypeError: Cannot read property 'content-length' of undefined" #318

Closed
eden opened this issue Jul 8, 2011 · 1 comment

Comments

@eden
Copy link

eden commented Jul 8, 2011

The logger middleware in 1.5.2 throws the above error if it's included before middleware that writes a response.

Example:

$ cat bug.js 
var connect = require('connect');
connect(
  connect.logger(),
  connect.favicon()
).listen(1111)

$ node bug &
[1] 6251

$ curl -s :1111/favicon.ico >/dev/null

/usr/local/lib/node_modules/connect/lib/middleware/logger.js:281
return res._headers[field.toLowerCase()];
                     ^
TypeError: Cannot read property 'content-length' of undefined
    at Function.res (/usr/local/lib/node_modules/connect/lib/middleware/logger.js:281:22)
    at anonymous (eval at compile (/usr/local/lib/node_modules/connect/lib/middleware/logger.js:158:10))
    at ServerResponse.<anonymous> (/usr/local/lib/node_modules/connect/lib/middleware/logger.js:138:20)
    at /usr/local/lib/node_modules/connect/lib/middleware/favicon.js:69:15
    at [object Object].<anonymous> (fs.js:107:5)
    at [object Object].emit (events.js:61:17)
    at afterRead (fs.js:878:12)
    at wrapper (fs.js:245:17)

Swapping the order of logger() and favicon() "fixes" it except nothing is logged for non-404 responses. Downgrading to 1.5.1 fixes everything.

@tj
Copy link
Member

tj commented Jul 8, 2011

probably due to the writeHead() in favicon, node doesnt really normalize any of this stuff internally so its a bit of a mess trying to provide this. and res.getHeader() throws in node after you write the header

@tj tj closed this as completed in dbbc704 Jul 8, 2011
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

2 participants