From: James Moger Date: Thu, 4 Sep 2014 17:04:20 +0000 (-0400) Subject: Do not stamp raw servlet responses with cache-control headers X-Git-Tag: v1.6.1~57^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=818973b2baece0ff3245de10091f5ca8bdffebc6;p=gitblit.git Do not stamp raw servlet responses with cache-control headers --- diff --git a/src/main/java/com/gitblit/servlet/PagesServlet.java b/src/main/java/com/gitblit/servlet/PagesServlet.java index f578f86f..a8e83418 100644 --- a/src/main/java/com/gitblit/servlet/PagesServlet.java +++ b/src/main/java/com/gitblit/servlet/PagesServlet.java @@ -15,10 +15,19 @@ */ package com.gitblit.servlet; +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; + +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevCommit; + import com.gitblit.Constants; +import com.gitblit.utils.JGitUtils; /** * Serves the content of a gh-pages branch. @@ -73,4 +82,22 @@ public class PagesServlet extends RawServlet { protected void setContentType(HttpServletResponse response, String contentType) { response.setContentType(contentType);; } + + @Override + protected void streamFromRepo(HttpServletResponse response, Repository repository, + RevCommit commit, String requestedPath) throws IOException { + + response.setDateHeader("Last-Modified", JGitUtils.getCommitDate(commit).getTime()); + response.setHeader("Cache-Control", "public, max-age=3600, must-revalidate"); + + super.streamFromRepo(response, repository, commit, requestedPath); + } + + @Override + protected void sendContent(HttpServletResponse response, Date date, InputStream is) throws ServletException, IOException { + response.setDateHeader("Last-Modified", date.getTime()); + response.setHeader("Cache-Control", "public, max-age=3600, must-revalidate"); + + super.sendContent(response, date, is); + } } diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index a9e58202..30d33fd7 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -421,12 +421,9 @@ public class RawServlet extends DaggerServlet { } } - private void streamFromRepo(HttpServletResponse response, Repository repository, + protected void streamFromRepo(HttpServletResponse response, Repository repository, RevCommit commit, String requestedPath) throws IOException { - response.setDateHeader("Last-Modified", JGitUtils.getCommitDate(commit).getTime()); - response.setHeader("Cache-Control", "public, max-age=3600, must-revalidate"); - RevWalk rw = new RevWalk(repository); TreeWalk tw = new TreeWalk(repository); try { @@ -457,9 +454,8 @@ public class RawServlet extends DaggerServlet { response.flushBuffer(); } - private void sendContent(HttpServletResponse response, Date date, InputStream is) throws ServletException, IOException { - response.setDateHeader("Last-Modified", date.getTime()); - response.setHeader("Cache-Control", "public, max-age=3600, must-revalidate"); + protected void sendContent(HttpServletResponse response, Date date, InputStream is) throws ServletException, IOException { + try { byte[] tmp = new byte[8192]; int len = 0;