views:

46

answers:

1

Hi,

I just created a HTTP server using this code fro the documentation:

var sys = require("sys"),
    http = require("http");

http.createServer(function(request, response) {
    response.writeHead(200, {"Content-Type": "text/plain"});
    response.end("Hello World!");
    sys.puts('Connection');
}).listen(8080);

sys.puts("Server running at http://localhost:8080/");**

My question is, why when I go to localhost:8080 I got "connection" printed twice? is this a bug?

+2  A: 

Your browser may be requesting the URL twice, once with a HEAD request and once with a GET request. Try using a simple interface, like telnet:

$ telnet localhost 8080
GET / HTTP/1.0

^]q

Leave a blank line after GET, and press Ctrl+]qEnter to get out.

Greg Hewgill
Don't think it's a HEAD and GET. Most likely the second requests is in search of the favicon, but that's nitpicking.
Ivo Wetzel
@Ivo: Good call, that's probably it indeed.
Greg Hewgill
that's correct, I just did: sys.puts(request.url); and the second one if for the favicon. Thanks
fast-dev