Skip to content

Commit

Permalink
the server name in the arguments also need to take the reverse proxy …
Browse files Browse the repository at this point in the history
…into account.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@10543 71c3de6d-444a-0410-be80-ed276b4c234a
  • Loading branch information
kohsuke committed Jul 1, 2008
1 parent dacf960 commit 396f299
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions core/src/main/java/hudson/Functions.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
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;
Expand Down Expand Up @@ -885,5 +887,26 @@ public String getSystemProperty(String key) {
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]+://.+");
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</resources>

<application-desc main-class="hudson.jnlp.Main">
<argument>${request.serverName}</argument>
<argument>${h.getServerName()}</argument>
<argument>${rootURL}/tcpSlaveAgentListener/</argument>
<argument>${app.secretKey}</argument>
<argument>${it.node.nodeName}</argument>
Expand Down

0 comments on commit 396f299

Please sign in to comment.