This repository has been archived by the owner. It is now read-only.

Can't update req.connection.remoteAddress #3323

Closed
keverw opened this Issue May 25, 2012 · 3 comments

Comments

Projects
None yet
2 participants
@keverw

keverw commented May 25, 2012

I use CloudFlare and I wrote a little module to check if CloudFlare is connecting and get the real IP address(https://github.com/keverw/node_CloudFlare).

In my app I use Express and I have a route before everything and then I call next(); In that first route I detect if they are using CloudFlare.

if (cf.check(req)) //CF
{
    req.connection.remoteAddress = cf.get(req);

    console.log('real ip: ' + cf.get(req));
    console.log('real IP: ' + req.connection.remoteAddress); //This doesn't match the console.log before it.
}
next();

I noticed you can't update req.connection.remoteAddress. I'm not sure if this is more of a bug or feature request. But I have a valid reason to update it and I don't see why this should be prevented. I can write new vars to req like req.ip = as a work around but I really wish I could just update req.connection.remoteAddress encase other modules try to read it, like say they wren't by me and not using req.ip, plus req.ip isn't really a standard anyways.

Can updating req.connection.remoteAddress be added(for both http and https) or fixed please? Is there a better workaround?

@bnoordhuis

This comment has been minimized.

Show comment Hide comment
@bnoordhuis

bnoordhuis May 25, 2012

Member

I already explained this to you on IRC: req.connection.remoteAddress is a getter. If you want to override it, define your own: req.connection.__defineGetter__('remoteAddress', function() { ... })

Member

bnoordhuis commented May 25, 2012

I already explained this to you on IRC: req.connection.remoteAddress is a getter. If you want to override it, define your own: req.connection.__defineGetter__('remoteAddress', function() { ... })

@bnoordhuis bnoordhuis closed this May 25, 2012

@keverw

This comment has been minimized.

Show comment Hide comment
@keverw

keverw May 25, 2012

Thanks for the code example. So I put that where I did my req.connection.remoteAddress = line? Gonna go try it.

keverw commented May 25, 2012

Thanks for the code example. So I put that where I did my req.connection.remoteAddress = line? Gonna go try it.

@keverw

This comment has been minimized.

Show comment Hide comment
@keverw

keverw May 26, 2012

Thanks :) seems to be working.

if (cf.check(req)) //CF
    {
        req.ip = cf.get(req);
        req.connection.__defineGetter__('remoteAddress', function() {
            return req.ip;
        });

I put in my route. It seems to be working. Think I'm doing it right.

keverw commented May 26, 2012

Thanks :) seems to be working.

if (cf.check(req)) //CF
    {
        req.ip = cf.get(req);
        req.connection.__defineGetter__('remoteAddress', function() {
            return req.ip;
        });

I put in my route. It seems to be working. Think I'm doing it right.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.