apache::testrequest.3

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· 3 代码 · 共 693 行 · 第 1/2 页

3
693
字号
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings.  \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote.  \*(C+ will.\" give a nicer C++.  Capital omega is used to do unbreakable dashes and.\" therefore won't be available.  \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\.    ds -- \(*W-.    ds PI pi.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch.    ds L" "".    ds R" "".    ds C` "".    ds C' ""'br\}.el\{\.    ds -- \|\(em\|.    ds PI \(*p.    ds L" ``.    ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el       .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD.  Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\.    de IX.    tm Index:\\$1\t\\n%\t"\\$2"...    nr % 0.    rr F.\}.el \{\.    de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear.  Run.  Save yourself.  No user-serviceable parts..    \" fudge factors for nroff and troff.if n \{\.    ds #H 0.    ds #V .8m.    ds #F .3m.    ds #[ \f1.    ds #] \fP.\}.if t \{\.    ds #H ((1u-(\\\\n(.fu%2u))*.13m).    ds #V .6m.    ds #F 0.    ds #[ \&.    ds #] \&.\}.    \" simple accents for nroff and troff.if n \{\.    ds ' \&.    ds ` \&.    ds ^ \&.    ds , \&.    ds ~ ~.    ds /.\}.if t \{\.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u".    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}.    \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E.    \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'.    \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\.    ds : e.    ds 8 ss.    ds o a.    ds d- d\h'-1'\(ga.    ds D- D\h'-1'\(hy.    ds th \o'bp'.    ds Th \o'LP'.    ds ae ae.    ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "Apache::TestRequest 3".TH Apache::TestRequest 3 "2005-10-21" "perl v5.10.0" "User Contributed Perl Documentation".\" For nroff, turn off justification.  Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"Apache::TestRequest \- Send requests to your Apache test server.SH "SYNOPSIS".IX Header "SYNOPSIS".Vb 3\&  use Apache::Test qw(ok have_lwp);\&  use Apache::TestRequest qw(GET POST);\&  use Apache::Constants qw(HTTP_OK);\&\&  plan tests => 1, have_lwp;\&\&  my $res = GET \*(Aq/test.html\*(Aq;\&  ok $res\->code == HTTP_OK, "Request is ok";.Ve.SH "DESCRIPTION".IX Header "DESCRIPTION"\&\fBApache::TestRequest\fR provides convenience functions to allow you tomake requests to your Apache test server in your test scripts. Itsubclasses \f(CW\*(C`LWP::UserAgent\*(C'\fR, so that you have access to all if itsmethods, but also exports a number of useful functions likely usefulfor majority of your test requests. Users of the old \f(CW\*(C`Apache::test\*(C'\fR(or \f(CW\*(C`Apache::testold\*(C'\fR) module, take note! Herein lie most of thefunctions you'll need to use to replace \f(CW\*(C`Apache::test\*(C'\fR in your testsuites..PPEach of the functions exported by \f(CW\*(C`Apache::TestRequest\*(C'\fR uses an\&\f(CW\*(C`LWP::UserAgent\*(C'\fR object to submit the request and retrieve itsresults. The return value for many of these functions is anHTTP::Response object. See HTTP::Response fordocumentation of its methods, which you can use in your tests. Forexample, use the \f(CW\*(C`code()\*(C'\fR and \f(CW\*(C`content()\*(C'\fR methods to test theresponse code and content of your request. Using \f(CW\*(C`GET\*(C'\fR, you canperform a couple of tests using these methods like this:.PP.Vb 3\&  use Apache::Test qw(ok have_lwp);\&  use Apache::TestRequest qw(GET POST);\&  use Apache::Constants qw(HTTP_OK);\&\&  plan tests => 2, have_lwp;\&\&  my $uri = "/test.html?foo=1&bar=2";\&  my $res = GET $uri;\&  ok $res\->code == HTTP_OK, "Check that the request was OK";\&  ok $res\->content eq "foo => 1, bar => 2", "Check its content";.Ve.PPNote that you can also use \f(CW\*(C`Apache::TestRequest\*(C'\fR with\&\f(CW\*(C`Test::Builder\*(C'\fR and its derivatives, including \f(CW\*(C`Test::More\*(C'\fR:.PP.Vb 4\&  use Test::More;\&  # ...\&  is $res\->code, HTTP_OK, "Check that the request was OK";\&  is $res\->content, "foo => 1, bar => 2", "Check its content";.Ve.SH "CONFIGURATION FUNCTION".IX Header "CONFIGURATION FUNCTION"You can tell \f(CW\*(C`Apache::TestRequest\*(C'\fR what kind of \f(CW\*(C`LWP::UserAgent\*(C'\fRobject to use for its convenience functions with \f(CW\*(C`user_agent()\*(C'\fR. Thisfunction uses its arguments to construct an internal global\&\f(CW\*(C`LWP::UserAgent\*(C'\fR object that will be used for all subsequent requestsmade by the convenience functions. The arguments it takes are the sameas for the \f(CW\*(C`LWP::UserAgent\*(C'\fR constructor. See the\&\f(CW\*(C`LWP::UserAgent\*(C'\fR documentation for a complete list..PPThe \f(CW\*(C`user_agent()\*(C'\fR function only creates the internal\&\f(CW\*(C`LWP::UserAgent\*(C'\fR object the first time it is called. Since thisfunction is called internally by \f(CW\*(C`Apache::TestRequest\*(C'\fR, you shouldalways use the \f(CW\*(C`reset\*(C'\fR parameter to force it to create a new global\&\f(CW\*(C`LWP::UserAgent\*(C'\fR Object:.PP.Vb 1\&  Apache::TestRequest::user_agent(reset => 1, %params);.Ve.PP\&\f(CW\*(C`user_agent()\*(C'\fR differs from \f(CW\*(C`LWP::UserAgent\->new\*(C'\fR in twoadditional ways. First, it supports an additional parameter,\&\f(CW\*(C`keep_alive\*(C'\fR, which enables connection persistence, where the sameconnection is used to process multiple requests (and, according to the\&\f(CW\*(C`LWP::UserAgent\*(C'\fR documentation, has the effect ofloading and enabling the new experimental \s-1HTTP/1\s0.1 protocol module)..PPAnd finally, the semantics of the \f(CW\*(C`requests_redirectable\*(C'\fR parameter isdifferent than for \f(CW\*(C`LWP::UserAgent\*(C'\fR in that you can pass it a booleanvalue as well as an array for \f(CW\*(C`LWP::UserAgent\*(C'\fR. To force\&\f(CW\*(C`Apache::TestRequest\*(C'\fR not to follow redirects in any of its conveniencefunctions, pass a false value to \f(CW\*(C`requests_redirectable\*(C'\fR:.PP.Vb 2\&  Apache::TestRequest::user_agent(reset => 1,\&                                  requests_redirectable => 0);.Ve.PPIf \s-1LWP\s0 is not installed, then you can still pass in an array referenceas \f(CW\*(C`LWP::UserAgent\*(C'\fR expects. \f(CW\*(C`Apache::TestRequest\*(C'\fR will examine thearray and allow redirects if the array contains more than one value orif there is only one value and that value is not \*(L"\s-1POST\s0\*(R":.PP.Vb 4\&  # Always allow redirection.\&  my $redir = have_lwp() ? [qw(GET HEAD POST)] : 1;\&  Apache::TestRequest::user_agent(reset => 1,\&                                  requests_redirectable => $redir);.Ve.PPBut note that redirection will \fBnot\fR work with \f(CW\*(C`POST\*(C'\fR unless \s-1LWP\s0 isinstalled. It's best, therefore, to check \f(CW\*(C`have_lwp\*(C'\fR before runningtests that rely on a redirection from \f(CW\*(C`POST\*(C'\fR..PPSometimes it is desireable to have \f(CW\*(C`Apache::TestRequest\*(C'\fR remembercookies sent by the pages you are testing and send them back to theserver on subsequent requests. This is especially necessary whentesting pages whose functionality relies on sessions or the presenceof preferences stored in cookies..PPBy default, \f(CW\*(C`LWP::UserAgent\*(C'\fR does \fBnot\fR remember cookies betweenrequests. You can tell it to remember cookies between request byadding:.PP.Vb 1\&  Apache::TestRequest::user_agent(cookie_jar => {});.Ve.PPbefore issuing the requests..SH "FUNCTIONS".IX Header "FUNCTIONS"\&\f(CW\*(C`Apache::TestRequest\*(C'\fR exports a number of functions that will likelyprove convenient for use in the majority of your request tests..Sh "Optional Parameters".IX Subsection "Optional Parameters"Each function also takes a number of optional arguments..IP "redirect_ok" 4.IX Item "redirect_ok"By default a request will follow redirects retrieved from the server. Toprevent this behavior, pass a false value to a \f(CW\*(C`redirect_ok\*(C'\fRparameter:.Sp.Vb 1\&  my $res = GET $uri, redirect_ok => 0;.Ve.SpAlternately, if all of your tests need to disable redirects, tell\&\f(CW\*(C`Apache::TestRequest\*(C'\fR to use an \f(CW\*(C`LWP::UserAgent\*(C'\fR object thatdisables redirects:.Sp.Vb 2\&  Apache::TestRequest::user_agent( reset => 1,\&                                   requests_redirectable => 0 );.Ve.IP "cert" 4.IX Item "cert"If you need to force an \s-1SSL\s0 request to use a particular \s-1SSL\s0certificate, pass the name of the certificate via the \f(CW\*(C`cert\*(C'\fRparameter:.Sp.Vb 1\&  my $res = GET $uri, cert => \*(Aqmy_cert\*(Aq;.Ve.IP "content" 4.IX Item "content"If you need to add content to your request, use the \f(CW\*(C`content\*(C'\fRparameter:.Sp.Vb 1\&  my $res = GET $uri, content => \*(Aqhello world!\*(Aq;.Ve.IP "filename" 4.IX Item "filename"The name of a local file on the file system to be sent to the Apachetest server via \f(CW\*(C`UPLOAD()\*(C'\fR and its friends..Sh "The Functions".IX Subsection "The Functions"\fI\s-1GET\s0\fR.IX Subsection "GET".PP.Vb 1\&  my $res = GET $uri;.Ve.PPSends a simple \s-1GET\s0 request to the Apache test server. Returns an\&\f(CW\*(C`HTTP::Response\*(C'\fR object..PPYou can also supply additional headers to be sent with the request byadding their name/value pairs after the \f(CW\*(C`url\*(C'\fR parameter, for example:.PP.Vb 1\&  my $res = GET $url, \*(AqAccept\-Language\*(Aq => \*(Aqde,en\-us,en;q=0.5\*(Aq;.Ve.PP\fI\s-1GET_STR\s0\fR.IX Subsection "GET_STR".PPA shortcut function for \f(CW\*(C`GET($uri)\->as_string\*(C'\fR..PP\fI\s-1GET_BODY\s0\fR.IX Subsection "GET_BODY".PPA shortcut function for \f(CW\*(C`GET($uri)\->content\*(C'\fR..PP\fI\s-1GET_BODY_ASSERT\s0\fR.IX Subsection "GET_BODY_ASSERT".PPUse this function when your test is outputting content that you needto check, and you want to make sure that the request was successfulbefore comparing the contents of the request. If the request wasunsuccessful, \f(CW\*(C`GET_BODY_ASSERT\*(C'\fR will return an errormessage. Otherwise it will simply return the content of the request

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?