Try to fix host resolution
package io.micronaut.starter.api.bind;
import edu.umd.cs.findbugs.annotations.Nullable;
+import io.micronaut.context.env.Environment;
import io.micronaut.core.convert.ArgumentConversionContext;
+import io.micronaut.core.io.socket.SocketUtils;
import io.micronaut.core.type.Argument;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.bind.binders.TypedRequestArgumentBinder;
@@ -62,20 +64,28 @@ public class RequestInfoArgumentBinder implements TypedRequestArgumentBinder<Req
private String resolveUrl(HttpRequest<?> request) {
String url;
+ String hostname = System.getenv(Environment.HOSTNAME);
+ String host;
+ InetSocketAddress serverAddress = request.getServerAddress();
+ if (hostname != null) {
+ host = hostname;
+ } else {
+ hostname = request.getUri().getHost();
+ if (hostname != null) {
+ host = hostname;
+ } else {
if (embeddedServerProvider != null) {
- url = embeddedServerProvider.get().getURL().toString();
- if (url.endsWith("/")) {
- url = url.substring(0, url.length() - 1);
- }
+ host = embeddedServerProvider.get().getHost();
} else {
- InetSocketAddress serverAddress = request.getServerAddress();
- String host = serverAddress.getHostString();
+ host = SocketUtils.LOCALHOST;
+ }
+ }
+ }
int port = serverAddress.getPort();
- if (port > -1) {
+ if (port > -1 && port != 80) {
host = host + ":" + port;
}
url = (request.isSecure() ? "https" : "http") + "://" + host ;
- }
return url;
}
}
