From 2d8e3b9850677a4337c6c6b74318132e9d30502d Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 7 Oct 2011 22:00:06 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51952 Make inclusion of a response body for redirects optional as it may cause issues and is only SHOULD in RFC2616. See also https://issues.apache.org/bugzilla/show_bug.cgi?id=41718 git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1180261 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/Context.java | 12 ++++++++++++ java/org/apache/catalina/connector/Response.java | 10 ++++++---- java/org/apache/catalina/core/StandardContext.java | 14 ++++++++++++++ webapps/docs/config/context.xml | 8 ++++++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/java/org/apache/catalina/Context.java b/java/org/apache/catalina/Context.java index 1a4e124b1..a448b0769 100644 --- a/java/org/apache/catalina/Context.java +++ b/java/org/apache/catalina/Context.java @@ -1391,5 +1391,17 @@ public interface Context extends Container { * resource. */ public boolean getPreemptiveAuthentication(); + + /** + * Configures if a response body is included when a redirect response is + * sent to the client. + */ + public void setSendRedirectBody(boolean enable); + + /** + * Dtermines if the context is configured to included a response body as + * part of a redirect response. + */ + public boolean getSendRedirectBody(); } diff --git a/java/org/apache/catalina/connector/Response.java b/java/org/apache/catalina/connector/Response.java index c1c726fd5..1878d6462 100644 --- a/java/org/apache/catalina/connector/Response.java +++ b/java/org/apache/catalina/connector/Response.java @@ -1335,10 +1335,12 @@ public class Response String absolute = toAbsolute(location); setStatus(SC_FOUND); setHeader("Location", absolute); - PrintWriter writer = getWriter(); - writer.print(sm.getString("coyoteResponse.sendRedirect.note", - RequestUtil.filter(absolute))); - flushBuffer(); + if (getContext().getSendRedirectBody()) { + PrintWriter writer = getWriter(); + writer.print(sm.getString("coyoteResponse.sendRedirect.note", + RequestUtil.filter(absolute))); + flushBuffer(); + } } catch (IllegalArgumentException e) { setStatus(SC_NOT_FOUND); } diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index e115380de..a408da0c2 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -859,7 +859,21 @@ public class StandardContext extends ContainerBase private boolean preemptiveAuthentication = false; + private boolean sendRedirectBody = false; + + // ----------------------------------------------------- Context Properties + + @Override + public boolean getSendRedirectBody() { + return sendRedirectBody; + } + + + @Override + public void setSendRedirectBody(boolean sendRedirectBody) { + this.sendRedirectBody = sendRedirectBody; + } @Override diff --git a/webapps/docs/config/context.xml b/webapps/docs/config/context.xml index 4be9ac2a1..e363d8bde 100644 --- a/webapps/docs/config/context.xml +++ b/webapps/docs/config/context.xml @@ -365,6 +365,14 @@ string, else the default value will be jsp.

+ +

If true, redirect responses will include a short + response body that includes details of the redirect as recommended by + RFC 2616. This is disabled by default since including a response body + may cause problems for some application component such as compression + filters.

+
+

The domain to be used for all session cookies created for this context. If set, this overrides any domain set by the web application. -- 2.11.0