sub
handler {
my
$r
=
shift
;
plan
$r
,
tests
=> 53;
my
$gr
= Apache->request;
ok
$$gr
==
$$r
;
my
$newr
= Apache::RequestRec->new(
$r
->connection,
$r
->pool);
Apache->request(
$newr
);
$gr
= Apache->request;
ok
$$gr
==
$$newr
;
Apache->request(
$r
);
ok
$r
->pool->isa(
'APR::Pool'
);
ok
$r
->connection->isa(
'Apache::Connection'
);
ok
$r
->server->isa(
'Apache::ServerRec'
);
for
(
qw(next prev main)
) {
ok (!
$r
->
$_
()) ||
$r
->
$_
()->isa(
'Apache::RequestRec'
);
}
ok !
$r
->assbackwards;
ok !
$r
->proxyreq;
ok !
$r
->header_only;
ok
$r
->protocol =~ /http/i;
ok t_cmp
$r
->proto_num, 1000,
't->proto_num'
;
ok t_cmp
$r
->hostname,
$r
->get_server_name,
'$r->hostname'
;
{
my
$old_hostname
=
$r
->hostname(
"other.hostname"
);
ok t_cmp
$r
->hostname,
"other.hostname"
,
'$r->hostname rw'
;
$r
->hostname(
$old_hostname
);
}
ok
$r
->request_time;
ok
$r
->status_line || 1;
ok
$r
->status || 1;
ok t_cmp
$r
->method,
'GET'
,
'$r->method'
;
ok t_cmp
$r
->method_number, Apache::M_GET,
'$r->method_number'
;
ok
$r
->headers_in;
ok
$r
->headers_out;
ok
$r
->err_headers_out;
ok
$r
->subprocess_env;
ok
$r
->notes;
ok
$r
->content_type;
ok
$r
->handler;
ok
$r
->ap_auth_type || 1;
ok
$r
->no_cache || 1;
ok !
$r
->no_local_copy;
{
local
$| = 0;
ok t_cmp
$r
->
print
(
"# buffered\n"
), 11,
"buffered print"
;
ok t_cmp
$r
->
print
(),
"0E0"
,
"buffered print"
;
local
$| = 1;
my
$string
=
"# not buffered\n"
;
ok t_cmp
$r
->
print
(
split
//,
$string
),
length
(
$string
),
"unbuffered print"
;
}
{
my
$args
=
"my_args=3"
;
my
$path_info
=
"/my_path_info"
;
my
$base_uri
=
"/TestAPI__request_rec"
;
ok t_cmp
$r
->unparsed_uri,
"$base_uri$path_info?$args"
;
ok t_cmp
$r
->uri,
"$base_uri$path_info"
,
'$r->uri'
;
ok t_cmp
$r
->path_info,
$path_info
,
'$r->path_info'
;
ok t_cmp
$r
->args,
$args
,
'$r->args'
;
ok t_cmp
$r
->the_request,
"GET $base_uri$path_info?$args HTTP/1.0"
,
'$r->the_request'
;
ok
$r
->filename;
my
$location
=
'/'
. Apache::TestRequest::module2path(__PACKAGE__);
ok t_cmp
$r
->location,
$location
,
'$r->location'
;
}
{
$r
->rflush;
my
$sent
=
$r
->bytes_sent;
t_debug
"sent so far: $sent bytes"
;
ok
$sent
> 100;
}
{
my
$mtime
= (
stat
__FILE__)[9];
$r
->mtime(
$mtime
);
ok t_cmp
$r
->mtime,
$mtime
,
"mtime"
;
}
{
my
$finfo
= APR::Finfo::
stat
(__FILE__, APR::FINFO_NORM,
$r
->pool);
$r
->finfo(
$finfo
);
ok t_cmp(
$r
->finfo->fname,
__FILE__,
'$r->finfo'
);
}
{
$r
->allowed(1 << Apache::M_GET);
ok
$r
->allowed & (1 << Apache::M_GET);
ok ! (
$r
->allowed & (1 << Apache::M_PUT));
$r
->allowed(
$r
->allowed | (1 << Apache::M_PUT));
ok
$r
->allowed & (1 << Apache::M_PUT);
}
{
my
$def
= [
qw(fr)
];
my
$l
= [
qw(fr us cn)
];
ok t_cmp
$r
->content_languages,
$def
,
'$r->content_languages'
;
ok t_cmp
$r
->content_languages(
$l
),
$def
,
'$r->content_languages'
;
ok t_cmp
$r
->content_languages,
$l
,
'$r->content_languages'
;
eval
{
$r
->content_languages({}) };
ok t_cmp $@,
qr/Not an array reference/
,
'$r->content_languages(invalid)'
;
}
{
my
$r
=
bless
{},
"Apache::RequestRec"
;
my
$err
=
q[method `uri' invoked by a `Apache::RequestRec' ]
.
q[object with no `r' key!]
;
eval
{
$r
->uri };
ok t_cmp $@,
qr/$err/
,
"invalid $r object"
;
}
{
my
$r
=
bless
{},
"NonExisting"
;
my
$err
=
q[method `uri' invoked by a `NonExisting' ]
.
q[object with no `r' key!]
;
eval
{ Apache::RequestRec::uri(
$r
) };
ok t_cmp $@,
qr/$err/
,
"invalid $r object"
;
}
{
my
$r
= {};
my
$err
=
q[method `uri' invoked by a `unknown' ]
.
q[object with no `r' key!]
;
eval
{ Apache::RequestRec::uri(
$r
) };
ok t_cmp $@,
qr/$err/
,
"invalid $r object"
;
}
Apache::OK;
}
1;