Apacheのモジュール内で、要求されたファイルに対するmimeタイプが決まるのはどこか?
基本的に、mimeタイプは type_checkerフィーズできまる。
そのmimeタイプを決めているのが、mod_mimeであり、mod_mimeでは、
AddType や、TypesConfigなどで指定したmime typeを拡張子を基に判断している。
static void register_hooks(apr_pool_t *p)
{
ap_hook_post_config(mime_post_config,NULL,NULL,APR_HOOK_MIDDLE);
ap_hook_type_checker(find_ct,NULL,NULL,APR_HOOK_MIDDLE);
/*
* this hook seems redundant ... is there any reason a type checker isn't
* allowed to do this already? I'd think that fixups in general would be
* the last opportunity to get the filters right.
* ap_hook_insert_filter(mime_insert_filters,NULL,NULL,APR_HOOK_MIDDLE);
*/
}
そしてfind_ctの中で、ap_set_content_typeを使って決定されたmime typeを設定している。
modules/http/http_protocol.c
にある、ap_set_content_typeは、以下のようになっている。
AP_DECLARE(void) ap_set_content_type(request_rec *r, const char *ct)
{
if (!ct) {
r->content_type = NULL;
}
else if (!r->content_type || strcmp(r->content_type, ct)) {
r->content_type = ct;
/* Insert filters requested by the AddOutputFiltersByType
* configuration directive. Content-type filters must be
* inserted after the content handlers have run because
* only then, do we reliably know the content-type.
*/
ap_add_output_filters_by_type(r);
}
}
従って、type_checkerの後のフェーズである。fixupsフェーズであれば、
r->content_type
から、要求したファイルに対するmime typeが取得できる。
もちろん、ここでファイルに対するcontent_typeなので、プログラムで出力した結果のcontent-typeは何も反映しない。
AddType text/html .php
とやっていれば、phpの拡張子の場合にはこの時点では
text/html
という訳だ。


