vert-x3 / vertx-4-migration-guide

Migration to Vert.x 4 guide
https://vert-x3.github.io/vertx-4-migration-guide/index.html
20 stars 16 forks source link

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

Open gilhod opened 1 year ago

gilhod commented 1 year ago

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.

vietj commented 1 year ago

thanks

vietj commented 1 year ago

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 commented 1 year ago

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

vietj commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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.