leaving the record of attempted gzip encoding problem fix.

This commit is contained in:
Kohsuke Kawaguchi committed 2012-05-23 20:08:57 -07:00
1 parent be1f8f91a3
commit ecec5902ff
1 file changed
+39 -7
@@ -33,6 +33,8 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static javax.servlet.http.HttpServletResponse.SC_FORBIDDEN;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@@ -81,12 +83,14 @@ public class HudsonAuthenticationEntryPoint extends AuthenticationProcessingFilt
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,
// so this is a hack.
sout = new GZIPOutputStream(sout);
}
// 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));
} catch (IllegalStateException e) {
out = rsp.getWriter();
@@ -103,7 +107,35 @@ public class HudsonAuthenticationEntryPoint extends AuthenticationProcessingFilt
// See http://support.microsoft.com/kb/294807
for (int i=0; i < 10; i++)
out.print(" ");
out.flush();
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);
}
}
}