Permalink
Browse files

Merge changes Ic2b78ba9,Ia13e63ed

* changes:
  Use '406 Not Acceptable' when info/refs is disabled
  Compress large /info/refs responses on HTTP
  • Loading branch information...
2 parents c3f1fac + b3e8f29 commit eb5b506acdd22c3e5d97d9b3efaf978659ef07f4 @spearce spearce committed with Gerrit Code Review @ Eclipse.org Sep 22, 2012
@@ -225,7 +225,7 @@ public void init(FilterConfig filterConfig) throws ServletException {
refs = refs.through(new AsIsFileFilter(asIs));
refs.with(new InfoRefsServlet());
} else
- refs.with(new ErrorServlet(HttpServletResponse.SC_FORBIDDEN));
+ refs.with(new ErrorServlet(HttpServletResponse.SC_NOT_ACCEPTABLE));
if (asIs != AsIsFileService.DISABLED) {
final IsLocalFilter mustBeLocal = new IsLocalFilter();
@@ -72,7 +72,8 @@ public void doGet(final HttpServletRequest req,
final Repository db = getRepository(req);
final OutputStreamWriter out = new OutputStreamWriter(
- new SmartOutputStream(req, rsp), Constants.CHARSET);
+ new SmartOutputStream(req, rsp, true),
+ Constants.CHARSET);
final RefAdvertiser adv = new RefAdvertiser() {
@Override
protected void writeOne(final CharSequence line) throws IOException {
@@ -171,7 +171,7 @@ public void doPost(final HttpServletRequest req,
return;
}
- SmartOutputStream out = new SmartOutputStream(req, rsp) {
+ SmartOutputStream out = new SmartOutputStream(req, rsp, true) {
@Override
public void flush() throws IOException {
doFlush();
@@ -70,22 +70,29 @@
private static final int LIMIT = 32 * 1024;
private final HttpServletRequest req;
-
private final HttpServletResponse rsp;
-
+ private boolean compressStream;
private boolean startedOutput;
SmartOutputStream(final HttpServletRequest req,
- final HttpServletResponse rsp) {
+ final HttpServletResponse rsp,
+ boolean compressStream) {
super(LIMIT);
this.req = req;
this.rsp = rsp;
+ this.compressStream = compressStream;
}
@Override
protected OutputStream overflow() throws IOException {
startedOutput = true;
- return rsp.getOutputStream();
+
+ OutputStream out = rsp.getOutputStream();
+ if (compressStream && acceptsGzipEncoding(req)) {
+ rsp.setHeader(HDR_CONTENT_ENCODING, ENCODING_GZIP);
+ out = new GZIPOutputStream(out);
+ }
+ return out;
}
public void close() throws IOException {
@@ -122,7 +122,7 @@ private void service(ServletRequest request, ServletResponse response)
throws IOException {
final HttpServletRequest req = (HttpServletRequest) request;
final HttpServletResponse res = (HttpServletResponse) response;
- final SmartOutputStream buf = new SmartOutputStream(req, res);
+ final SmartOutputStream buf = new SmartOutputStream(req, res, true);
try {
res.setContentType(infoRefsResultType(svc));
@@ -172,7 +172,7 @@ public void doPost(final HttpServletRequest req,
return;
}
- SmartOutputStream out = new SmartOutputStream(req, rsp) {
+ SmartOutputStream out = new SmartOutputStream(req, rsp, false) {
@Override
public void flush() throws IOException {
doFlush();

0 comments on commit eb5b506

Please sign in to comment.