Use server name for advertised SSH host keys

Like our parent commit, if we are behind an Apache2 reverse proxy,
getLocalAddr() returns 127.0.0.1, which is not an address that a
client can use to connect to us.

Instead we should use the hostname the client asked Apache for in
the HTTP headers, as that is still present as getServerName().

Signed-off-by: Shawn O. Pearce <sop@google.com>
diff --git a/src/main/java/com/google/gerrit/server/SystemInfoServiceImpl.java b/src/main/java/com/google/gerrit/server/SystemInfoServiceImpl.java
index 69d9959..8a674b6 100644
--- a/src/main/java/com/google/gerrit/server/SystemInfoServiceImpl.java
+++ b/src/main/java/com/google/gerrit/server/SystemInfoServiceImpl.java
@@ -145,17 +145,17 @@
         GerritJsonServlet.getCurrentCall().getHttpServletRequest();
 
     InetSocketAddress addr = GerritSshDaemon.getAddress();
-    if (addr.getAddress() != null && addr.getAddress().isAnyLocalAddress()) {
-      final InetAddress me;
+    InetAddress ip = addr.getAddress();
+    if (ip.isAnyLocalAddress()) {
       try {
-        me = InetAddress.getByName(req.getLocalAddr());
+        ip = InetAddress.getByName(req.getServerName());
       } catch (UnknownHostException e) {
-        throw new RuntimeException("Unexpected uknown host", e);
+        throw new RuntimeException(e);
       }
-      addr = new InetSocketAddress(me, addr.getPort());
+      addr = new InetSocketAddress(ip, addr.getPort());
     }
 
-    if (addr.getPort() == 22 && !(addr.getAddress() instanceof Inet6Address)) {
+    if (addr.getPort() == 22 && !(ip instanceof Inet6Address)) {
       return addr.getHostName();
     }
     return "[" + addr.getHostName() + "]:" + addr.getPort();