From 396f29985a910b8506785f454703370aa4926b53 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 1 Jul 2008 18:01:38 +0000 Subject: [PATCH] the server name in the arguments also need to take the reverse proxy into account. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@10543 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/Functions.java | 23 +++++++++++++++++++ .../SlaveComputer/slave-agent.jnlp.jelly | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index d62070e9df..3ac8c91677 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 2232ee69ef..fd87a11cef 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 @@ - ${request.serverName} + ${h.getServerName()} ${rootURL}/tcpSlaveAgentListener/ ${app.secretKey} ${it.node.nodeName} -- GitLab