[perl]改变文档请求对象的三种方法
时间:2007-02-06 来源:zhangjunxia
当我们在对/url/1发起请求的时候,如果希望Apache以/url/2响应,有如下三种实现方式。
1. 第一种(使用内部重定向)
sub handler {
my $r = shift;
....
$r->internal_redirect("/url/2");
return OK;
}
Unfortunately internal_redirect() returns no result code, so there's no way of knowing whether the redirect was successful.
2.第二种(使用外部重定向)
sub handler {
my $r = shift;
....
$r->header_out(Location => "/url/2");
return REDIRECT;
}
3. 第三种(发起子请求)
sub handler {
my $r = shift;
....
my $sub_r = $r->lookup_uri("/url/2");
$r->content_type($sub_r->content_type);
$r->send_http_header;
$sub_r->run;
return OK;
}