この文書は、2010/02/18 時点のmod_filter - Apache HTTP Serverをkoshigoeが私的に翻訳したものです。訳の正確さは保証できませんし、無条件に信用すべきでもありません。
<-
Apache > HTTP Server > Documentation > Version 2.2 > Modules

Apache Module mod_filter

Available Languages:  en 

Description:Context-sensitive smart filter configuration module
Status:Base
Module Identifier:filter_module
Source File:mod_filter.c
Compatibility:Version 2.1 and later

Summary

This module enables smart, context-sensitive configuration of output content filters. For example, apache can be configured to process different content-types through different filters, even when the content-type is not known in advance (e.g. in a proxy).

このモジュールはスマートでコンテキスト・センシティブな出力コンテント・フィルタの設定を可能にします。 例えば、前もって content-type がわからない時でも、異なる content-type を異なるフィルタに通して処理する様に設定できます(例:プロキシ)。

mod_filter works by introducing indirection into the filter chain. Instead of inserting filters in the chain, we insert a filter harness which in turn dispatches conditionally to a filter provider. Any content filter may be used as a provider to mod_filter; no change to existing filter modules is required (although it may be possible to simplify them).

mod_filter はフィルタ・チェインに回り道を差し込む事によって作用します。 チェインの中にフィルタを差し込む代わりに、条件付きでフィルタ・プロバイダを順に割り当てるフィルタ・ハーネスを差し込みます。 コンテント・フィルタは mod_filter にプロバイダとして使われるかもしれません; 既存フィルタ・モジュールへの変更は不要です(たとえそれらを単純にする事が可能だとしても)。

Directives

Topics

top

Smart Filtering

In the traditional filtering model, filters are inserted unconditionally using AddOutputFilter and family. Each filter then needs to determine whether to run, and there is little flexibility available for server admins to allow the chain to be configured dynamically.

古いフィルタリング・モデルでは、AddOutputFilter ファミリを使うことで、フィルタが無条件に差し込まれてしまいます。 その後で各フィルタを実行するか決定する必要があり、サーバ管理者がチェインを動的に設計するための柔軟性がほとんどありません。

mod_filter by contrast gives server administrators a great deal of flexibility in configuring the filter chain. In fact, filters can be inserted based on any Request Header, Response Header or Environment Variable. This generalises the limited flexibility offered by AddOutputFilterByType, and fixes it to work correctly with dynamic content, regardless of the content generator. The ability to dispatch based on Environment Variables offers the full flexibility of configuration with mod_rewrite to anyone who needs it.

mod_filter はそれに比べて、サーバ管理者にフィルタ・チェインの設計における大変大きな柔軟性を与えます。 実際、フィルタはいかなるリクエストヘッダ/レスポンスヘッダ/環境変数を元にして、差し込むことが出来ます。 このことは、AddOutputFilterByType によってもたらされる限定された柔軟性を一般化し、コンテント・ジェネレータにかかわらず動的コンテントで正確に働くよう修正します。 環境変数ベースでディスパッチ出来る能力は、??mod_rewrite の様な??、設計の完全な柔軟性を提供します。
top

Filter Declarations, Providers and Chains

[This image displays the traditional filter model]
Figure 1: The traditional filter model

In the traditional model, output filters are a simple chain from the content generator (handler) to the client. This works well provided the filter chain can be correctly configured, but presents problems when the filters need to be configured dynamically based on the outcome of the handler.

古いモデルでは、出力フィルタはコンテント・ジェネレータ(ハンドラ)からクライアントへの単純なチェインです。 正しく設定されただろうフィルタチェインをうまく提供できましたが、フィルタがハンドラの結果に基づいた動的に設計される必要があるときに問題をひきおこしました。

[This image shows the mod_filter model]
Figure 2: The mod_filter model

mod_filter works by introducing indirection into the filter chain. Instead of inserting filters in the chain, we insert a filter harness which in turn dispatches conditionally to a filter provider. Any content filter may be used as a provider to mod_filter; no change to existing filter modules is required (although it may be possible to simplify them). There can be multiple providers for one filter, but no more than one provider will run for any single request.

mod_filter はフィルタ・チェインに回り道を差し込む事によって作用します。 チェインの中にフィルタを差し込む代わりに、条件付きでフィルタ・プロバイダを順に割り当てるフィルタ・ハーネスを差し込みます。 コンテント・フィルタは mod_filter にプロバイダとして使われるかもしれません; 既存フィルタ・モジュールへの変更は不要です(たとえそれらを単純にする事が可能だとしても)。 一つのフィルタに複数のプロバイダをつけられますが、一つのリクエストに一つのプロバイダだけが実行されるでしょう。

A filter chain comprises any number of instances of the filter harness, each of which may have any number of providers. A special case is that of a single provider with unconditional dispatch: this is equivalent to inserting the provider filter directly into the chain.

フィルタ・チェインは、それぞれ数限りないプロバイダを持つ数限りないフィルタ・ハーネスのインスタンスから構成されます。 特別なケースに無条件に割り当てられる一つのプロバイダがあります: これは、チェインに直接プロバイダフィルタを差し込む事と等価です。
top

Configuring the Chain

There are three stages to configuring a filter chain with mod_filter. For details of the directives, see below.

Declare Filters
The FilterDeclare directive declares a filter, assigning it a name and filter type. Required only if the filter is not the default type AP_FTYPE_RESOURCE.
FilterDeclare ディレクティブはフィルタを宣言し、名前とフィルタ・タイプを割り当てます。 フィルタが標準タイプの AP_FTYPE_RESOURCE でない場合のみ必須です。
Register Providers
The FilterProvider directive registers a provider with a filter. The filter may have been declared with FilterDeclare; if not, FilterProvider will implicitly declare it with the default type AP_FTYPE_RESOURCE. The provider must have been registered with ap_register_output_filter by some module. The remaining arguments to FilterProvider are a dispatch criterion and a match string. The former may be an HTTP request or response header, an environment variable, or the Handler used by this request. The latter is matched to it for each request, to determine whether this provider will be used to implement the filter for this request.
FilterProvider ディレクティブはフィルタにプロバイダを登録します。 フィルタは FilterDeclare によって宣言されているかもしれません; もしそうでないなら、FilterProvider は標準タイプの AP_FTYPE_RESOURCE として宣言します。 プロバイダはいくつかのモジュールによって ap_register_output_filter で登録されていなければなりません。 FilterProvider の残りの引数はディスパッチの基準とマッチ文字列です。 前者は HTTP リクエストかレスポンスヘッダ、もしくは環境変数、またはこのリクエストによって使われるハンドラです。 後者は、各リクエストについて、マッチするかどうかで、そのリクエストに対してフィルタを実行するために、このプロバイダが使われるかどうかを判断します。
Configure the Chain
The above directives build components of a smart filter chain, but do not configure it to run. The FilterChain directive builds a filter chain from smart filters declared, offering the flexibility to insert filters at the beginning or end of the chain, remove a filter, or clear the chain.
前述のディレクティブ達はスマート・フィルタ・チェインのコンポーネントを組み立てますが、それを実行するための設定ではありません。 FilterChain ディレクティブは宣言されたスマート・フィルタからフィルタ・チェインを組み立て、チェインの最初か最後にフィルタ達を差し込むんだり、削除したり、チェインを消し去ったりするための柔軟性を提供します。
top

Examples

Server side Includes (SSI)
A simple case of using mod_filter in place of AddOutputFilterByType
AddOutputFilterByType の代わりに mod_filter を利用する単純なケース。

FilterDeclare SSI
FilterProvider SSI INCLUDES resp=Content-Type $text/html
FilterChain SSI

Server side Includes (SSI)
The same as the above but dispatching on handler (classic SSI behaviour; .shtml files get processed).
上記と同じながら、ハンドラによるディスパッチです(伝統的な SSI の振る舞い; .shtml ファイルが処理されます)

FilterProvider SSI INCLUDES Handler server-parsed
FilterChain SSI

Emulating mod_gzip with mod_deflate
Insert INFLATE filter only if "gzip" is NOT in the Accept-Encoding header. This filter runs with ftype CONTENT_SET.
Accept-Encoding に "gzip" が含まれない場合のみ INFLATE フィルタを差し込みます。

FilterDeclare gzip CONTENT_SET
FilterProvider gzip inflate req=Accept-Encoding !$gzip
FilterChain gzip

Image Downsampling
Suppose we want to downsample all web images, and have filters for GIF, JPEG and PNG.
画像をダウンサンプルしたいなら。

FilterProvider unpack jpeg_unpack Content-Type $image/jpeg
FilterProvider unpack gif_unpack Content-Type $image/gif
FilterProvider unpack png_unpack Content-Type $image/png

FilterProvider downsample downsample_filter Content-Type $image
FilterProtocol downsample "change=yes"

FilterProvider repack jpeg_pack Content-Type $image/jpeg
FilterProvider repack gif_pack Content-Type $image/gif
FilterProvider repack png_pack Content-Type $image/png
<Location /image-filter>
FilterChain unpack downsample repack
</Location>

top

Protocol Handling

Historically, each filter is responsible for ensuring that whatever changes it makes are correctly represented in the HTTP response headers, and that it does not run when it would make an illegal change. This imposes a burden on filter authors to re-implement some common functionality in every filter:

歴史的経緯から、フィルタは、どんな変更であっても HTTP レスポンスヘッダの中に正しく表現される様、確実に責任を持たなければならず、不正な変化をもたらす場合は実行しません。 このことは、フィルタ作者にすべてのフィルタにおける共通の機能要件を再実装する負担を課します:

mod_filter aims to offer generic handling of these details of filter implementation, reducing the complexity required of content filter modules. This is work-in-progress; the FilterProtocol implements some of this functionality for back-compatibility with Apache 2.0 modules. For httpd 2.1 and later, the ap_register_output_filter_protocol and ap_filter_protocol API enables filter modules to declare their own behaviour.

mod_filter フィルタ実行の詳細に関する一般的なハンドリングの提供し、コンテント・フィルタ・モジュールへの複雑な要求を減らします。 これは開発中(work-in-progress)です; FilterProtocol は Apache 2.0 モジュールとの後方互換性のためにこの機能要件のいくつかをみたします。 httpd 2.1 以降については、ap_register_output_filter_protocol と ap_filter_protocol という API で、フィルタ・モジュールのそれら自身の振る舞いを宣言できます。

At the same time, mod_filter should not interfere with a filter that wants to handle all aspects of the protocol. By default (i.e. in the absence of any FilterProtocol directives), mod_filter will leave the headers untouched.

同時に、mod_filter はフィルタがプロトコルのすべての面を扱う事を妨げるべきではありません。 標準で(i.e. FilterProtocol ディレクティブがない場合)、mod_filter はヘッダに触れません。

At the time of writing, this feature is largely untested, as modules in common use are designed to work with 2.0. Modules using it should test it carefully.

これを書いているとき、この特徴は2.0 で動作するために設計された共用のモジュールとしては十分検証されていません。 モジュールは注意深くテストすべきです。
top

FilterChain Directive

Description:Configure the filter chain
Syntax:FilterChain [+=-@!]filter-name ...
Context:server config, virtual host, directory, .htaccess
Override:Options
Status:Base
Module:mod_filter

This configures an actual filter chain, from declared filters. FilterChain takes any number of arguments, each optionally preceded with a single-character control that determines what to do:

宣言済みのフィルタによるフィルタチェインを設定します。 FilterChain は任意個の引数をとります。各引数には、任意で以下のような動作を制御する頭文字をつけられます。
+filter-name
Add filter-name to the end of the filter chain
filter-name をフィルタ・チェインの末尾に追加します。
@filter-name
Insert filter-name at the start of the filter chain
filter-name をフィルタ・チェインの先頭に追加します。
-filter-name
Remove filter-name from the filter chain
filter-name をフィルタ・チェインから取り除きます。
=filter-name
Empty the filter chain and insert filter-name フィルタ・チェインを空にし、filter-name を追加します。
!
Empty the filter chain
フィルタ・チェインを空にします。
filter-name
Equivalent to +filter-name
+filter-name と同じです。
top

FilterDeclare Directive

Description:Declare a smart filter
Syntax:FilterDeclare filter-name [type]
Context:server config, virtual host, directory, .htaccess
Override:Options
Status:Base
Module:mod_filter

This directive declares an output filter together with a header or environment variable that will determine runtime configuration. The first argument is a filter-name for use in FilterProvider, FilterChain and FilterProtocol directives.

このディレクティブは実行する時を決めるためのヘッダか環境変数と一緒に出力フィルタを宣言します。 最初の引数は FilterProviderFilterChainFilterProtocol ディレクティブで使うための filter-name です。

The final (optional) argument is the type of filter, and takes values of ap_filter_type - namely RESOURCE (the default), CONTENT_SET, PROTOCOL, TRANSCODE, CONNECTION or NETWORK.

最後の任意の引数はフィルタのタイプで、RESOURCE (デフォルト)、CONTENT_SETPROTOCOLTRANSCODECONNECTIONNETWORK と名付けられている ap_filter_type の値をとります。
top

FilterProtocol Directive

Description:Deal with correct HTTP protocol handling
Syntax:FilterProtocol filter-name [provider-name] proto-flags
Context:server config, virtual host, directory, .htaccess
Override:Options
Status:Base
Module:mod_filter

This directs mod_filter to deal with ensuring the filter doesn't run when it shouldn't, and that the HTTP response headers are correctly set taking into account the effects of the filter.

これは、フィルタを実行すべきでないときに確実に実行しないようにしたり、フィルタの効果を考慮して HTTP レスポンスヘッダを正確にセットしたりする様に、mod_filter が振る舞うようにします。

There are two forms of this directive. With three arguments, it applies specifically to a filter-name and a provider-name for that filter. With two arguments it applies to a filter-name whenever the filter runs any provider.

このディレクティブには二つの形式があります。 三つの引数があるなら、filter-name というフィルタに対して provider-name を割り当てます。 二つの引数があるなら、filter-name というフィルタはいかなるプロバイダであっても実行します。

proto-flags is one or more of

change=yes
The filter changes the content, including possibly the content length
そのフィルタはコンテントを変え、コンテントの長さを変えるかもしれません。
change=1:1
The filter changes the content, but will not change the content length
フィルタは長さを変えずにコンテントを変化させます。
byteranges=no
The filter cannot work on byteranges and requires complete input
フィルタはバイト範囲に働きかけられず、完全な入力を要求します。
proxy=no
The filter should not run in a proxy context
フィルタは proxy コンテントについて実行すべきでありません。
proxy=transform
The filter transforms the response in a manner incompatible with the HTTP Cache-Control: no-transform header.
フィルタは Cache-Control: no-transform ヘッダと互換性がないやり方でレスポンスを変形します。
cache=no
The filter renders the output uncacheable (eg by introducing randomised content changes)
フィルタはキャッシュしない出力を描画します(eg ランダムなコンテントの変化など)
top

FilterProvider Directive

Description:Register a content filter
Syntax:FilterProvider filter-name provider-name [req|resp|env]=dispatch match
Context:server config, virtual host, directory, .htaccess
Override:Options
Status:Base
Module:mod_filter

This directive registers a provider for the smart filter. The provider will be called if and only if the match declared here matches the value of the header or environment variable declared as dispatch.

このディレクティブはスマート・フィルタのプロバイダをを登録します。 プロバイダはここで宣言された matchdispatch として宣言されたヘッダか環境変数の値がマッチしたときに呼ばれます。

provider-name must have been registered by loading a module that registers the name with ap_register_output_filter.

provider-nameap_register_output_filter で名前を登録するモジュールのロードによって登録されていなければなりません。

The dispatch argument is a string with optional req=, resp= or env= prefix causing it to dispatch on (respectively) the request header, response header, or environment variable named. In the absence of a prefix, it defaults to a response header. A special case is the word handler, which causes mod_filter to dispatch on the content handler.

dispatch 引数は req=resp=env= といった、それぞれリクエスト、レスポンス、環境変数を意味するプレフィックスを任意で持つ文字列です。 プレフィックスを省略した場合、デフォルトでレスポンスヘッダとなります。 特例は、mod_filter をコンテント・ハンドラでディスパッチするようにする??? handler という語です。

The match argument specifies a match that will be applied to the filter's dispatch criterion. The match may be a string match (exact match or substring), a regex, an integer (greater, lessthan or equals), or unconditional. The first characters of the match argument determines this:

match 引数はフィルタの dispatch 基準に当てはまる事のマッチを指定します。 match は文字列マッチ(完全一致か部分文字列)、正規表現、整数(大なり、小なり、等価)、無条件のいずれかで行います。 match 引数の最初の文字はこのように決めます:

First, if the first character is an exclamation mark (!), this reverses the rule, so the provider will be used if and only if the match fails.

はじめに、最初の文字が ! なら、これは否定となり、プロバイダはマッチに失敗した場合のみ使われます。

Second, it interprets the first character excluding any leading ! as follows:

次に、! 以外はの先頭文字は以下のように解釈します:
CharacterDescription
(none)exact match - 完全一致
$substring match - 部分一致
/regex match (delimited by a second /) - 正規表現(二つ目の / で分割される)
=integer equality - 整数の等価
<integer less-than 整数の小なり
<=integer less-than or equal - 整数の小なりイコール
>integer greater-than - 整数の大なり
>=integer greater-than or equal - 整数の大なりイコール
*Unconditional match - 無条件でマッチする???
top

FilterTrace Directive

Description:Get debug/diagnostic information from mod_filter
Syntax:FilterTrace filter-name level
Context:server config, virtual host, directory
Status:Base
Module:mod_filter

This directive generates debug information from mod_filter. It is designed to help test and debug providers (filter modules), although it may also help with mod_filter itself.

このディレクティブは mod_filter からデバッグ情報を生成します。 プロバイダ(フィルタモジュール)のテストとデバッグの手助けのために設計されていますが、mod_filter 自身のためにも役立ちます。

The debug output depends on the level set:

デバッグ出力は level によります:
0 (default)
No debug information is generated.
デバッグ情報を生成しません。
1
mod_filter will record buckets and brigades passing through the filter to the error log, before the provider has processed them. This is similar to the information generated by mod_diagnostics.
mod_filter はプロバイダの処理前にエラーログにフィルタを通してバケットとグループを記録します???。 これは mod_diagnostics ににています。
2 (not yet implemented)
Will dump the full data passing through to a tempfile before the provider. For single-user debug only; this will not support concurrent hits.
(未実装)

Available Languages:  en