Net::HTTPServer::Response(3) HTTP response


Net::HTTPServer::Response handles formatting the response to the client.


Net::HTTPServer::Response provides a nice OOP interface for easy control of headers, cookies, sessions, and/or the content that will be sent to the requesting client.


my $response = new Net::HTTPServer::Response();

my $response = new Net::HTTPServer::Response(code=>200,

my $response = $request->Response();



Given a config hash, return a server object that you can start, process, and stop. The config hash takes the options:

    body => string      - The contents of the response.
                          ( Default: "" )
    code => int         - The return code of this reponse.
                          ( Default: 200 )
    cookies => hashref  - Hash reference to a set of cookies to send.
                          Most people should just use the Cookie method
                          to set these.
                          ( Default: {} )
    headers => hashref  - Hash reference to the headers to send.  Most
                          people should just use the Header method.
                          ( Default: {} )


Returns the current value of the response body. Sets the content of the response if a value is specified.


Reset the body to "".


Returns the current value of the response code. Set the status code of the response if a value is specified.


Returns the cookie value for the specified name, or undef if it is not set. If the value is also specified, then the cookie is set to the value. The optional hash options that you can provide to the cookie are:

    domain => string   - If specified, the client will return the
                         cookie for any hostname that is part of
                         the domain.
    expires => string  - When should the cookie expire.  Must be
                         formatted according to the rules:
                             Wednesday, 30-June-2004 18:14:24 GMT
                         Optionally you can specify "now" which
                         will resolve to the current time.
    path => string     - The path on the server that the client should
                         return the cookie for.
    secure => 0|1      - The client will only return the cookie over
                         an HTTPS connection.


Returns the header value for the specified name, or undef if it is not set. If the value is specified, then the header is set to the value.


Appends the arguments to the end of the body.


Redirect the client to the specified URL.


Register the Net::HTTPServer::Session object with the response. When the server builds the actual reponse to the client it will set the appropriate cookie and save the session. If the response is created from the request object, and there was a session created from the request object then this, will be prepopulated with that session.


If you use the CGI perl module then it wants to print everything to STDOUT. CaptureSTDOUT() will put the Reponse object into a mode where it will capture all the output from the module. See ProcessSTDOUT() for more information.


This will harvest all of the data printed to STDOUT and put it into the Response object via a Print() call. This will also stop monitoring STDOUT and release it. You can specify some options:

  strip_header => 0|1     - If you use the CGI module and you
                            print the headers then ProcessSTDOUT()
                            can try to strip those out.  The best
                            plan is not to print them.

See CaptureSTDOUT() for more information.


Ryan Eatmon


Copyright (c) 2003-2005 Ryan Eatmon <[email protected]>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.