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
This commit is contained in:
kohsuke committed 2008-07-01 18:01:38 +00:00
1 parent dacf9604aa
commit 396f29985a
2 files changed
+24 -1

No files matched your search

+23
View File
@@ -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.
* <p>
* This is primarily used in <tt>slave-agent.jnlp.jelly</tt> 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]+://.+");
}