From 8bf7c9cef87d4d7423cdd7a0522c82894f57b344 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Sun, 5 Feb 2023 09:18:24 +1100 Subject: [PATCH] Fix #9285 use possibly wrapper response for redirection (#9286) Use the servlet response sendRedirect method. Always close the connection if there is content. Signed-off-by: Greg Wilkins --- .../eclipse/jetty/server/handler/ContextHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index 9af02651968..1b872f2faf5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -61,6 +61,8 @@ import javax.servlet.http.HttpSessionAttributeListener; import javax.servlet.http.HttpSessionIdListener; import javax.servlet.http.HttpSessionListener; +import org.eclipse.jetty.http.HttpHeader; +import org.eclipse.jetty.http.HttpHeaderValue; import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.http.MimeTypes; import org.eclipse.jetty.server.AllowedResourceAliasChecker; @@ -1213,10 +1215,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu // context request must end with / baseRequest.setHandled(true); String queryString = baseRequest.getQueryString(); - baseRequest.getResponse().sendRedirect( - HttpServletResponse.SC_MOVED_TEMPORARILY, - baseRequest.getRequestURI() + (queryString == null ? "/" : ("/?" + queryString)), - true); + // If there is request content, close the connection rather than try to consume it. + if (baseRequest.getContentType() != null || baseRequest.getContentLengthLong() > 0) + response.setHeader(HttpHeader.CONNECTION.asString(), HttpHeaderValue.CLOSE.asString()); + response.sendRedirect(baseRequest.getRequestURI() + (queryString == null ? "/" : ("/?" + queryString))); return false; }