@@ -18,6 +18,7 @@ public class GrailsContentBufferingResponse extends HttpServletResponseWrapper {
1818 private final GrailsPageResponseWrapper pageResponseWrapper ;
1919 private final ContentProcessor contentProcessor ;
2020 private final SiteMeshWebAppContext webAppContext ;
21+ private boolean redirectCalled ;
2122
2223 public GrailsContentBufferingResponse (HttpServletResponse response , final ContentProcessor contentProcessor , final SiteMeshWebAppContext webAppContext ) {
2324 super (new GrailsPageResponseWrapper (webAppContext .getRequest (), response , new PageParserSelector () {
@@ -65,19 +66,30 @@ public Content getContent() throws IOException {
6566
6667 public void sendError (int sc ) throws IOException {
6768 GrailsWebRequest webRequest = WebUtils .retrieveGrailsWebRequest ();
69+
6870 try {
69- super .sendError (sc );
70- } finally {
71+ if (!redirectCalled && !isCommitted ())
72+ super .sendError (sc );
73+ }
74+ finally {
7175 WebUtils .storeGrailsWebRequest (webRequest );
7276 }
7377 }
7478
7579 public void sendError (int sc , String msg ) throws IOException {
7680 GrailsWebRequest webRequest = WebUtils .retrieveGrailsWebRequest ();
7781 try {
78- super .sendError (sc , msg );
79- } finally {
82+ if (!redirectCalled && !isCommitted ())
83+ super .sendError (sc , msg );
84+ }
85+ finally {
8086 WebUtils .storeGrailsWebRequest (webRequest );
8187 }
8288 }
89+
90+ @ Override
91+ public void sendRedirect (String location ) throws IOException {
92+ this .redirectCalled = true ;
93+ super .sendRedirect (location );
94+ }
8395}
0 commit comments