diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index d62070e9df9a8dea4032496fc86dac4aa235279a..3ac8c916776083fc75aac1ddf96984598c6fe238 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -55,6 +55,8 @@ import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; import java.net.URI; import java.net.URISyntaxException; +import java.net.URL; +import java.net.MalformedURLException; import java.util.Calendar; import java.util.Collection; import java.util.Collections; @@ -885,5 +887,26 @@ public class Functions { return System.getProperty(key); } + /** + * Obtains the host name of the Hudson server that clients can use to talk back to. + *
+ * This is primarily used in slave-agent.jnlp.jelly to specify the destination
+ * that the slaves talk to.
+ */
+ public String getServerName() {
+ // try to infer this from the request URL
+ String url = Hudson.getInstance().getRootUrl();
+ try {
+ if(url!=null) {
+ String host = new URL(url).getHost();
+ if(host!=null)
+ return host;
+ }
+ } catch (MalformedURLException e) {
+ // fall back to HTTP request
+ }
+ return Stapler.getCurrentRequest().getServerName();
+ }
+
private static final Pattern SCHEME = Pattern.compile("[a-z]+://.+");
}
diff --git a/core/src/main/resources/hudson/slaves/SlaveComputer/slave-agent.jnlp.jelly b/core/src/main/resources/hudson/slaves/SlaveComputer/slave-agent.jnlp.jelly
index 2232ee69efa6d890d029b817350c6576ec324df4..fd87a11cefd88916dc311be55cfe15c90a78ba64 100644
--- a/core/src/main/resources/hudson/slaves/SlaveComputer/slave-agent.jnlp.jelly
+++ b/core/src/main/resources/hudson/slaves/SlaveComputer/slave-agent.jnlp.jelly
@@ -37,7 +37,7 @@