Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=39396
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 9 Feb 2009 20:13:14 +0000 (20:13 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Mon, 9 Feb 2009 20:13:14 +0000 (20:13 +0000)
Exclude TRACE in OPTIONS response by default. Include it where we know it is enabled.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@742714 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/RequestFacade.java
java/org/apache/catalina/servlets/DefaultServlet.java

index 8f4383f..2f929fb 100644 (file)
@@ -994,4 +994,7 @@ public class RequestFacade implements HttpServletRequest {
         return null;
     }
 
+    public boolean getAllowTrace() {
+        return request.getConnector().getAllowTrace();
+    }
 }
index acb97d7..cf6a93f 100644 (file)
@@ -56,6 +56,7 @@ import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.stream.StreamSource;
 
 import org.apache.catalina.Globals;
+import org.apache.catalina.connector.RequestFacade;
 import org.apache.catalina.util.RequestUtil;
 import org.apache.catalina.util.ServerInfo;
 import org.apache.catalina.util.StringManager;
@@ -77,8 +78,7 @@ import org.apache.naming.resources.ResourceAttributes;
 
 public class DefaultServlet
     extends HttpServlet {
-
-
+    
     // ----------------------------------------------------- Instance Variables
 
 
@@ -355,6 +355,49 @@ public class DefaultServlet
 
 
     /**
+     * Override default implementation to ensure that TRACE is correctly
+     * handled.
+     *
+     * @param req   the {@link HttpServletRequest} object that
+     *                  contains the request the client made of
+     *                  the servlet
+     *
+     * @param resp  the {@link HttpServletResponse} object that
+     *                  contains the response the servlet returns
+     *                  to the client                                
+     *
+     * @exception IOException   if an input or output error occurs
+     *                              while the servlet is handling the
+     *                              OPTIONS request
+     *
+     * @exception ServletException  if the request for the
+     *                                  OPTIONS cannot be handled
+     */
+    protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
+        throws ServletException, IOException {
+
+        StringBuffer allow = new StringBuffer();
+        // There is a doGet method
+        allow.append("GET, HEAD");
+        // There is a doPost
+        allow.append(", POST");
+        // There is a doPut
+        allow.append(", PUT");
+        // There is a doDelete
+        allow.append(", POST");
+        // Trace - assume disabled unless we can prove otherwise
+        if (req instanceof RequestFacade &&
+                ((RequestFacade) req).getAllowTrace()) {
+            allow.append(", TRACE");
+        }
+        // Always allow options
+        allow.append(", OPTIONS");
+        
+        resp.setHeader("Allow", allow.toString());
+    }
+    
+    
+    /**
      * Process a POST request for the specified resource.
      *
      * @param request The servlet request we are processing