From b590ed40aeea0facb2d66988bf12cc6b5022e5fa Mon Sep 17 00:00:00 2001 From: Bauke Scholtz Date: Sun, 9 Jul 2023 11:58:42 -0400 Subject: [PATCH] https://github.com/eclipse-ee4j/mojarra/issues/5272 Extract Faces spec version from manifest --- .../main/java/com/sun/faces/config/WebConfiguration.java | 8 ++++++++ .../java/com/sun/faces/context/ExternalContextImpl.java | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/impl/src/main/java/com/sun/faces/config/WebConfiguration.java b/impl/src/main/java/com/sun/faces/config/WebConfiguration.java index 012bb5cd16..f66dd7d28a 100644 --- a/impl/src/main/java/com/sun/faces/config/WebConfiguration.java +++ b/impl/src/main/java/com/sun/faces/config/WebConfiguration.java @@ -114,6 +114,8 @@ public class WebConfiguration { private FaceletsConfiguration faceletsConfig; private boolean hasFlows; + + private String specificationVersion; // ------------------------------------------------------------ Constructors @@ -134,6 +136,8 @@ private WebConfiguration(ServletContext servletContext) { getOptionValue(WebContextInitParameter.ResourceExcludes, " "); getOptionValue(WebContextInitParameter.FaceletsViewMappings, ";"); getOptionValue(WebContextInitParameter.FaceletsSuffix, " "); + + specificationVersion = getClass().getPackage().getSpecificationVersion(); } // ---------------------------------------------------------- Public Methods @@ -200,6 +204,10 @@ public void setHasFlows(boolean hasFlows) { this.hasFlows = hasFlows; } + public String getSpecificationVersion() { + return specificationVersion; + } + /** * Obtain the value of the specified boolean parameter * diff --git a/impl/src/main/java/com/sun/faces/context/ExternalContextImpl.java b/impl/src/main/java/com/sun/faces/context/ExternalContextImpl.java index bc5e77f3cb..13e505874b 100644 --- a/impl/src/main/java/com/sun/faces/context/ExternalContextImpl.java +++ b/impl/src/main/java/com/sun/faces/context/ExternalContextImpl.java @@ -43,6 +43,7 @@ import java.util.logging.Logger; import com.sun.faces.RIConstants; +import com.sun.faces.config.WebConfiguration; import com.sun.faces.context.flash.ELFlash; import com.sun.faces.renderkit.html_basic.ScriptRenderer; import com.sun.faces.renderkit.html_basic.StylesheetRenderer; @@ -130,7 +131,12 @@ public ExternalContextImpl(ServletContext sc, ServletRequest request, ServletRes boolean enabled = ContextParamUtils.getValue(servletContext, SendPoweredByHeader, Boolean.class); if (enabled) { - ((HttpServletResponse) response).addHeader("X-Powered-By", "Faces/3.0"); + String poweredBy = "Faces"; + String specificationVersion = WebConfiguration.getInstance(sc).getSpecificationVersion(); + if (specificationVersion != null) { + poweredBy += "/" + specificationVersion; + } + ((HttpServletResponse) response).addHeader("X-Powered-By", poweredBy); } distributable = ContextParamUtils.getValue(servletContext, ContextParam.EnableDistributable, Boolean.class);