Commits

Anonymous committed 8425212

Changed page WhatsNewIn21

Comments (0)

Files changed (1)

WhatsNewIn21.wiki

 }}}
 
 
+= Changes to Filters =
 
- 3. Changes to [wiki:Filters21 filters]
-    * [wiki:StdFilterBaseUrl Base URL filter]
-    * [wiki:StdFilterCache Cache filter]
-    * [wiki:StdFilterDecoding Decoding filter]
-    * [wiki:StdFilterEncoding Encoding filter]
-    * [wiki:StdFilterGzip Gzip filter]
-    * [wiki:StdFilterLogDebug Log debug filter]
-    * [wiki:StdFilterNsgml Nsgml filter]
-    * [wiki:StdFilterSessionAuthenticate Session authenticate filter]
-    * [wiki:StdFilterStatic Static filter]
-    * [wiki:StdFilterTidy Tidy filter]
-    * [wiki:StdFilterVirtualHost Virtual Host filter]
-    * [wiki:StdFilterXmlRpc XML-RPC filter]
- 4. Changes to [wiki:Sessions21 sessions]
+== New way of using filters ==
+
+It is now much easier to use standard filters. No more _cpFilterList is required (although you still have to use it if you want to use some non-standard filter).
+Standard filters are now included in 2 internal lists called _cpDefaultInputFilterList and _cpDefaultOutputFilterList.
+All you have to do is enable them through the config file.
+For instance, if you want to enable EncodingFilter (using utf-8) on all the site and DecodingFilter for everything under /dir1 (using latin-1), all you have to do is put this in your config file:
+
+{{{
+[/]
+encodingFilter.on = True
+
+[/dir1]
+decodingFilter.on = True
+decodingFilter.encoding = "latin-1"
+}}}
+
+The "standard" filters are currently: baseurlfilter, cachefilter, decodingfilter, encodingfilter, gzipfilter, logdebuginfofilter, staticfilter, tidyfilter, virtualhostfilter, xmlrpcfilter
+
+It is also possible to add your own filters like this (since rev 522, you must use [global], not [/]):
+
+Note: Be careful when using that feature that might change before 2.1 stable is out. Either way, if you do use the feature below, let us know how it goes so that we know how to improve it.
+
+{{{
+[global]
+#specify where to look for filters
+server.filtersRoot = ['.', 'my/filters']
+
+# defines what filters to load for working on the incoming request
+# the key is the Python module name without the .py extension
+# the value is the classname within that module
+server.inputFiltersDict = {'myFilter': 'MyFilterClassIn'}
+server.outputFiltersDict = {'myFilter': 'MyFilterClassOut'}
+
+[/dir1]
+# Now we can work on our filter as with the standard filters
+myFilter.on = True
+myFilter.saySome = ' world'
+
+[/dir2]
+myFilter.on = False
+}}}
+
+From within your filter classes, you will have to call for instance:
+
+{{{
+cherrypy.config.get('myFilter.on', False)
+cherrypy.config.get('myFilter.saySome', '')
+}}}
+
+{{{
+#!html
+<div class="highlighted">
+}}}
+
+'''Steps to upgrade your site'''
+
+If you're using some of these default filters in your code, you can remove them from _cpFilterList and just enable them through the config file.
+
+{{{
+#!html
+</div>
+}}}
+
+
+== Filter changes for developers ==
+
+Since the core was rewritten to use iterators, some of the filter method names are obsolete, and have been replaced. In addition, the filters are no longer divided into separate input and output classes; each core filter is now implemented with a single class per filter.
+
+{{{
+#!html
+<div class="highlighted">
+<a name="filter_methods"></a>
+}}}
+'''Steps to upgrade your site'''
+
+If you have custom filters, you should collapse your classes, and then change the method names (or your code will not be called). In general, you can follow this mapping from old to new names:
+
+||'''Old Name'''||'''New Name'''||
+||no equivalent||onStartResource||
+||setConfig, afterRequestHeader||beforeRequestBody||
+||afterRequestBody||beforeMain||
+||beforeResponse||beforeFinalize||
+||afterResponse||onEndResource||
+||beforeErrorResponse|| no change ||
+||afterErrorResponse|| no change ||
+
+{{{
+#!html
+</div>
+}}}
+
+Also, be aware that !CherryPy 2.1 no longer uses wfile to write output to the client. Instead, you should append output strings to cherrypy.response.body.
+
+
+= New session system =
+
+== New session filter ==
+
+Sessions have been moved into a filter called "sessionFilter". Sessions are enabled by setting "sessionFilter.on" to True.  This gives you access to a dictionary-like object called "cherrypy.session". See the [http://www.cherrypy.org/trunk/docs/book/chunk/ch03.html#id2940947 Session chapter] of the !CherryPy book for more information about the session system.
+
+{{{
+#!html
+<div class="highlighted">
+}}}
+'''Steps to upgrade your site'''
+
+You may need to update your config (covered [wiki:ConfigSystem21 here]).
+You also need to change any references of "cpg.request.sessionMap" to "cherrypy.session".
+
+{{{
+#!html
+</div>
+}}}
+
+
  5. Changes to [wiki:StaticContent21 static content]
  6. New [wiki:ServerEnvironment "server.environment" modes]
  7. New [wiki:FileUpload21 file upload behavior]