diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-10-09 19:05:47 +0300 |
---|---|---|
committer | Leif Åstrand <leif@vaadin.com> | 2012-10-09 19:05:47 +0300 |
commit | fcd9b4773e13d7ffe5b0871525775e38759da0cc (patch) | |
tree | 2260f4b2cffbffd2bf68081bbc3c89d4285951c3 /server | |
parent | d693378d9350934aebbf3b3562c1132fbbbd7a64 (diff) | |
download | vaadin-framework-fcd9b4773e13d7ffe5b0871525775e38759da0cc.tar.gz vaadin-framework-fcd9b4773e13d7ffe5b0871525775e38759da0cc.zip |
Redirect if no ending slash in context root request (#9921)
Change-Id: Ief3f2c339a962230607df2e3e17dea93fcfb4f2e
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/server/VaadinServlet.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 7673c2d2f7..13ea68f252 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -206,11 +206,36 @@ public class VaadinServlet extends HttpServlet implements Constants { @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + /* + * Some servlet containers cause problems with requests to the context + * root without any ending slash - ensure we avoid such problems by + * redirecting to an ending slash in these cases. See #9921 + */ + if (handleContextRootWithoutSlash(request, response)) { + return; + } CurrentInstance.clearAll(); setCurrent(this); service(createVaadinRequest(request), createVaadinResponse(response)); } + private boolean handleContextRootWithoutSlash(HttpServletRequest request, + HttpServletResponse response) { + if ("/".equals(request.getPathInfo()) + && "".equals(request.getServletPath()) + && !request.getRequestURI().endsWith("/")) { + /* + * Path info is for the root but request URI doesn't end with a + * slash -> redirect to the same URI but with an ending slash. + */ + response.setStatus(HttpServletResponse.SC_FOUND); + response.setHeader("Location", request.getRequestURI() + "/"); + return true; + } else { + return false; + } + } + private void service(VaadinServletRequest request, VaadinServletResponse response) throws ServletException, IOException { |