How get remote address for HttpServerRequest?

3,810 views
Skip to first unread message

万古云霄一羽毛

unread,
Jan 31, 2013, 8:10:36 AM1/31/13
to ve...@googlegroups.com
How get remote address for HttpServerRequest, like javax.servlet.HttpServletRequest request.getRemoteAddr?

Pid

unread,
Jan 31, 2013, 8:58:55 AM1/31/13
to ve...@googlegroups.com
On 31/01/2013 13:10, 万古云霄一羽毛 wrote:
> How get remote address for HttpServerRequest, like
> javax.servlet.HttpServletRequest *request.getRemoteAddr*?

All HTTP headers are available in the headers() collection.


p

> --
> You received this message because you are subscribed to the Google
> Groups "vert.x" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to vertx+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>


--

[key:62590808]

万古云霄一羽毛

unread,
Jan 31, 2013, 8:21:18 PM1/31/13
to ve...@googlegroups.com
Thansk,I loop ALL HTTP headers.

for (String key : req.headers().keySet()) {
        logger.info("#" + key + "=" + req.headers().get(key));
}

The content image is:
The remote ip address not in the http headers.

在 2013年1月31日星期四UTC+8下午9时58分55秒,Pid写道:

Ronan Michaux

unread,
Feb 1, 2013, 3:07:46 AM2/1/13
to ve...@googlegroups.com
With Groovy :

import org.vertx.groovy.core.http.HttpServerRequest

String getIp(HttpServerRequest req) {
        req.toJavaRequest().conn.channel.remoteAddress.hostString
}


In Java you have to use introspection to get values of private fields :

https://github.com/vert-x/vert.x/issues/112#issuecomment-9889478

I hope, that helps...

Regards,
Ronan.

Ronan Michaux

unread,
Feb 1, 2013, 3:19:05 AM2/1/13
to ve...@googlegroups.com
/!\ It doesn't use public API /!\

Brian Lalor

unread,
Feb 1, 2013, 6:37:48 AM2/1/13
to ve...@googlegroups.com
On Feb 1, 2013, at 3:19 AM, Ronan Michaux <ronan....@gmail.com> wrote:

/!\ It doesn't use public API /!\

Agreed.  This needs to be exposed.

Jeremy Truelove

unread,
Oct 29, 2014, 11:45:46 PM10/29/14
to ve...@googlegroups.com, bla...@bravo5.org
So I'm calling request.remoteAddress().getAddress().getHostAddress() on a HttpServerRequest and I'm always getting 127.0.0.1 which seems wrong as the connections are not coming from the host where I'm running the server at all. Am I missing something here?

Jeremy Truelove

unread,
Oct 30, 2014, 2:36:12 AM10/30/14
to ve...@googlegroups.com, bla...@bravo5.org
Never mind I think this is Nginx in front of my server causing the problem, false alarm my bad.

Adam Medeiros

unread,
Aug 17, 2018, 1:24:13 AM8/17/18
to vert.x
It's now 2018. Was the client IP address ever exposed within the request? Or, is there a way to get it through the route handlers? Is there a way to get it from the connection handler and then set a header with the client IP address so that it can be fetched in the route context? Any documentation on how to get the client ip address and pass it along in the routing context?

Julien Viet

unread,
Aug 17, 2018, 9:56:59 AM8/17/18
to ve...@googlegroups.com
the client IP is exposed by the request remoteAddress() method.

in the routing context you have access to the http server request.

HTH

Julien

On 17 Aug 2018, at 07:24, Adam Medeiros <adam...@gmail.com> wrote:

It's now 2018. Was the client IP address ever exposed within the request? Or, is there a way to get it through the route handlers? Is there a way to get it from the connection handler and then set a header with the client IP address so that it can be fetched in the route context? Any documentation on how to get the client ip address and pass it along in the routing context?

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Adam Medeiros

unread,
Aug 17, 2018, 12:09:48 PM8/17/18
to ve...@googlegroups.com
Thanks Julian. I tried exactly what you suggested prior to asking. In ruby, the cntxt .request.remote_address call hangs and causes a timeout for me. So I thought I was trying the wrong thing. Instead of getting a string as a return value, remote_address returns some kind of a Socket object I think. I’ll look again today.


Reply all
Reply to author
Forward
0 new messages