Skip to content

Commit

Permalink
Delegate compression to servlet container (#9379)
Browse files Browse the repository at this point in the history
* Delegate compression to servlet container

* Update incrementals

* Use released versions
  • Loading branch information
basil authored Jun 18, 2024
1 parent 92ac1d8 commit 500169b
Show file tree
Hide file tree
Showing 19 changed files with 25 additions and 100 deletions.
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ THE SOFTWARE.
<properties>
<commons-fileupload2.version>2.0.0-M2</commons-fileupload2.version>
<slf4jVersion>2.0.13</slf4jVersion>
<stapler.version>1880.vb_6d94a_3b_05db_</stapler.version>
<stapler.version>1881.vd39f3ee5c629</stapler.version>
<groovy.version>2.4.21</groovy.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.UncaughtExceptionFilter;
import org.kohsuke.stapler.WebApp;
import org.kohsuke.stapler.compression.CompressionFilter;

/**
* Deals with exceptions that get thrown all the way up to the Stapler rendering layer.
Expand All @@ -30,7 +30,7 @@ public class InstallUncaughtExceptionHandler {

@Initializer
public static void init(final Jenkins j) throws IOException {
CompressionFilter.setUncaughtExceptionHandler(j.servletContext, (e, context, req, rsp) -> handleException(j, e, req, rsp, 500));
UncaughtExceptionFilter.setUncaughtExceptionHandler(j.servletContext, (e, context, req, rsp) -> handleException(j, e, req, rsp, 500));
try {
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
LOGGER.log(Level.FINE, "Successfully installed a global UncaughtExceptionHandler.");
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/model/Api.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ public void doXml(StaplerRequest req, StaplerResponse rsp,
return;
}

// switch to gzipped output
try (OutputStream o = rsp.getCompressedOutputStream(req)) {
try (OutputStream o = rsp.getOutputStream()) {
if (isSimpleOutput(result)) {
// simple output allowed
rsp.setContentType("text/plain;charset=UTF-8");
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Computer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ public void doDumpExportTable(StaplerRequest req, StaplerResponse rsp) throws IO
checkPermission(Jenkins.ADMINISTER);

rsp.setContentType("text/plain");
try (PrintWriter w = new PrintWriter(rsp.getCompressedWriter(req))) {
try (PrintWriter w = new PrintWriter(rsp.getWriter())) {
VirtualChannel vc = getChannel();
if (vc instanceof Channel) {
w.println("Controller to agent");
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ public void doBuildTimestamp(StaplerRequest req, StaplerResponse rsp, @QueryPara
public void doConsoleText(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("text/plain;charset=UTF-8");
try (InputStream input = getLogInputStream();
OutputStream os = rsp.getCompressedOutputStream(req);
OutputStream os = rsp.getOutputStream();
PlainTextConsoleOutputStream out = new PlainTextConsoleOutputStream(os)) {
IOUtils.copy(input, out);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/security/csrf/CrumbIssuer.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static class RestrictedApi extends Api {
text = null;
}
if (text != null) {
try (OutputStream o = rsp.getCompressedOutputStream(req)) {
try (OutputStream o = rsp.getOutputStream()) {
rsp.setContentType("text/plain;charset=UTF-8");
o.write(text.getBytes(StandardCharsets.UTF_8));
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/triggers/SCMTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public String getUrlName() {
*/
public void doPollingLog(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("text/plain;charset=UTF-8");
try (OutputStream os = rsp.getCompressedOutputStream(req);
try (OutputStream os = rsp.getOutputStream();
// Prevent jelly from flushing stream so Content-Length header can be added afterwards
FlushProofOutputStream out = new FlushProofOutputStream(os)) {
getPollingLogText().writeLogTo(0, out);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/util/RemotingDiagnostics.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void doHeapDump(StaplerRequest req, StaplerResponse rsp) throws IOExcepti

FilePath dump = obtain();
try {
dump.copyTo(rsp.getCompressedOutputStream(req));
dump.copyTo(rsp.getOutputStream());
} finally {
dump.delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ THE SOFTWARE.
Called from doScriptText() to display the execution result.
-->
<?jelly escape-by-default='true'?>
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout">
<l:view contentType="text/plain;charset=UTF-8">
<j:out value="${output}"/>
</l:view>
</st:compress>
</j:jelly>
4 changes: 2 additions & 2 deletions core/src/main/resources/hudson/model/Run/console.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ THE SOFTWARE.
Displays the console output
-->
<?jelly escape-by-default='true'?>
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:t="/lib/hudson">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout" xmlns:t="/lib/hudson">
<l:layout title="${it.fullDisplayName} Console">
<st:include page="sidepanel.jelly" />

Expand Down Expand Up @@ -84,4 +84,4 @@ THE SOFTWARE.
</j:choose>
</l:main-panel>
</l:layout>
</st:compress>
</j:jelly>
4 changes: 2 additions & 2 deletions core/src/main/resources/hudson/model/Run/consoleFull.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<?jelly escape-by-default='true'?>
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:set var="consoleFull" value="true" />
<st:include page="console.jelly" />
</st:compress>
</j:jelly>
4 changes: 2 additions & 2 deletions core/src/main/resources/hudson/model/Run/statusIcon.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ THE SOFTWARE.
Displays the console output
-->
<?jelly escape-by-default='true'?>
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<st:setHeader name="X-Building" value="${it.building}" />
<st:setHeader name="X-Progress" value="${it.executor.progress}" />
<st:setHeader name="X-Executor-Runtime" value="${it.executor.timestampString}" />
Expand All @@ -37,4 +37,4 @@ THE SOFTWARE.
<l:ajax>
<l:icon alt="${it.iconColor.description}" src="symbol-status-${it.iconColor.iconName}" class="icon-xlg" tooltip="${it.iconColor.description}"/>
</l:ajax>
</st:compress>
</j:jelly>
4 changes: 2 additions & 2 deletions core/src/main/resources/hudson/model/View/index.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:layout title="${(it.class.name=='hudson.model.AllView' and it.ownerItemGroup == app) ? '%Dashboard' : it.displayName}${not empty it.ownerItemGroup.fullDisplayName?' ['+it.ownerItemGroup.fullDisplayName+']':''}">
<j:set var="view" value="${it}"/> <!-- expose view to the scripts we include from owner -->
<st:include page="sidepanel.jelly" />
Expand All @@ -49,4 +49,4 @@ THE SOFTWARE.
<st:adjunct includes="hudson.model.View.screen-resolution"/>
</l:header>
</l:layout>
</st:compress>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ THE SOFTWARE.
Displays the polling log output
-->
<?jelly escape-by-default='true'?>
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:layout title="${it.run.parent.displayName} #${it.run.number} ${%Polling Log}">
<st:include it="${it.run}" page="sidepanel.jelly" />
<l:main-panel>
Expand All @@ -39,4 +39,4 @@ THE SOFTWARE.
</pre>
</l:main-panel>
</l:layout>
</st:compress>
</j:jelly>
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ THE SOFTWARE.
<bridge-method-injector.version>1.29</bridge-method-injector.version>
<spotless.check.skip>false</spotless.check.skip>
<!-- Make sure to keep the jetty-maven-plugin version in war/pom.xml in sync with the Jetty release in Winstone: -->
<winstone.version>6.19</winstone.version>
<winstone.version>6.20</winstone.version>
</properties>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,6 @@ public void canViewPagesThatRedirectToViews() throws Exception {
}
}

@Test
public void canViewCompressedViews() throws Exception {
String[] urls = {"groovy/compress", "jelly/compress"};
for (String url : urls) {
HtmlPage root = j.createWebClient().goTo(url);
assertEquals("Fragment", root.getElementById("frag").asNormalizedText());
}
}

@Test
public void cannotViewFragment() throws Exception {
String[] urls = {"annotated/frag", "groovy/frag", "jelly/frag", "whitelist/frag"};
Expand Down

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions war/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ THE SOFTWARE.
<async-supported>true</async-supported>
</filter>
<filter>
<filter-name>compression-filter</filter-name>
<filter-class>org.kohsuke.stapler.compression.CompressionFilter</filter-class>
<filter-name>uncaught-exception-filter</filter-name>
<filter-class>org.kohsuke.stapler.UncaughtExceptionFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter>
Expand Down Expand Up @@ -149,7 +149,7 @@ THE SOFTWARE.
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>compression-filter</filter-name>
<filter-name>uncaught-exception-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
Expand Down

0 comments on commit 500169b

Please sign in to comment.