[Pkg-javascript-commits] [node-static] 25/151: 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).

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:17:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository node-static.

commit 0549e6393368dadcf1d00deba63ee811c4e723ee
Author: jeremybarnes <jeremy at recoset.com>
Date:   Fri Aug 6 02:54:58 2010 +0800

    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 at 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 at 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.
---
 lib/node-static.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/node-static.js b/lib/node-static.js
index a9a57aa..4e8abd2 100644
--- a/lib/node-static.js
+++ b/lib/node-static.js
@@ -71,8 +71,8 @@ this.Server.prototype.serveFile = function (pathname, req, res, callback) {
                     that.respond(null, [pathname], stat, req, res, finish);
 
                 } else if (stat.isDirectory()) {
-                    path.exists(htmlIndex, function (exists) {
-                        if (exists) {
+                    fs.stat(htmlIndex, function (e, stat) {
+                        if (!e) {
                             that.respond(null, [htmlIndex], stat, req, res, finish);
                         } else {
                             if (pathname in exports.store) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-static.git



More information about the Pkg-javascript-commits mailing list