roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r451053 - /incubator/roller/trunk/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java
Date Thu, 28 Sep 2006 23:24:06 GMT
Author: agilliland
Date: Thu Sep 28 16:24:04 2006
New Revision: 451053

URL: http://svn.apache.org/viewvc?view=rev&rev=451053
Log:
fix for trailing slash issue with weblog urls.  we now consider all weblog urls that end with
a "/" to be invalid and get a 404, except for the weblog index pages.  we also allow the weblog
index pages to work without a trailing slash and then redirect them to the version with the
trailing slash for consistency.
 

Modified:
    incubator/roller/trunk/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java

Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java?view=diff&rev=451053&r1=451052&r2=451053
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/WeblogRequestMapper.java Thu
Sep 28 16:24:04 2006
@@ -89,6 +89,10 @@
     public boolean handleRequest(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {
         
+        // kinda silly, but we need to keep track of whether or not the url had
+        // a trailing slash so that we can act accordingly
+        boolean trailingSlash = false;
+        
         String weblogHandle = null;
         String weblogLocale = null;
         String weblogRequestContext = null;
@@ -107,6 +111,7 @@
             // strip off trailing slash if needed
             if(servlet.endsWith("/")) {
                 servlet = servlet.substring(0, servlet.length() - 1);
+                trailingSlash = true;
             }
             
             if(servlet.indexOf("/") != -1) {
@@ -165,6 +170,29 @@
                 }
             }
             
+        }
+        
+        // special handling for trailing slash issue
+        // we need this because by http standards the urls /foo and /foo/ are
+        // supposed to be considered different, so we must enforce that
+        if(weblogRequestContext == null && !trailingSlash) {
+            // this means someone referred to a weblog index page with the 
+            // shortest form of url /<weblog> or /<weblog>/<locale> and
we need
+            // to do a redirect to /<weblog>/ or /<weblog>/<locale>/
+            String redirectUrl = request.getRequestURI() + "/";
+            if(request.getQueryString() != null) {
+                redirectUrl += "?"+request.getQueryString();
+            }
+            
+            response.sendRedirect(redirectUrl);
+            return true;
+            
+        } else if(weblogRequestContext != null && trailingSlash) {
+            // this means that someone has accessed a weblog url and included
+            // a trailing slash, like /<weblog>/entry/<anchor>/ which is not
+            // supported, so we need to offer up a 404 Not Found
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return true;
         }
         
         // calculate forward url



Mime
View raw message