If we're automatically serving up the index.html from a directory, we need to perform an extra stat() call to get the size of that file.  Otherwise, we end up setting the context-length to the size of the directory (4096 bytes in my case).
If we're automatically serving up the index.html from a directory, we need
to perform an extra stat() call to get the size of that file.  Otherwise,
we end up setting the context-length to the size of the directory (4096
bytes in my case).

This would lead to the first N bytes of the file being served, and the
client hanging around: the client was expecting more bytes, but the server
was just waiting for the client to send another request.

Even stranger, sometimes in the browser I'd get some binary data that looked
like it could be a memory dump.  I don't know if that was a problem with
firefox or if node-static was serving up some random data.

----

Testing:

I have a directory with an index.html file with 548 bytes that I'm serving
up.

Before:

jeremy@dev:~/projects/xxx$ wget -S http://localhost:9876/
--2010-08-05 14:26:42--  http://localhost:9876/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:9876... failed: Connection refused.
Connecting to localhost|127.0.0.1|:9876... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Cache-Control: max-age=1
  Server: node-static/0.4.2
  Etag: "14160490-4096-1281030888000"
  Date: Thu, 05 Aug 2010 18:26:42 GMT
  Last-Modified: Thu, 05 Aug 2010 17:54:48 GMT
  Content-Length: 4096
  Content-Type: text/html
  Connection: keep-alive
Length: 4096 (4.0K) [text/html]
Saving to: `index.html.7'

13% [====>                                  ] 548         --.-K/s  eta 2m 15s  ^C

After fix:

jeremy@dev:~/projects/xxx$ wget -S http://localhost:9876/
--2010-08-05 14:51:41--  http://localhost:9876/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:9876... failed: Connection refused.
Connecting to localhost|127.0.0.1|:9876... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Cache-Control: max-age=1
  Server: node-static/0.4.2
  Etag: "14160533-548-1281028503000"
  Date: Thu, 05 Aug 2010 18:51:41 GMT
  Last-Modified: Thu, 05 Aug 2010 17:15:03 GMT
  Content-Length: 548
  Content-Type: text/html
  Connection: keep-alive
Length: 548 [text/html]
Saving to: `index.html.8'

100%[======================================>] 548         --.-K/s   in 0s

2010-08-05 14:51:41 (1.48 MB/s) - `index.html.8' saved [548/548]

Note that the Content-Length is now correct.

edpaget/node-static,cloudhead/node-static,winkapp/node-static,janmonschke/node-static,hayksaakian/static_striationnutrition,lucasconstantino/node-static,Slayer95/node-static,hayashi311/node-static,brodybits/node-static