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

Missing information about changes in SoketAddress for getting hostname and IP #70

Open
gilhod opened this issue Jul 21, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@gilhod
Copy link

gilhod commented Jul 21, 2022

SoketAddress.host() used to return IP address. Now after the migration it returns host name. From SoketAddress docs it seems that host() method changed its meaning, and I should use hostAddress if I want the IP. This is not documneted in migration guide, and it is very confusing and easy to overlook in the migration.

@gilhod gilhod added the bug Something isn't working label Jul 21, 2022
@vietj vietj self-assigned this Jul 21, 2022
@vietj
Copy link
Contributor

vietj commented Jul 21, 2022

thanks

@vietj
Copy link
Contributor

vietj commented Aug 4, 2022

it seems according to the implementation that previously host could also return the hostname in vertx 3, can you give an example of a difference you found ?

@gilhod
Copy link
Author

gilhod commented Aug 7, 2022

We experienced the change when trying to get remote IP address of http connection:
HttpClientRequest.connection().remoteAddress().host()

@vietj
Copy link
Contributor

vietj commented Aug 7, 2022

that's odd, I just checked the vertx 3 behavior and I don't understand how that is possible, can you provide a reproducer ?

@gilhod
Copy link
Author

gilhod commented Aug 8, 2022

Sure. Here is a reproducer.
Java 8, Windows 10 Pro

vertx version 4.2.7:
`import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.http.HttpMethod;

public class HostAddressVertx4 {

public static void main(String[] args) {

System.out.println("vertx version 4.2.7");

Vertx
    .vertx()
    .createHttpClient()
    .request(HttpMethod.GET, 443, "icanhazdadjoke.com", "/", ar -> {
      if (ar.succeeded()) {
        HttpClientRequest request = ar.result();
        request.response(ar2 -> {
          if (ar2.succeeded()) {
            HttpClientResponse response = ar2.result();
            String host = response.request().connection().remoteAddress().host();
            System.out.println("host() method returns: " +  host);
          } else {
            System.out.println("Response error: " + ar.cause());
          }
        }).send();
      } else {
        System.out.println("Request error: " + ar.cause());
      }
    });

}
}
`

vertx version 3.9.5
`import io.vertx.core.Vertx;

public class HostAddressVertx3 {

public static void main(String[] args) {

System.out.println("vertx version 3.9.5");

Vertx
    .vertx()
    .createHttpClient()
    .get(443, "icanhazdadjoke.com", "/")
    .handler(response -> {
      String host = response.request().connection().remoteAddress().host();
      System.out.println("host() method returns: " +  host);
    })
    .exceptionHandler(error -> {
      System.out.println("ERROR: " + error);
    })
    .end();

}
}`

Outputs:

vertx version 4.2.7 host() method returns: icanhazdadjoke.com

vertx version 3.9.5 host() method returns: 104.21.37.176

@sac10nikam
Copy link

https://vertx.io/docs/apidocs/io/vertx/core/net/SocketAddress.html

host() - Returns the host name when available or the IP address in string representation.
hostName() - Returns the host name when available or null. Domain socket address returns null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

3 participants