Skip to content

Commit

Permalink
[FIXED JENKINS-13625]
Browse files Browse the repository at this point in the history
In the end, proper fix requires having a filter that tracks
GZipOutputStream.
  • Loading branch information
kohsuke committed May 24, 2012
1 parent ecec590 commit 18963ee
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 39 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Expand Up @@ -42,7 +42,7 @@ THE SOFTWARE.

<properties>
<staplerFork>true</staplerFork>
<stapler.version>1.188</stapler.version>
<stapler.version>1.189</stapler.version>
</properties>

<dependencies>
Expand Down
Expand Up @@ -82,16 +82,7 @@ public void commence(ServletRequest request, ServletResponse response, Authentic
rsp.setContentType("text/html;charset=UTF-8");
PrintWriter out;
try {
OutputStream sout = rsp.getOutputStream();
// if (rsp.containsHeader("Content-Encoding")) {
// // we serve Jelly pages with Content-Encoding:gzip.
// // ServletResponse doesn't provide means for us to check the value of the header,
// // to make the matter worse, GZIPOutputStream writes a header right away,
// // so by the time we get here we already have GZip header. Skip that part away by skipping first 10 bytes.
// // this is a hack.
// sout = new GZIPOutputStream(new ChopHeaderOutputStream(sout,10));
// }
out = new PrintWriter(new OutputStreamWriter(sout));
out = new PrintWriter(new OutputStreamWriter(rsp.getOutputStream()));
} catch (IllegalStateException e) {
out = rsp.getWriter();
}
Expand All @@ -110,32 +101,4 @@ public void commence(ServletRequest request, ServletResponse response, Authentic
out.close();
}
}

private static class ChopHeaderOutputStream extends FilterOutputStream {
private int count;

ChopHeaderOutputStream(OutputStream out, int count) {
super(out);
this.count = count;
}

@Override
public void write(byte[] b, int off, int len) throws IOException {
int i = Math.min(len,count);
count-=i;
off+=i;
len-=i;

if (len>0)
out.write(b, off, len);
}

@Override
public void write(int b) throws IOException {
if (count>0)
count--;
else
out.write(b);
}
}
}
7 changes: 7 additions & 0 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -2997,6 +2997,13 @@ public void doGc(StaplerResponse rsp) throws IOException {
rsp.getWriter().println("GCed");
}

/**
* End point that intentionally throws an exception to test the error behaviour.
*/
public void doException() {
throw new RuntimeException();
}

public ContextMenu doContextMenu(StaplerRequest request, StaplerResponse response) throws IOException, JellyException {
return new ContextMenu().from(this,request,response);
}
Expand Down
8 changes: 8 additions & 0 deletions war/src/main/webapp/WEB-INF/web.xml
Expand Up @@ -48,6 +48,10 @@ THE SOFTWARE.
<filter-name>encoding-filter</filter-name>
<filter-class>hudson.util.CharacterEncodingFilter</filter-class>
</filter>
<filter>
<filter-name>compression-filter</filter-name>
<filter-class>org.kohsuke.stapler.compression.CompressionFilter</filter-class>
</filter>
<filter>
<filter-name>authentication-filter</filter-name>
<filter-class>hudson.security.HudsonFilter</filter-class>
Expand Down Expand Up @@ -110,6 +114,10 @@ THE SOFTWARE.
<filter-name>encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>compression-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>authentication-filter</filter-name>
<url-pattern>/*</url-pattern>
Expand Down

0 comments on commit 18963ee

Please sign in to comment.