Chinaunix首页 | 论坛 | 博客
  • 博客访问: 175476
  • 博文数量: 37
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 256
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-06 23:02
文章分类

全部博文(37)

分类: LINUX

2015-11-30 10:26:37

过滤器(filter)
A filter is a process that is applied to data that is sent or received by the server. Data sent by clients to the server is processed by input filters while data sent by the server to the client is processed by output filters. Multiple filters can be applied to the data, and the order of the filters can be explicitly specified.
过滤器用来对 server 收到/发送的数据进行再加工。过滤器分两种:input filters 用于处理 server 从 client 收到的数据,output filters 用于处理 server 向 client 发送的数据。一个数据流上可以挂多个过滤器。这些过滤器可以通过显式指定来确定执行顺序。

Filters are used internally by Apache to perform functions such as chunking and byte-range request handling. In addition, modules can provide filters that are selectable using run-time configuration directives. The set of filters that apply to data can be manipulated with the SetInputFilter, SetOutputFilter, AddInputFilter, AddOutputFilter, RemoveInputFilter, and RemoveOutputFilter directives.

数据的输入和输出:

过滤器所加工的数据,存储在一种称为 桶 bucket 的容器中。 bucket 的实际存储可以是 文件\管道(pipe)\流(socket stream )堆内存(heap)甚至是栈内存(stack)。apache 提供了apr_bucket_read 方法,将 bucket 中的数据读取到用户指定的内存中。apchet 也提供了数据在不同类型的 bucket 之间传递的的手段。除了常规的 apr_bucket_copy 外,还提供了 



过滤器可以通过 conf 中 配置的指令来决定 过滤器用于哪些数据。apache filter 官方文档介绍了 。 主要的可分为两类:

1、强制过滤器(SetInputFilter, SetOutputFilter)。例如,在输出 http页面时,强制在每个页面加入页底的版权信息。

2、选择性过滤器。分为按扩展名过滤(AddHandler),按MIME类型过滤(AddInputFilter)

3、过滤器内部参数过滤。例如下面介绍的 CaseFilter。


过滤器的注册和使用:

过滤器使用 ap_register_output_filter 进行注册。并通过 ap_add_output_filter 来唤醒调用。

Filters currently register using

ap_register_output_filter(name, filter_func, filter_init, ftype)

and are inserted using

ap_add_output_filter(name, ctx, req, conn)

关于 以上两个api的用法, 在其文章   中做了详细解释。

阅读(2240) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~