⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch20_03.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
📖 第 1 页 / 共 5 页
字号:
</pre><p><a name="INDEX-2543" />Returns the URL string that givesaccess to the server root.</p></div><a name="perlnut2-CHP-20-SECT-3.7.1" /><div class="sect3"><h3 class="sect3">20.3.7.1. HTTP::Daemon::ClientConn methods</h3><p><a name="INDEX-2544" /><a name="INDEX-2545" />Thefollowing methods can be used on HTTP::Daemon::ClientConn objects.</p><a name="INDEX-2546" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>antique_client</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;antique_client</pre><p><a name="INDEX-2546" />Returns true ifthe client uses the HTTP/0.9 protocol (i.e., no status code orheaders should be returned).</p></div><a name="INDEX-2547" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>crlf</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;crlf(  )</pre><p><a name="INDEX-2547" />Sends the CRLFsequence to the client.</p></div><a name="INDEX-2548" /><a name="INDEX-2549" /><a name="INDEX-2550" /><a name="INDEX-2551" /><a name="INDEX-2552" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>daemon</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;daemon</pre><p><a name="INDEX-2548" />Returns areference to the HTTP::Daemon object from which the currentClientConn object was generated.<a name="INDEX-2549" /><a name="INDEX-2550" /><a name="INDEX-2551" /><a name="INDEX-2552" /> </p></div><a name="INDEX-2553" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>force_last_request</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;force_last_request(  )</pre><p><a name="INDEX-2553" />Ensures that<tt class="literal">$c-&gt;get_request</tt> will not try to read morerequests off this connection. If you generate a response that is notself-delimiting, then you should signal this fact by calling thismethod. This attribute is turned on automatically if the clientannounces protocol HTTP/1.0 or worse and does not include aConnection: Keep-Alive header. It is also turned on automaticallywhen HTTP/1.1 or better clients send the Connection: Close requestheader</p></div><a name="INDEX-2554" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>get_request</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;get_request</pre><p><a name="INDEX-2554" />Reads informationfrom the client request and returns a reference to an HTTP::Requestobject. Returns <tt class="literal">undef</tt> if the request failed.</p></div><a name="INDEX-2555" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>proto_ge</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;proto_ge ( [$<em class="replaceable">new_value</em>] )</pre><p><a name="INDEX-2555" />Returns true ifthe client announced a protocol with version number greater or equalto the given argument. The <tt class="literal">$proto</tt> argument can bea string such as <tt class="literal">"HTTP/1.1"</tt>, or just<tt class="literal">"1.1"</tt>.</p></div><a name="INDEX-2556" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>read_buffer</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;read_buffer ( [$<em class="replaceable">new_value</em>] )</pre><p><a name="INDEX-2556" />Bytes read, butnot used, by <tt class="literal">$c-&gt;get_reques</tt> t are placed in theread buffer. The next time <tt class="literal">$c-&gt;get_request</tt> iscalled, it will consume the bytes in this buffer before reading moredata from the network connection itself.</p></div><a name="INDEX-2557" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>reason</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;reason(  )</pre><p><a name="INDEX-2557" />Returns a shortstring describing what happened if<tt class="literal">$c-&gt;get_request</tt> returns<tt class="literal">undef</tt>.</p></div><a name="INDEX-2558" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>send_basic_header</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;send_basic_header ( [<em class="replaceable">code</em>, [<em class="replaceable">msg</em>, [<em class="replaceable">proto</em>]]] )</pre><p><a name="INDEX-2558" />Sends status linecomposed of the specified parameters and the Date and Server headersto the client. If no arguments are given, the default status line<tt class="literal">HTTP/1.1 200 OK</tt> is used.</p></div><a name="INDEX-2559" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>send_error</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;send_error ( [<em class="replaceable">code</em>, [<em class="replaceable">msg</em>]] )</pre><p><a name="INDEX-2559" />Returns an errorresponse to the client. <em class="replaceable"><tt>code</tt></em> can containone of the error response codes; the default is <tt class="literal">400 BadRequest</tt>. <em class="replaceable"><tt>msg</tt></em> is a stringdescribing the error displayed in the HTML entity body.</p></div><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>send_file</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;send_file (<em class="replaceable">filename</em>)</pre><p>Copies contents of the file <em class="replaceable">filename</em> tothe client as the response. <em class="replaceable"><tt>filename</tt></em> canbe a string that is interpreted as a filename, or a reference to aglob.</p></div><a name="INDEX-2560" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>send_file_response</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;send_file_response (<em class="replaceable">filename</em>)</pre><p><a name="INDEX-2560" />Sends a responsewith the file <em class="replaceable"><tt>filename</tt></em> as content. If<em class="replaceable"><tt>filename</tt></em> is a directory, an index listingwill be generated and sent as HTML.</p></div><a name="INDEX-2561" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>send_redirect</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;send_redirect ( <em class="replaceable">url</em>, [<em class="replaceable">code</em>, [<em class="replaceable">entity_body</em>]] )</pre><p><a name="INDEX-2561" />Sends a redirectresponse to the client, with the location<em class="replaceable"><tt>url</tt></em>, an absolute or a relative URL. Theoptional <em class="replaceable"><tt>code</tt></em> argument should be one ofthe redirect status codes; the default is <tt class="literal">301 MovedPermanently</tt>. An <em class="replaceable"><tt>entity_body</tt></em>string can be sent as HTML that informs the user of the redirection.</p></div><a name="INDEX-2562" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>send_response</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;send_response ( [$<em class="replaceable">resp</em> | @<em class="replaceable">resplist</em>] )</pre><p><a name="INDEX-2562" />Sends a responseto the client created from the HTTP::Response object,<tt class="literal">$</tt><em class="replaceable"><tt>resp</tt></em>, or the list ofparameters, <tt class="literal">@</tt><em class="replaceable"><tt>resplist</tt></em>.The <em class="replaceable"><tt>resplist</tt></em> parameters are the same asthose used in the constructor for HTTP::Response and must at leastcontain a status code. If no argument is given, the default OKresponse is sent.</p></div><a name="INDEX-2563" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>send_status_line</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">c</em>-&gt;send_status_line ( [<em class="replaceable">code</em>, [<em class="replaceable">msg</em>, [<em class="replaceable">proto</em>]]] )</pre><p><a name="INDEX-2563" />Sends the statusline composed of the given arguments back to the client. If thearguments are given, the default status line is sent as<tt class="literal">HTTP/1.1 200 OK</tt>. The arguments are:</p><dl><dt><i><em class="replaceable"><tt>code</tt></em></i></dt><dd>The numeric code indicating the status of the request, e.g., 200 foran OK request or 404 for a request for a resource thatdoesn't exist</p></dd><dt><i><em class="replaceable"><tt>msg</tt></em></i></dt><dd>A short string describing the status code</p></dd><dt><i><em class="replaceable"><tt>proto</tt></em></i></dt><dd>A string indicating the protocol and version number used by theserver, e.g., HTTP/1.1.</p></dd></dl></div></div></div><a name="perlnut2-CHP-20-SECT-3.8" /><div class="sect2"><h3 class="sect2">20.3.8. HTTP::Message</h3><p><a name="INDEX-2564" /><a name="INDEX-2565" />HTTP::Messageis the generic base class for HTTP::Request and HTTP::Response. Itprovides a couple of methods used on both classes. The constructorfor this class is used internally by the Request and Responseclasses, so you will probably not need to use it. Methods defined bythe HTTP::Headers class will also work on Message objects.</p><a name="INDEX-2566" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>add_content</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">r</em>-&gt;add_content(<em class="replaceable">data</em>)</pre><p><a name="INDEX-2566" />Appends<em class="replaceable"><tt>data</tt></em> to the end of theobject's current entity body.</p></div><a name="INDEX-2567" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>clone</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">r</em>-&gt;clone(  )</pre><p><a name="INDEX-2567" />Creates a copy of the currentobject, <tt class="literal">$</tt><em class="replaceable"><tt>r</tt></em>, and returnsa reference to it.</p></div><a name="INDEX-2568" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>content</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">r</em>-&gt;content ([<em class="replaceable">content</em>])</pre><p><a name="INDEX-2568" />Without an argument,<tt class="literal">content</tt> returns the entity body of the object.With a scalar argument, the entity body will be set to<em class="replaceable"><tt>content</tt></em>.</p></div><a name="INDEX-2569" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>content_ref</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">r</em>-&gt;content_ref(  )</pre><p><a name="INDEX-2569" />Returns a reference to thestring containing the content body. This reference can be used tomanage large content data.</p></div><a name="INDEX-2570" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>headers</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">r</em>-&gt;headers(  )</pre><p><a name="INDEX-2570" />Returns the embedded HTTP::Headersobject from the message object.</p></div><a name="INDEX-2571" /><a name="INDEX-2572" /><a name="INDEX-2573" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><b>protocol</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><pre>$<em class="replaceable">r</em>-&gt;protocol([<em class="replaceable">string</em>])</pre><p><a name="INDEX-2571" />Sets or retrieves the HTTP protocol<em class="replaceable"><tt>string</tt></em> for the message object. This stringlooks like HTTP/1.1.<a name="INDEX-2572" /><a name="INDEX-2573" /> </p></div></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch20_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="ch20_04.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">20.2. The LWP Modules</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">20.4. The HTML Modules</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>

⌨️ 快捷键说明

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