📄 http::daemon.3
字号:
blessed into the given class. It is probably a good idea to make thatclass a subclass of \f(CW\*(C`HTTP::Daemon::ClientConn\*(C'\fR..SpThe accept method will return \f(CW\*(C`undef\*(C'\fR if timeouts have been enabledand no connection is made within the given time. The \fItimeout()\fR methodis described in IO::Socket..SpIn list context both the client object and the peer address will bereturned; see the description of the accept method IO::Socket fordetails..ie n .IP "$d\->url" 4.el .IP "\f(CW$d\fR\->url" 4.IX Item "$d->url"Returns a \s-1URL\s0 string that can be used to access the server root..ie n .IP "$d\->product_tokens" 4.el .IP "\f(CW$d\fR\->product_tokens" 4.IX Item "$d->product_tokens"Returns the name that this server will use to identify itself. Thisis the string that is sent with the \f(CW\*(C`Server\*(C'\fR response header. Themain reason to have this method is that subclasses can override it ifthey want to use another product name..SpThe default is the string \*(L"libwww\-perl\-daemon/#.##\*(R" where \*(L"#.##\*(R" isreplaced with the version number of this module..PPThe \f(CW\*(C`HTTP::Daemon::ClientConn\*(C'\fR is a \f(CW\*(C`IO::Socket::INET\*(C'\fRsubclass. Instances of this class are returned by the \fIaccept()\fR methodof \f(CW\*(C`HTTP::Daemon\*(C'\fR. The following methods are provided:.ie n .IP "$c\->get_request" 4.el .IP "\f(CW$c\fR\->get_request" 4.IX Item "$c->get_request".PD 0.ie n .IP "$c\fR\->get_request( \f(CW$headers_only )" 4.el .IP "\f(CW$c\fR\->get_request( \f(CW$headers_only\fR )" 4.IX Item "$c->get_request( $headers_only )".PDThis method read data from the client and turns it into an\&\f(CW\*(C`HTTP::Request\*(C'\fR object which is returned. It returns \f(CW\*(C`undef\*(C'\fRif reading fails. If it fails, then the \f(CW\*(C`HTTP::Daemon::ClientConn\*(C'\fRobject ($c) should be discarded, and you should not try call thismethod again on it. The \f(CW$c\fR\->reason method might give you someinformation about why \f(CW$c\fR\->get_request failed..SpThe \fIget_request()\fR method will normally not return until the wholerequest has been received from the client. This might not be what youwant if the request is an upload of a large file (and with chunkedtransfer encoding \s-1HTTP\s0 can even support infinite request messages \-uploading live audio for instance). If you pass a \s-1TRUE\s0 value as the\&\f(CW$headers_only\fR argument, then \fIget_request()\fR will return immediatelyafter parsing the request headers and you are responsible for readingthe rest of the request content. If you are going to call\&\f(CW$c\fR\->get_request again on the same connection you better read thecorrect number of bytes..ie n .IP "$c\->read_buffer" 4.el .IP "\f(CW$c\fR\->read_buffer" 4.IX Item "$c->read_buffer".PD 0.ie n .IP "$c\fR\->read_buffer( \f(CW$new_value )" 4.el .IP "\f(CW$c\fR\->read_buffer( \f(CW$new_value\fR )" 4.IX Item "$c->read_buffer( $new_value )".PDBytes read by \f(CW$c\fR\->get_request, but not used are placed in the \fIreadbuffer\fR. The next time \f(CW$c\fR\->get_request is called it will consume thebytes in this buffer before reading more data from the networkconnection itself. The read buffer is invalid after \f(CW$c\fR\->get_requesthas failed..SpIf you handle the reading of the request content yourself you need toempty this buffer before you read more and you need to placeunconsumed bytes here. You also need this buffer if you implementservices like \fI101 Switching Protocols\fR..SpThis method always return the old buffer content and can optionallyreplace the buffer content if you pass it an argument..ie n .IP "$c\->reason" 4.el .IP "\f(CW$c\fR\->reason" 4.IX Item "$c->reason"When \f(CW$c\fR\->get_request returns \f(CW\*(C`undef\*(C'\fR you can obtain a short stringdescribing why it happened by calling \f(CW$c\fR\->reason..ie n .IP "$c\fR\->proto_ge( \f(CW$proto )" 4.el .IP "\f(CW$c\fR\->proto_ge( \f(CW$proto\fR )" 4.IX Item "$c->proto_ge( $proto )"Return \s-1TRUE\s0 if the client announced a protocol with version numbergreater or equal to the given argument. The \f(CW$proto\fR argument can be astring like \*(L"\s-1HTTP/1\s0.1\*(R" or just \*(L"1.1\*(R"..ie n .IP "$c\->antique_client" 4.el .IP "\f(CW$c\fR\->antique_client" 4.IX Item "$c->antique_client"Return \s-1TRUE\s0 if the client speaks the \s-1HTTP/0\s0.9 protocol. No statuscode and no headers should be returned to such a client. This shouldbe the same as !$c\->proto_ge(\*(L"\s-1HTTP/1\s0.0\*(R")..ie n .IP "$c\->head_request" 4.el .IP "\f(CW$c\fR\->head_request" 4.IX Item "$c->head_request"Return \s-1TRUE\s0 if the last request was a \f(CW\*(C`HEAD\*(C'\fR request. No contentbody must be generated for these requests..ie n .IP "$c\->force_last_request" 4.el .IP "\f(CW$c\fR\->force_last_request" 4.IX Item "$c->force_last_request"Make sure that \f(CW$c\fR\->get_request will not try to read more requests offthis connection. If you generate a response that is not selfdelimiting, then you should signal this fact by calling this method..SpThis attribute is turned on automatically if the client announcesprotocol \s-1HTTP/1\s0.0 or worse and does not include a \*(L"Connection:Keep-Alive\*(R" header. It is also turned on automatically when \s-1HTTP/1\s0.1or better clients send the \*(L"Connection: close\*(R" request header..ie n .IP "$c\->send_status_line" 4.el .IP "\f(CW$c\fR\->send_status_line" 4.IX Item "$c->send_status_line".PD 0.ie n .IP "$c\fR\->send_status_line( \f(CW$code )" 4.el .IP "\f(CW$c\fR\->send_status_line( \f(CW$code\fR )" 4.IX Item "$c->send_status_line( $code )".ie n .IP "$c\fR\->send_status_line( \f(CW$code\fR, \f(CW$mess )" 4.el .IP "\f(CW$c\fR\->send_status_line( \f(CW$code\fR, \f(CW$mess\fR )" 4.IX Item "$c->send_status_line( $code, $mess )".ie n .IP "$c\fR\->send_status_line( \f(CW$code\fR, \f(CW$mess\fR, \f(CW$proto )" 4.el .IP "\f(CW$c\fR\->send_status_line( \f(CW$code\fR, \f(CW$mess\fR, \f(CW$proto\fR )" 4.IX Item "$c->send_status_line( $code, $mess, $proto )".PDSend the status line back to the client. If \f(CW$code\fR is omitted 200 isassumed. If \f(CW$mess\fR is omitted, then a message corresponding to \f(CW$code\fRis inserted. If \f(CW$proto\fR is missing the content of the\&\f(CW$HTTP::Daemon::PROTO\fR variable is used..ie n .IP "$c\->send_crlf" 4.el .IP "\f(CW$c\fR\->send_crlf" 4.IX Item "$c->send_crlf"Send the \s-1CRLF\s0 sequence to the client..ie n .IP "$c\->send_basic_header" 4.el .IP "\f(CW$c\fR\->send_basic_header" 4.IX Item "$c->send_basic_header".PD 0.ie n .IP "$c\fR\->send_basic_header( \f(CW$code )" 4.el .IP "\f(CW$c\fR\->send_basic_header( \f(CW$code\fR )" 4.IX Item "$c->send_basic_header( $code )".ie n .IP "$c\fR\->send_basic_header( \f(CW$code\fR, \f(CW$mess )" 4.el .IP "\f(CW$c\fR\->send_basic_header( \f(CW$code\fR, \f(CW$mess\fR )" 4.IX Item "$c->send_basic_header( $code, $mess )".ie n .IP "$c\fR\->send_basic_header( \f(CW$code\fR, \f(CW$mess\fR, \f(CW$proto )" 4.el .IP "\f(CW$c\fR\->send_basic_header( \f(CW$code\fR, \f(CW$mess\fR, \f(CW$proto\fR )" 4.IX Item "$c->send_basic_header( $code, $mess, $proto )".PDSend the status line and the \*(L"Date:\*(R" and \*(L"Server:\*(R" headers back tothe client. This header is assumed to be continued and does not endwith an empty \s-1CRLF\s0 line..SpSee the description of \fIsend_status_line()\fR for the description of theaccepted arguments..ie n .IP "$c\fR\->send_response( \f(CW$res )" 4.el .IP "\f(CW$c\fR\->send_response( \f(CW$res\fR )" 4.IX Item "$c->send_response( $res )"Write a \f(CW\*(C`HTTP::Response\*(C'\fR object to theclient as a response. We try hard to make sure that the response isself delimiting so that the connection can stay persistent for furtherrequest/response exchanges..SpThe content attribute of the \f(CW\*(C`HTTP::Response\*(C'\fR object can be a normalstring or a subroutine reference. If it is a subroutine, thenwhatever this callback routine returns is written back to theclient as the response content. The routine will be called until itreturn an undefined or empty value. If the client is \s-1HTTP/1\s0.1 awarethen we will use chunked transfer encoding for the response..ie n .IP "$c\fR\->send_redirect( \f(CW$loc )" 4.el .IP "\f(CW$c\fR\->send_redirect( \f(CW$loc\fR )" 4.IX Item "$c->send_redirect( $loc )".PD 0.ie n .IP "$c\fR\->send_redirect( \f(CW$loc\fR, \f(CW$code )" 4.el .IP "\f(CW$c\fR\->send_redirect( \f(CW$loc\fR, \f(CW$code\fR )" 4.IX Item "$c->send_redirect( $loc, $code )".ie n .IP "$c\fR\->send_redirect( \f(CW$loc\fR, \f(CW$code\fR, \f(CW$entity_body )" 4.el .IP "\f(CW$c\fR\->send_redirect( \f(CW$loc\fR, \f(CW$code\fR, \f(CW$entity_body\fR )" 4.IX Item "$c->send_redirect( $loc, $code, $entity_body )".PDSend a redirect response back to the client. The location ($loc) canbe an absolute or relative \s-1URL\s0. The \f(CW$code\fR must be one the redirectstatus codes, and defaults to \*(L"301 Moved Permanently\*(R".ie n .IP "$c\->send_error" 4.el .IP "\f(CW$c\fR\->send_error" 4.IX Item "$c->send_error".PD 0.ie n .IP "$c\fR\->send_error( \f(CW$code )" 4.el .IP "\f(CW$c\fR\->send_error( \f(CW$code\fR )" 4.IX Item "$c->send_error( $code )".ie n .IP "$c\fR\->send_error( \f(CW$code\fR, \f(CW$error_message )" 4.el .IP "\f(CW$c\fR\->send_error( \f(CW$code\fR, \f(CW$error_message\fR )" 4.IX Item "$c->send_error( $code, $error_message )".PDSend an error response back to the client. If the \f(CW$code\fR is missing a\&\*(L"Bad Request\*(R" error is reported. The \f(CW$error_message\fR is a string thatis incorporated in the body of the \s-1HTML\s0 entity body..ie n .IP "$c\fR\->send_file_response( \f(CW$filename )" 4.el .IP "\f(CW$c\fR\->send_file_response( \f(CW$filename\fR )" 4.IX Item "$c->send_file_response( $filename )"Send back a response with the specified \f(CW$filename\fR as content. If thefile is a directory we try to generate an \s-1HTML\s0 index of it..ie n .IP "$c\fR\->send_file( \f(CW$filename )" 4.el .IP "\f(CW$c\fR\->send_file( \f(CW$filename\fR )" 4.IX Item "$c->send_file( $filename )".PD 0.ie n .IP "$c\fR\->send_file( \f(CW$fd )" 4.el .IP "\f(CW$c\fR\->send_file( \f(CW$fd\fR )" 4.IX Item "$c->send_file( $fd )".PDCopy the file to the client. The file can be a string (whichwill be interpreted as a filename) or a reference to an \f(CW\*(C`IO::Handle\*(C'\fRor glob..ie n .IP "$c\->daemon" 4.el .IP "\f(CW$c\fR\->daemon" 4.IX Item "$c->daemon"Return a reference to the corresponding \f(CW\*(C`HTTP::Daemon\*(C'\fR object..SH "SEE ALSO".IX Header "SEE ALSO"\&\s-1RFC\s0 2616.PPIO::Socket::INET, IO::Socket.SH "COPYRIGHT".IX Header "COPYRIGHT"Copyright 1996\-2003, Gisle Aas.PPThis library is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -