📄 request.pod
字号:
=head1 NAMEAPR::Request - wrapper for libapreq2's module/handle API.=begin testing use APR::Pool; use APR::Brigade; use APR::Bucket; use APR::BucketAlloc; use APR::Request; use APR::Request::Parser; $pool = APR::Pool->new; $ba = APR::BucketAlloc->new($pool); $bb = APR::Brigade->new($pool, $ba); $content = <<EOT;---XYZ-Content-Disposition: form-data; name="alpha"Content-Type: text/plain; charset=us-asciibody1---XYZ-Content-Disposition: form-data; name="beta" filename="foo.txt"Content-Type: text/plain; charset=us-asciibody2---XYZ-Content-Disposition: form-data; name="foo"Content-Type: text/plain; charset=us-asciibody3---XYZ---EOT s/(?<!\015)\012/\015\012/g for $content; $bb->insert_tail(APR::Bucket->new($ba, $content)); $parser = APR::Request::Parser->multipart($pool, $ba, "multipart/form-data; boundary=-XYZ-");=end testing=head1 SYNOPSIS=for example begin use APR::Request; $req = APR::Request::Custom->handle($pool, "foo=arg1&bar=arg2", "apache=quux", $parser, 1e6, $bb); $param = $req->param("foo"); $cookie = $req->jar("apache");=for example end=for example_testing ok $req->isa("APR::Request"); is $param, "arg1", "param"; is $cookie, "quux", "cookie";=head1 DESCRIPTIONThe C<< APR::Request >> module provides the base methodsfor interfacing with libapreq2's module API. It also providesa few utility functions and constants.This manpage documents version 2.08of the APR::Request, APR::Request::Custom,APR::Request::Cookie::Table, andAPR::Request::Param::Table packages.=head1 METHODSAPR::Request::Custom - derived from APR::Request.=head2 handle APR::Request::Custom->handle($pool, $query_string, $cookie_header, $parser, $read_limit, $brigade)Creates a new APR::Request::Custom object. The $query_stringand $cookie_headers are immediately parsed into the C<args> andC<jar> tables. The $parser is an APR::Request::Parser objectwhich is invoked when fetching C<body> entries from the $brigade.The $read_limit represents the maximum number of bytes this handlemay feed into the parser.=head1 METHODSAPR::Request=head2 pool $req->pool()Returns the APR::Pool object associated to this handle.=for example begin=for example end=for example_testing is ${$req->pool()}, $$pool, "pool";=head2 bucket_alloc $req->bucket_alloc()Returns the APR::BucketAlloc object associated to this handle.=for example begin=for example end=for example_testing is ${$req->bucket_alloc()}, $$ba, "bucket alloc";=head2 jar_status $req->jar_status()Returns the final status code of the handle's cookie header parser.=for example begin=for example end=for example_testing is $req->jar_status == 0, 1, "jar status";=head2 args_status $req->args_status()Returns the final status code of the handle's query-string parser.=for example begin=for example end=for example_testing is $req->args_status == 0, 1, "args status";=head2 body_status $req->body_status()Returns the final status code of the handle's body parser.=for example begin=for example end=for example_testing is $req->body_status == 0, 1, "body status";=head2 param_status $req->param_status()Returns C<< ($req->args_status, $req->body_status) >> in listcontext; otherwise returns C<< $req->args_status || $req->body_status >>.=for example begin=for example end=for example_testing is $req->param_status == 0, 1, "param status";=head2 parse $req->parse()Parses the jar, args, and body tables. ReturnsC<< $req->jar_status, $req->args_status, $req->body_status >>.=for example begin @status = $req->parse; ok @status == 3; ok $status[0] == $req->jar_status; ok $status[1] == $req->args_status; ok $status[2] == $req->body_status;=for example end=for example_testing $_ += 0 for @status; # convert to proper IVs is "@status", "0 0 0", "parse";=head2 jar $req->jar() $req->jar($key)With no arguments, this method returns a tied APR::Request::Cookie::Tableobject (or undef if the "Cookie" header is absent) in scalar context, or the names (in order, with repetitions) of all the parsed cookies.With the C<$key> argument, in scalar context this method fetches the firstmatching cookie. In list context it returns all matching cookies.The returned cookies are the values as they appeared in the incomingCookie header.jar() will throw an APR::Request::Error object whenever jar_status() is non-zero and the return value is potentially invalid (egC<< scalar $req->jar($key) >> will not die if the desired cookiewas successfully parsed).=for example begin $jar = $req->jar; @cookie_names = $req->jar; ok $jar->isa("APR::Request::Cookie::Table"); ok shift @cookie_names eq $_ for keys %$jar; $cookie = $req->jar("apache"); @cookies = $req->jar("apache");=for example end=for example_testing is $cookie, "quux", "cookie"; is "@cookies", "quux", "cookies";=head2 args $req->args() $req->args($key)With no arguments, this method returns a tied APR::Request::Param::Tableobject (or undef if the query string is absent) in scalar context, or the names (in order, with repetitions) of all the parsed query-string arguments.With the C<$key> argument, in scalar context this method fetches the firstmatching query-string arg. In list context it returns all matching args.args() will throw an APR::Request::Error object whenever args_status() is non-zero and the return value is potentially invalid (egC<< scalar $req->args($key) >> will not die if the desired query argumentwas successfully parsed).=for example begin $args = $req->args; @arg_names = $req->args; ok $args->isa("APR::Request::Param::Table"); ok shift @arg_names eq $_ for keys %$args; $foo = $req->args("foo"); @bar = $req->args("bar");=for example end=for example_testing is $foo, "arg1", "arg"; is "@bar", "arg2", "args";=head2 body $req->body() $req->body($key)With no arguments, this method returns a tied APR::Request::Param::Tableobject (or undef if the request body is absent) in scalar context, or the names (in order, with repetitions) of all the parsed cookies.With the C<$key> argument, in scalar context this method fetches the firstmatching body param. In list context it returns all matching body params.body() will throw an APR::Request::Error object whenever body_status() is non-zero and the return value is potentially invalid (eg C<< scalar $req->body($key) >> will not die if the desired body param wassuccessfully parsed).=for example begin $body = $req->body; @body_names = $req->body; ok $body->isa("APR::Request::Param::Table"); ok shift @body_names eq $_ for keys %$body; $alpha = $req->body("alpha"); @beta = $req->body("beta");=for example end=for example_testing is $alpha, "body1", "alpha body"; is "@beta", "foo.txt", "beta body";=head2 param $req->param() $req->param($key)With no arguments, this method returns a tied APR::Request::Param::Tableobject (or undef, if the query string and request body are absent) in scalarcontext, or the names (in order, with repetitions) of all the incoming(args + body) params.With the C<$key> argument, in scalar context this method fetches the firstmatching param. In list context it returns all matching params.param() will throw an APR::Request::Error object whenever param_status() is non-zero and the return value is potentially invalid (eg C<< scalar $req->param($key) >> will not die if the desired param was successfully parsed).=for example begin $param = $req->param; @param_names = $req->param; ok $param->isa("APR::Request::Param::Table"); ok shift @param_names eq $_ for keys %$param; $foo = $req->param("foo"); @foo = $req->param("foo");=for example end=for example_testing is $foo, "arg1", "scalar param"; is "@foo", "arg1 body3", "list param";
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -