diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 0320f1b7c6..426d0669f6 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -1765,4 +1765,24 @@ public class Functions { .replaceAll("(\\w{10})(?=\\w{3})", "$1") ; } + + /** + * Advertises the minimum set of HTTP headers that assist programmatic + * discovery of Jenkins. + */ + public static void advertiseHeaders(HttpServletResponse rsp) { + Jenkins j = Jenkins.getInstance(); + + rsp.setHeader("X-Hudson","1.395"); + rsp.setHeader("X-Jenkins", Jenkins.VERSION); + rsp.setHeader("X-Jenkins-Session", Jenkins.SESSION_HASH); + + TcpSlaveAgentListener tal = j.tcpSlaveAgentListener; + if (tal !=null) { + rsp.setIntHeader("X-Hudson-CLI-Port", tal.getPort()); + rsp.setIntHeader("X-Jenkins-CLI-Port", tal.getPort()); + rsp.setIntHeader("X-Jenkins-CLI2-Port", tal.getPort()); + rsp.setHeader("X-Jenkins-CLI-Host", TcpSlaveAgentListener.CLI_HOST_NAME); + } + } } diff --git a/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java b/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java index 630d225f4f..30f386eb1f 100644 --- a/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java +++ b/core/src/main/java/hudson/security/HudsonAuthenticationEntryPoint.java @@ -23,6 +23,7 @@ */ package hudson.security; +import hudson.Functions; import jenkins.model.Jenkins; import hudson.TcpSlaveAgentListener; @@ -84,14 +85,7 @@ public class HudsonAuthenticationEntryPoint extends AuthenticationProcessingFilt rsp.setStatus(SC_FORBIDDEN); rsp.setContentType("text/html;charset=UTF-8"); - // advertise the CLI TCP port - TcpSlaveAgentListener tal = Jenkins.getInstance().getTcpSlaveAgentListener(); - if (tal!=null) { - rsp.setIntHeader("X-Hudson-CLI-Port", tal.getPort()); - rsp.setIntHeader("X-Jenkins-CLI-Port", tal.getPort()); - rsp.setIntHeader("X-Jenkins-CLI2-Port", tal.getPort()); - rsp.setHeader("X-Jenkins-CLI-Host", TcpSlaveAgentListener.CLI_HOST_NAME); - } + Functions.advertiseHeaders(rsp); AccessDeniedException2 cause = null; // report the diagnosis information if possible diff --git a/core/src/main/resources/lib/layout/layout.jelly b/core/src/main/resources/lib/layout/layout.jelly index adcf6b66ef..75ef24237a 100644 --- a/core/src/main/resources/lib/layout/layout.jelly +++ b/core/src/main/resources/lib/layout/layout.jelly @@ -71,16 +71,7 @@ ${h.initPageVariables(context)} - - - - - - - - - - + ${h.advertiseHeaders(response)}