vertx-4-migration-guide icon indicating copy to clipboard operation
vertx-4-migration-guide copied to clipboard

Missing information about changes in SoketAddress for getting hostname and IP

Open gilhod opened this issue 1 year ago • 6 comments

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 avatar Jul 21 '22 09:07 gilhod

thanks

vietj avatar Jul 21 '22 10:07 vietj

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 ?

vietj avatar Aug 04 '22 07:08 vietj

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

gilhod avatar Aug 07 '22 07:08 gilhod

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

vietj avatar Aug 07 '22 21:08 vietj

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

gilhod avatar Aug 08 '22 08:08 gilhod

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.

sac10nikam avatar Sep 26 '22 12:09 sac10nikam