diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java index f42e59df..16f69c25 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowController.java @@ -104,6 +104,21 @@ public class FlowController implements Controller, ApplicationContextAware, Init flowHandlerAdapter.setAjaxHandler(ajaxHandler); } + /** + * Set whether redirects sent by this controller should be compatible with HTTP 1.0 clients. + *
+ * By default, this will enforce a redirect HTTP status code of 302 by delegating to
+ * HttpServletResponse.sendRedirect. Setting this to false will send HTTP status code 303, which is
+ * the correct code for HTTP 1.1 clients, but not understood by HTTP 1.0 clients.
+ *
+ * Many HTTP 1.1 clients treat 302 just like 303, not making any difference. However, some clients depend on 303 + * when redirecting after a POST request; turn this flag off in such a scenario. + * @see javax.servlet.http.HttpServletResponse#sendRedirect + */ + public void setRedirectHttp10Compatible(boolean redirectHttp10Compatible) { + flowHandlerAdapter.setRedirectHttp10Compatible(redirectHttp10Compatible); + } + /** * Sets the custom flow handles for managing the access to flows in a custom manner. * @param flowHandlers the flow handler map diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java index 09ea5896..fa103b91 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/servlet/FlowHandlerAdapter.java @@ -74,6 +74,8 @@ public class FlowHandlerAdapter extends WebContentGenerator implements HandlerAd */ private AjaxHandler ajaxHandler; + private boolean redirectHttp10Compatible = true; + /** * Creates a new flow handler adapter. * @see #setFlowExecutor(FlowExecutor) @@ -131,6 +133,21 @@ public class FlowHandlerAdapter extends WebContentGenerator implements HandlerAd this.ajaxHandler = ajaxHandler; } + /** + * Set whether redirects sent by this handler adapter should be compatible with HTTP 1.0 clients. + *
+ * By default, this will enforce a redirect HTTP status code of 302 by delegating to
+ * HttpServletResponse.sendRedirect. Setting this to false will send HTTP status code 303, which is
+ * the correct code for HTTP 1.1 clients, but not understood by HTTP 1.0 clients.
+ *
+ * Many HTTP 1.1 clients treat 302 just like 303, not making any difference. However, some clients depend on 303 + * when redirecting after a POST request; turn this flag off in such a scenario. + * @see javax.servlet.http.HttpServletResponse#sendRedirect + */ + public void setRedirectHttp10Compatible(boolean redirectHttp10Compatible) { + this.redirectHttp10Compatible = redirectHttp10Compatible; + } + public void afterPropertiesSet() throws Exception { Assert.notNull(flowExecutor, "The FlowExecutor to execute flows is required"); if (flowUrlHandler == null) { @@ -369,7 +386,14 @@ public class FlowHandlerAdapter extends WebContentGenerator implements HandlerAd if (ajaxHandler.isAjaxRequest(request, response)) { ajaxHandler.sendAjaxRedirect(url, request, response, false); } else { - response.sendRedirect(response.encodeRedirectURL(url)); + if (redirectHttp10Compatible) { + // Always send status code 302. + response.sendRedirect(response.encodeRedirectURL(url)); + } else { + // Correct HTTP status code is 303, in particular for POST requests. + response.setStatus(303); + response.setHeader("Location", response.encodeRedirectURL(url)); + } } }