LearnBoost/socket.io — Issue #602: this.req.headers.upgrade is undefined when trying to call toLowerCase()
Author: makeusabrew
Created: 2011-10-28 11:18:38+00:00
State: open

Hi guys,

First of all apologies I can't be more helpful with this bug report - it occurred on a production server thus logging was down to its minimum level. I'm also not very familiar with all the magic which socket.io provides, but here it is anyway. All of a sudden, my server app crashed, and the following was all I had in the log:

```
/var/www/socket2m/node/node_modules/socket.io/lib/transports/websocket/hybi-07-12.js:94
if (this.req.headers.upgrade.toLowerCase() !== 'websocket') {
^
TypeError: Cannot call method 'toLowerCase' of undefined
at WebSocket.onSocketConnect (/var/www/socket2m/node/node_modules/socket.io/lib/transports/websocket/hybi-07-12.js:94:32)
at WebSocket.handleRequest (/var/www/socket2m/node/node_modules/socket.io/lib/transport.js:71:10)
at WebSocket.Transport (/var/www/socket2m/node/node_modules/socket.io/lib/transport.js:31:8)
at new WebSocket (/var/www/socket2m/node/node_modules/socket.io/lib/transports/websocket/hybi-07-12.js:60:13)
at new WebSocket (/var/www/socket2m/node/node_modules/socket.io/lib/transports/websocket.js:31:17)
at Manager.handleClient (/var/www/socket2m/node/node_modules/socket.io/lib/manager.js:626:19)
at Manager.handleHTTPRequest (/var/www/socket2m/node/node_modules/socket.io/lib/manager.js:597:8)
at Manager.handleRequest (/var/www/socket2m/node/node_modules/socket.io/lib/manager.js:559:12)
at HTTPServer. (/var/www/socket2m/node/node_modules/socket.io/lib/manager.js:107:10)
at HTTPServer.emit (events.js:67:17)
```

It looks like something unexpected happened when a new client tried to connect to the server - with my poor HTTP knowledge it looks like socket.io is always expecting an upgrade header which it didn't receive? I suspect the fact that I am *only* supporting the websocket transport (e.g. io.set('transports', ['websocket']) may be relevant - perhaps an old client tried to connect which refused to send the upgrade header. Not sure.

Using latest release, 0.8.6 for both client and server:

```
socket.io@0.8.6 ./node_modules/socket.io
├── redis@0.6.7
├── policyfile@0.0.4
└── socket.io-client@0.8.6
```

Anything else I can provide you with to help, just shout.