{
    "content": [
        {
            "type": "text",
            "text": "# HTTP::Daemon (perldoc)\n\n## NAME\n\nHTTP::Daemon - A simple http server class\n\n## SYNOPSIS\n\nuse HTTP::Daemon;\nuse HTTP::Status;\nmy $d = HTTP::Daemon->new || die;\nprint \"Please contact me at: <URL:\", $d->url, \">\\n\";\nwhile (my $c = $d->accept) {\nwhile (my $r = $c->getrequest) {\nif ($r->method eq 'GET' and $r->uri->path eq \"/xyzzy\") {\n# remember, this is *not* recommended practice :-)\n$c->sendfileresponse(\"/etc/passwd\");\n}\nelse {\n$c->senderror(RCFORBIDDEN)\n}\n}\n$c->close;\nundef($c);\n}\n\n## DESCRIPTION\n\nInstances of the \"HTTP::Daemon\" class are HTTP/1.1 servers that listen on a socket for incoming\nrequests. The \"HTTP::Daemon\" is a subclass of \"IO::Socket::IP\", so you can perform socket\noperations directly on it too.\n\n## Sections\n\n- **NAME**\n- **VERSION**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **SEE ALSO**\n- **SUPPORT**\n- **AUTHOR**\n- **CONTRIBUTORS**\n- **COPYRIGHT AND LICENCE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "HTTP::Daemon",
        "section": "",
        "mode": "perldoc",
        "summary": "HTTP::Daemon - A simple http server class",
        "synopsis": "use HTTP::Daemon;\nuse HTTP::Status;\nmy $d = HTTP::Daemon->new || die;\nprint \"Please contact me at: <URL:\", $d->url, \">\\n\";\nwhile (my $c = $d->accept) {\nwhile (my $r = $c->getrequest) {\nif ($r->method eq 'GET' and $r->uri->path eq \"/xyzzy\") {\n# remember, this is *not* recommended practice :-)\n$c->sendfileresponse(\"/etc/passwd\");\n}\nelse {\n$c->senderror(RCFORBIDDEN)\n}\n}\n$c->close;\nundef($c);\n}",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "VERSION",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 193,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "SUPPORT",
                "lines": 8,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "CONTRIBUTORS",
                "lines": 96,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENCE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "HTTP::Daemon - A simple http server class\n",
                "subsections": []
            },
            "VERSION": {
                "content": "version 6.13\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use HTTP::Daemon;\nuse HTTP::Status;\n\nmy $d = HTTP::Daemon->new || die;\nprint \"Please contact me at: <URL:\", $d->url, \">\\n\";\nwhile (my $c = $d->accept) {\nwhile (my $r = $c->getrequest) {\nif ($r->method eq 'GET' and $r->uri->path eq \"/xyzzy\") {\n# remember, this is *not* recommended practice :-)\n$c->sendfileresponse(\"/etc/passwd\");\n}\nelse {\n$c->senderror(RCFORBIDDEN)\n}\n}\n$c->close;\nundef($c);\n}\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Instances of the \"HTTP::Daemon\" class are HTTP/1.1 servers that listen on a socket for incoming\nrequests. The \"HTTP::Daemon\" is a subclass of \"IO::Socket::IP\", so you can perform socket\noperations directly on it too.\n\nPlease note that \"HTTP::Daemon\" used to be a subclass of \"IO::Socket::INET\". To support IPv6, it\nswitched the parent class to \"IO::Socket::IP\" at version 6.05. See \"IPv6 SUPPORT\" for details.\n\nThe accept() method will return when a connection from a client is available. The returned value\nwill be an \"HTTP::Daemon::ClientConn\" object which is another \"IO::Socket::IP\" subclass. Calling\nthe getrequest() method on this object will read data from the client and return an\n\"HTTP::Request\" object. The ClientConn object also provide methods to send back various\nresponses.\n\nThis HTTP daemon does not fork(2) for you. Your application, i.e. the user of the \"HTTP::Daemon\"\nis responsible for forking if that is desirable. Also note that the user is responsible for\ngenerating responses that conform to the HTTP/1.1 protocol.\n\nThe following methods of \"HTTP::Daemon\" are new (or enhanced) relative to the \"IO::Socket::IP\"\nbase class:\n\n$d = HTTP::Daemon->new\n$d = HTTP::Daemon->new( %opts )\nThe constructor method takes the same arguments as the \"IO::Socket::IP\" constructor, but\nunlike its base class it can also be called without any arguments. The daemon will then set\nup a listen queue of 5 connections and allocate some random port number.\n\nA server that wants to bind to some specific address on the standard HTTP port will be\nconstructed like this:\n\n$d = HTTP::Daemon->new(\nLocalAddr => 'www.thisplace.com',\nLocalPort => 80,\n);\n\nSee IO::Socket::IP for a description of other arguments that can be used to configure the\ndaemon during construction.\n\n$c = $d->accept\n$c = $d->accept( $pkg )\n($c, $peeraddr) = $d->accept\nThis method works the same as the one provided by the base class, but it returns an\n\"HTTP::Daemon::ClientConn\" reference by default. If a package name is provided as argument,\nthen the returned object will be blessed into the given class. It is probably a good idea to\nmake that class a subclass of \"HTTP::Daemon::ClientConn\".\n\nThe accept method will return \"undef\" if timeouts have been enabled and no connection is\nmade within the given time. The timeout() method is described in IO::Socket::IP.\n\nIn list context both the client object and the peer address will be returned; see the\ndescription of the accept method of IO::Socket for details.\n\n$d->url\nReturns a URL string that can be used to access the server root.\n\n$d->producttokens\nReturns the name that this server will use to identify itself. This is the string that is\nsent with the \"Server\" response header. The main reason to have this method is that\nsubclasses can override it if they want to use another product name.\n\nThe default is the string \"libwww-perl-daemon/#.##\" where \"#.##\" is replaced with the\nversion number of this module.\n\nThe \"HTTP::Daemon::ClientConn\" is a subclass of \"IO::Socket::IP\". Instances of this class are\nreturned by the accept() method of \"HTTP::Daemon\". The following methods are provided:\n\n$c->getrequest\n$c->getrequest( $headersonly )\nThis method reads data from the client and turns it into an \"HTTP::Request\" object which is\nreturned. It returns \"undef\" if reading fails. If it fails, then the\n\"HTTP::Daemon::ClientConn\" object ($c) should be discarded, and you should not try to call\nthis method again on it. The $c->reason method might give you some information about why\n$c->getrequest failed.\n\nThe getrequest() method will normally not return until the whole request has been received\nfrom the client. This might not be what you want if the request is an upload of a large file\n(and with chunked transfer encoding HTTP can even support infinite request messages -\nuploading live audio for instance). If you pass a TRUE value as the $headersonly argument,\nthen getrequest() will return immediately after parsing the request headers and you are\nresponsible for reading the rest of the request content. If you are going to call\n$c->getrequest again on the same connection you better read the correct number of bytes.\n\n$c->readbuffer\n$c->readbuffer( $newvalue )\nBytes read by $c->getrequest, but not used are placed in the *read buffer*. The next time\n$c->getrequest is called it will consume the bytes in this buffer before reading more data\nfrom the network connection itself. The read buffer is invalid after $c->getrequest has\nfailed.\n\nIf you handle the reading of the request content yourself you need to empty this buffer\nbefore you read more and you need to place unconsumed bytes here. You also need this buffer\nif you implement services like *101 Switching Protocols*.\n\nThis method always returns the old buffer content and can optionally replace the buffer\ncontent if you pass it an argument.\n\n$c->reason\nWhen $c->getrequest returns \"undef\" you can obtain a short string describing why it\nhappened by calling $c->reason.\n\n$c->protoge( $proto )\nReturn TRUE if the client announced a protocol with version number greater or equal to the\ngiven argument. The $proto argument can be a string like \"HTTP/1.1\" or just \"1.1\".\n\n$c->antiqueclient\nReturn TRUE if the client speaks the HTTP/0.9 protocol. No status code and no headers should\nbe returned to such a client. This should be the same as !$c->protoge(\"HTTP/1.0\").\n\n$c->headrequest\nReturn TRUE if the last request was a \"HEAD\" request. No content body must be generated for\nthese requests.\n\n$c->forcelastrequest\nMake sure that $c->getrequest will not try to read more requests off this connection. If\nyou generate a response that is not self-delimiting, then you should signal this fact by\ncalling this method.\n\nThis attribute is turned on automatically if the client announces protocol HTTP/1.0 or worse\nand does not include a \"Connection: Keep-Alive\" header. It is also turned on automatically\nwhen HTTP/1.1 or better clients send the \"Connection: close\" request header.\n\n$c->sendstatusline\n$c->sendstatusline( $code )\n$c->sendstatusline( $code, $mess )\n$c->sendstatusline( $code, $mess, $proto )\nSend the status line back to the client. If $code is omitted 200 is assumed. If $mess is\nomitted, then a message corresponding to $code is inserted. If $proto is missing the content\nof the $HTTP::Daemon::PROTO variable is used.\n\n$c->sendcrlf\nSend the CRLF sequence to the client.\n\n$c->sendbasicheader\n$c->sendbasicheader( $code )\n$c->sendbasicheader( $code, $mess )\n$c->sendbasicheader( $code, $mess, $proto )\nSend the status line and the \"Date:\" and \"Server:\" headers back to the client. This header\nis assumed to be continued and does not end with an empty CRLF line.\n\nSee the description of sendstatusline() for the description of the accepted arguments.\n\n$c->sendheader( $field, $value )\n$c->sendheader( $field1, $value1, $field2, $value2, ... )\nSend one or more header lines.\n\n$c->sendresponse( $res )\nWrite an \"HTTP::Response\" object to the client as a response. We try hard to make sure that\nthe response is self-delimiting so that the connection can stay persistent for further\nrequest/response exchanges.\n\nThe content attribute of the \"HTTP::Response\" object can be a normal string or a subroutine\nreference. If it is a subroutine, then whatever this callback routine returns is written\nback to the client as the response content. The routine will be called until it returns an\nundefined or empty value. If the client is HTTP/1.1 aware then we will use chunked transfer\nencoding for the response.\n\n$c->sendredirect( $loc )\n$c->sendredirect( $loc, $code )\n$c->sendredirect( $loc, $code, $entitybody )\nSend a redirect response back to the client. The location ($loc) can be an absolute or\nrelative URL. The $code must be one of the redirect status codes, and defaults to \"301 Moved\nPermanently\"\n\n$c->senderror\n$c->senderror( $code )\n$c->senderror( $code, $errormessage )\nSend an error response back to the client. If the $code is missing a \"Bad Request\" error is\nreported. The $errormessage is a string that is incorporated in the body of the HTML\nentity.\n\n$c->sendfileresponse( $filename )\nSend back a response with the specified $filename as content. If the file is a directory we\ntry to generate an HTML index of it.\n\n$c->sendfile( $filename )\n$c->sendfile( $fd )\nCopy the file to the client. The file can be a string (which will be interpreted as a\nfilename) or a reference to an \"IO::Handle\" or glob.\n\n$c->daemon\nReturn a reference to the corresponding \"HTTP::Daemon\" object.\n\nIPv6 SUPPORT\nSince version 6.05, \"HTTP::Daemon\" is a subclass of \"IO::Socket::IP\" rather than\n\"IO::Socket::INET\", so that it supports IPv6.\n\nFor some reasons, you may want to force \"HTTP::Daemon\" to listen on IPv4 addresses only. Then\npass \"Family\" argument to \"HTTP::Daemon->new\":\n\nuse HTTP::Daemon;\nuse Socket 'AFINET';\n\nmy $d = HTTP::Daemon->new(Family => AFINET);\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "RFC 2616\n\nIO::Socket::IP, IO::Socket\n",
                "subsections": []
            },
            "SUPPORT": {
                "content": "Bugs may be submitted through <https://github.com/libwww-perl/HTTP-Daemon/issues>.\n\nThere is also a mailing list available for users of this distribution, at\n<mailto:libwww@perl.org>.\n\nThere is also an irc channel available for users of this distribution, at \"#lwp\" on\n\"irc.perl.org\" <irc://irc.perl.org/#lwp>.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Gisle Aas <gisle@activestate.com>\n",
                "subsections": []
            },
            "CONTRIBUTORS": {
                "content": "*   Olaf Alders <olaf@wundersolutions.com>\n\n*   Ville Skyttä <ville.skytta@iki.fi>\n\n*   Karen Etheridge <ether@cpan.org>\n\n*   Mark Stosberg <MARKSTOS@cpan.org>\n\n*   Shoichi Kaji <skaji@cpan.org>\n\n*   Chase Whitener <capoeirab@cpan.org>\n\n*   Slaven Rezic <slaven@rezic.de>\n\n*   Petr Písař <ppisar@redhat.com>\n\n*   Zefram <zefram@fysh.org>\n\n*   Alexey Tourbin <at@altlinux.ru>\n\n*   Bron Gondwana <brong@fastmail.fm>\n\n*   Mike Schilli <mschilli@yahoo-inc.com>\n\n*   Tom Hukins <tom@eborcom.com>\n\n*   Adam Kennedy <adamk@cpan.org>\n\n*   Adam Sjogren <asjo@koldfront.dk>\n\n*   Alex Kapranoff <ka@nadoby.ru>\n\n*   amire80 <amir.aharoni@gmail.com>\n\n*   Andreas J. Koenig <andreas.koenig@anima.de>\n\n*   Bill Mann <wfmann@alum.mit.edu>\n\n*   Daniel Hedlund <Daniel.Hedlund@eprize.com>\n\n*   David E. Wheeler <david@justatheory.com>\n\n*   DAVIDRW <davidrw@cpan.org>\n\n*   Father Chrysostomos <sprout@cpan.org>\n\n*   Ferenc Erki <erkiferenc@gmail.com>\n\n*   FWILES <FWILES@cpan.org>\n\n*   Gavin Peters <gpeters@deepsky.com>\n\n*   Graeme Thompson <Graeme.Thompson@mobilecohesion.com>\n\n*   Hans-H. Froehlich <hfroehlich@co-de-co.de>\n\n*   Ian Kilgore <iank@cpan.org>\n\n*   Jacob J <waif@chaos2.org>\n\n*   jefflee <shaohua@gmail.com>\n\n*   john9art <john9art@yahoo.com>\n\n*   murphy <murphy@genome.chop.edu>\n\n*   Ondrej Hanak <ondrej.hanak@ubs.com>\n\n*   Perlover <perlover@perlover.com>\n\n*   Peter Rabbitson <ribasushi@cpan.org>\n\n*   phrstbrn <phrstbrn@gmail.com>\n\n*   Robert Stone <talby@trap.mtview.ca.us>\n\n*   Rolf Grossmann <rg@progtech.net>\n\n*   ruff <ruff@ukrpost.net>\n\n*   sasao <sasao@yugen.org>\n\n*   Sean M. Burke <sburke@cpan.org>\n\n*   Spiros Denaxas <s.denaxas@gmail.com>\n\n*   Steve Hay <SteveHay@planit.com>\n\n*   Todd Lipcon <todd@amiestreet.com>\n\n*   Tony Finch <dot@dotat.at>\n\n*   Toru Yamaguchi <zigorou@cpan.org>\n\n*   Yuri Karaban <tech@askold.net>\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENCE": {
                "content": "This software is copyright (c) 1995 by Gisle Aas.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
                "subsections": []
            }
        }
    }
}