Permalink
Browse files

[FIXED JENKINS-13625]

In the end, proper fix requires having a filter that tracks
GZipOutputStream.
  • Loading branch information...
kohsuke committed May 24, 2012
1 parent ecec590 commit 18963ee9af2b98ce94eda799069d9135f6031a0e
@@ -42,7 +42,7 @@ THE SOFTWARE.

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

<dependencies>
@@ -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();
}
@@ -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);
}
}
}
@@ -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);
}
@@ -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>
@@ -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>

0 comments on commit 18963ee

Please sign in to comment.