Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose local address in reactive ServerHttpRequest #24174

Closed
bilak opened this issue Dec 10, 2019 · 2 comments
Closed

Expose local address in reactive ServerHttpRequest #24174

bilak opened this issue Dec 10, 2019 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@bilak
Copy link

bilak commented Dec 10, 2019

Hello,
is there any way how to obtain localAddr from incoming request? I mean if I have multiple virtual addresses/interfaces on host and I need to distinguish on which address was the request accepted.

Only way which I found now is little hack with netty's HttpServerRequest.

if ((((AbstractServerHttpRequest) exchange.getRequest()).getNativeRequest()) instanceof HttpServerRequest) {
    final InetSocketAddress localAddress = ((HttpServerRequest) (((AbstractServerHttpRequest) exchange.getRequest()).getNativeRequest())).hostAddress();
    logger.debug("!!! Hostname {}, HostString {}, Address {}",
            localAddress.getHostName(),
            localAddress.getHostString(),
            localAddress.getAddress()
    );
}

Is there any general approach?

Thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 10, 2019
@rstoyanchev rstoyanchev self-assigned this Dec 10, 2019
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 10, 2019
@rstoyanchev rstoyanchev added this to the 5.2.3 milestone Dec 10, 2019
@rstoyanchev
Copy link
Contributor

rstoyanchev commented Dec 10, 2019

We already have ServerRequest#remoteAddress and ServerHttpRequest#getRemoteAddress and can add localAddress next to that.

By comparison the non-reactive ServerHttpRequest exposes both local and remote.

@rstoyanchev rstoyanchev changed the title Get localAddr from webflux Exposes local address in reactive ServerHttpRequest Dec 10, 2019
@bilak
Copy link
Author

bilak commented Dec 10, 2019

Yes that's the case. I was initially looking at non-reactive ServerHttpRequest so I was confused where can I find localAddress in reactive classes.
Just linking here this issue for reference.

@rstoyanchev rstoyanchev changed the title Exposes local address in reactive ServerHttpRequest Expose local address in reactive ServerHttpRequest Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants