spdy-http2 / node-spdy

SPDY server on Node.js
2.81k stars 196 forks source link

No remoteAddress in request object #55

Closed larzconwell closed 12 years ago

larzconwell commented 12 years ago

In Geddy we're adding SPDY support and we have a logger that logs all the requests. But when a browser request comes in from SPDY we aren't getting back a request.connection.remoteAddress item, which we are using to log the request IP.

But the remoteAddress exists when you try to curl to the server.

Here's the http version of the code I was using:

var http = require('http');

http.createServer(function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  console.log(req.method + ' ' + req.connection.remoteAddress)
  res.end('Hello ' + req.connection.remoteAddress);
}).listen(3000);

Curling to the server I get this response, same if I go to the address on the browser.

curl localhost:3000 
=> Hello 127.0.0.1

Now here's the SPDY example I was using:

var fs = require('fs')
  , spdy = require('spdy')
  , options = { 
      key: fs.readFileSync('/home/larz/Desktop/server.key')
    , cert: fs.readFileSync('/home/larz/Desktop/server.crt')
  };

spdy.createServer(options, function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  console.log(req.method + ' ' + req.connection.remoteAddress);
  res.end('Hello ' + req.connection.remoteAddress);
}).listen(3000);

Curling to the server this time I get the same thing back

curl -k https://localhost:3000
=> Hello 127.0.0.1

But when I try to go to it via the browser I get "Hello undefined"

indutny commented 12 years ago

Thanks, fixed in 13ec8d7

larzconwell commented 12 years ago

Thanks man!