Skip to content

Commit

Permalink
Fix #9285 use possibly wrapper response for redirection (#9286)
Browse files Browse the repository at this point in the history
Use the servlet response sendRedirect method.
Always close the connection if there is content.

Signed-off-by: Greg Wilkins <gregw@webtide.com>
  • Loading branch information
gregw committed Feb 4, 2023
1 parent 016de2f commit 8bf7c9c
Showing 1 changed file with 6 additions and 4 deletions.
Expand Up @@ -61,6 +61,8 @@
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;
Expand Down Expand Up @@ -1213,10 +1215,10 @@ public boolean checkContext(final String target, final Request baseRequest, fina
// 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;
}

Expand Down

0 comments on commit 8bf7c9c

Please sign in to comment.