199d031999-09-05Francesco Chemolli /* * by Francesco Chemolli
9284272000-03-17Martin Nilsson  * This is a roxen module. Copyright © 1999 - 2000, Roxen IS.
199d031999-09-05Francesco Chemolli  * * Notice: this might look ugly, it's been designed to be split into * a "library" program plus a tiny imlpementation module */
64dd112000-05-15Francesco Chemolli constant cvs_version="$Id: throttling_bytype.pike,v 1.8 2000/05/15 20:05:41 kinkie Exp $";
199d031999-09-05Francesco Chemolli  #include <module.h>
cdc2981999-09-29Francesco Chemolli inherit "throttlelib"; string filter_type="(by type)";
a87ab42000-05-06Francesco Chemolli string rules_doc= #"Throttling rules. One rule per line, whose format is:<br> <tt>type-glob modifier [fix]</tt><br> <tt>type-glob</tt> is matched on the Content Type header. (i.e. <tt>image/gif</tt> or <tt>text/html</tt>).<p> <i>modifier</i> is the altering rule. There are six possible rule types:<br> <tt>+{number}</tt> adds <i>number</i> bytes/sec to the request<br> <tt>-{number}</tt> subtracts <i>number</i> bytes/sec to the request<br> <tt>*{number}</tt> multiplies the bandwidth assigned to the request by <i>number</i> (a floating-point number)<br> <tt>/{number}</tt> divides the bandwidth assigned to the request by <i>number</i> (a floating-point number)<br> <tt>={number}</tt> assigns the request <i>number</i> bytes/sec of bandwidth<br> <tt>nothrottle</tt> asserts that the request is not to be throttled. It implies using <tt>fix</tt>.<p> The optional keyword <tt>fix</tt> will make the assigned bandwidth final. The entries are scanned in order, and processing is stopped as soon as a match is found.<p> Lines starting with <tt>#</tt> are considered comments.";
199d031999-09-05Francesco Chemolli  #ifdef THROTTLING_DEBUG #undef THROTTLING_DEBUG
b3ef2d1999-12-18Martin Nilsson #define THROTTLING_DEBUG(X) werror("Throttling: "+X+"\n")
199d031999-09-05Francesco Chemolli #else #define THROTTLING_DEBUG(X) #endif
ad959c2000-02-12Martin Nilsson constant module_type = MODULE_FILTER; constant module_name = "Throttling: throttle by type"; constant module_doc = "This module will alter the throttling definitions by content type";
64dd112000-05-15Francesco Chemolli constant module_unique = 1;
199d031999-09-05Francesco Chemolli 
cdc2981999-09-29Francesco Chemolli array find_rule (mapping res, object id, array(string) rulenames, mapping rules) {
199d031999-09-05Francesco Chemolli  if (!res) return 0;
cdc2981999-09-29Francesco Chemolli  return low_find_rule(res->type, rulenames, rules);
199d031999-09-05Francesco Chemolli }