f41b982009-05-07Martin Stjernholm // This is a roxen module. Copyright © 2000 - 2009, Roxen IS.
d69ba52001-09-03Martin Nilsson 
83735f2000-07-20Johan Sundström inherit "module"; // All roxen modules must inherit module.pike
0917d32013-03-04Anders Johansson constant cvs_version = "$Id$";
0420032022-11-04Henrik Grubbström (Grubba) constant module_type = MODULE_FILTER|MODULE_EXPERIMENTAL;
83735f2000-07-20Johan Sundström constant module_name = "RefDoc for MODULE_FILTER"; constant module_doc = "This module does nothing, but its inlined " "documentation gets imported into the roxen " "programmer manual. You hardly want to add " "this module to your virtual servers."; mapping last_seen; int handled; int seen; mapping|void filter(mapping|void result, RequestID id)
cd202d2001-08-31Henrik Grubbström (Grubba) //! The @[filter()] method is called for all files just before the
83735f2000-07-20Johan Sundström //! final resulting page is sent back to the browser. In effect, filter //! modules are essentially MODULE_LAST modules that get called for all //! requests, not only failed requests. The result parameter is either a //! zero (for an unhandled request) or a standard <ref>result //! mapping</ref>, as returned by any previous modules in the server. //! The id argument, as usual, is the request information object //! associated with the request. //! //! The returned value is either zero, here signifying that you didn't //! rewrite or in any way alter the result mapping, or a new or changed //! result mapping. //! //! Since all data server by your virtual server gets passed your //! filter module(s), you typically need to make sure your filter //! module doesn't interfere with such requests it wasn't intended to //! touch, or you may end up with some pretty hard to find problems. { seen++; last_seen = result;
9158562008-12-17Jonas Wallden  string|array(string) type = result->type; if (arrayp(type)) type = type[0];
83735f2000-07-20Johan Sundström  if(!result // If nobody had anything to say, neither do we. || !stringp(result->data) // Got a file descriptor. Hardly ever happens anyway. || !id->prestate->filterpass // No prestate, no action for this module.
9158562008-12-17Jonas Wallden  || !glob("text/*", type) // Only touch content types we're interested in.
83735f2000-07-20Johan Sundström  ) return 0; handled++; result->data = sprintf("%O", result); result->type = "text/plain"; // When we're still mangling the request. :-) return result; } string status() { return sprintf("Received <b>%d</b> requests, of which <b>%d</b> were " "touched by the module. Last seen request's result " "mapping: <pre>%s</pre>", seen, handled, Roxen.html_encode_string(sprintf("%O", last_seen))); }