]> source.dussan.org Git - vaadin-framework.git/commitdiff
Redirect if no ending slash in context root request (#9921) 94/94/1
authorLeif Åstrand <leif@vaadin.com>
Tue, 9 Oct 2012 16:05:47 +0000 (19:05 +0300)
committerLeif Åstrand <leif@vaadin.com>
Tue, 9 Oct 2012 16:05:47 +0000 (19:05 +0300)
Change-Id: Ief3f2c339a962230607df2e3e17dea93fcfb4f2e

server/src/com/vaadin/server/VaadinServlet.java

index 7673c2d2f78f29ba772b1a8e7b75049612e0bf2a..13ea68f2524daa1990e7d4f67e748a58b0771de3 100644 (file)
@@ -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 {