Commits

Anonymous committed 2bbc136

Started to split filters (not finished yet).
Also need to re-write handleRequest and document which info is available in cpg.request and cpg.response and when

Comments (0)

Files changed (5)

         cpg.request.method = 'GET'
         _cphttptools.parseFirstLine(self.raw_requestline)
         self.cook_headers()
-        _cphttptools.applyFilterList('afterRequestHeader')
-        _cphttptools.applyFilterList('afterRequestBody')
+        # TODO _cphttptools.applyFilterList('afterRequestHeader')
+        # TODO _cphttptools.applyFilterList('afterRequestBody')
         _cphttptools.doRequest(self.wfile)
 
     def do_HEAD(self): # Head is not implemented
         self.cook_headers()
         cpg.request.parsePostData = 1
         cpg.request.rfile = self.rfile
-        _cphttptools.applyFilterList('afterRequestHeader')
+        # TODO _cphttptools.applyFilterList('afterRequestHeader')
         if cpg.request.parsePostData:
             _cphttptools.parsePostData(self.rfile)
-        _cphttptools.applyFilterList('afterRequestBody')
+        # TODO _cphttptools.applyFilterList('afterRequestBody')
         _cphttptools.doRequest(self.wfile)
 
     def setup(self):
 def applyFilterList(methodName):
     filterList = _cputil.getSpecialFunction('_cpFilterList')
     for filter in filterList:
-        method = getattr(filter, methodName)
-        method()
+        method = getattr(filter, methodName, None)
+        if method:
+            method()
 
 def insertIntoHeaderMap(key,value):
     normalizedKey = '-'.join([s.capitalize() for s in key.split('-')])
     cpg.request.browserUrl = cpg.request.base + cpg.request.browserUrl
     cpg.request.isStatic = 0
 
+    # TODO: Temp hack ... These filters shouldn't be here and remi
+    # needs to rewrite this code ...
+    applyFilterList('afterRequestHeader')
+    applyFilterList('afterRequestBody')
+
     # Clean up expired sessions if needed:
     if cpg.configOption.sessionStorageType and cpg.configOption.sessionCleanUpDelay and cpg._lastSessionCleanUpTime + cpg.configOption.sessionCleanUpDelay * 60 <= now:
         cpg._lastSessionCleanUpTime = now

lib/filter/basefilter.py

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 """
 
-class BaseFilter(object):
+class BaseInputFilter(object):
     """
-    Base class for filters. Derive new filter classes from this, then
+    Base class for input filters. Derive new filter classes from this, then
     override some of the methods to add some side-effects.
     """
-
     def afterRequestHeader(self):
         """ Called after the request header has been read/parsed"""
         pass
         """ Called after the request body has been read/parsed"""
         pass
 
-
+class BaseOutputFilter(object):
+    """
+    Base class for output filters. Derive new filter classes from this, then
+    override some of the methods to add some side-effects.
+    """
     def beforeResponse(self):
         """ Called before starting to write response """
         pass

lib/filter/baseurlfilter.py

+"""
+Copyright (c) 2004, CherryPy Team (team@cherrypy.org)
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+    * Neither the name of the CherryPy Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+"""
+
+from basefilter import BaseInputFilter
+from cherrypy import cpg
+
+class BaseUrlFilter(BaseInputFilter):
+    """
+    Filter that changes the base URL.
+    Useful when running a CP server behind Apache.
+    """
+
+    def __init__(self, baseUrl = 'http://localhost'):
+        # New baseUrl
+        self.baseUrl = baseUrl
+
+    def afterRequestHeader(self):
+        cpg.request.browserUrl = cpg.request.browserUrl.replace(
+            cpg.request.base, self.baseUrl)
+        cpg.request.base = self.baseUrl

lib/filter/tidyfilter.py

 """
 
 import os, cgi
-from basefilter import BaseFilter
+from basefilter import BaseOutputFilter
 from cherrypy import cpg
 
-class TidyFilter(BaseFilter):
+class TidyFilter(BaseOutputFilter):
     """
     Filter that runs the response through Tidy.
     Note that we use the standalone Tidy tool rather than the python
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.