NAME

cs::HTTP - operate the HTTP protocol


SYNOPSIS

use cs::HTTP;


DESCRIPTION

This module implements functions and methods for dealing with HTTP connections.


CONSTANTS

HTTP Response Codes

$R_OK

200 Request fulfilled.

$R_CREATED

201 follows post - text is URI of new document

$R_ACCEPTED

202 request accepted but not complete (may never be)

$R_PARTIAL

203 response is a private metaweb, not the original

$R_NORESPONSE

204 request ok, but nothing to send back - client's browser should stay in the same spot

$M_MOVED

301 document has new permanent URI. Lines follow of the form:

        B<URI>: I<url> I<comment>
$M_FOUND

302 document is currently elsewhere. Lines follow of the form:

        B<URI:> I<url> I<comment>
$M_METHOD

303 document needs different method. Following is:

        B<Method:> I<method> I<url>
        I<body-section>

body-section is data for method.

$M_NOT_MOD

304 response to conditional GET - document not modified, client should used cached version.

$E_BAD

400 bad request

$E_UNAUTH

401 bad authorisation - text is auth scheme spec

$E_PAYMENT

402 payment required - text is payment scheme spec

$E_FORBIDDEN

403 request denied - authorisation won't help

$E_NOT_FOUND

404 no match for URI

$E_INTERNAL

500 undiagnosed server problem

$E_NOT_IMPL

501 facility not supported

$E_OVERLOAD

502 load too high - try later

$E_GTIMEOUT

503 gateway timeout - subservices didn't respond in time


GENERAL FUNCTIONS

hexify(string,chptn)

Convert all characters string not matching chptn into %xx escapes. If chptn is HTML, use [^!-~]|`` for the pattern.

unhexify(string)

Convert all %xx escapes in string into characters.

rqhdr(url,srcurl,agent)

Return a cs::RFC822 header set to accompany a request for the cs::URL url, including cookie fields. The optional cs::URL srcurl is used for the Referer: field, defaulting to the environment variable HTTP_REFERER or failing that, url. The optional agent is used for the User-Agent: field, defaulting to the environment variable HTTP_USER_AGENT or failing that, ``$::cmd/1.0''.

getCookies(cookiefile)

Return an array of hashrefs representing cookies from the specified file. If cookiefile is omitted use the file specified by the environment variable $COOKIE_FILE or failing that $HOME/.netscape/cookies.txt.


OBJECT CREATION

new cs::HTTP (host, port, isProxy)

Return a cs::Net::TCP object attached to the host:port specified (port defaults to 80, the standard HTTP port). If the optional isProxy flag is set the connection is taken to be to a web proxy.


OBJECT METHODS

Request(method,uri,hdrs,data,version,sinkfile)

Request the uri with the specified method. If supplied, hdrs are added to the headers sent with the request, superceding matching headers. If supplied, data is a cs::Source containing data to follow the headers. If supplied, version is an HTTP/n.n version string to use instead of the default HTTP/1.0.

Get(args...)

Call the Request method a GET method specification.

Post(uri,data)

Call the Request method for the specified uri with a POST method specification and the values in the hashref data attached as the data source.


SEE ALSO

cs::Net::TCP(3), cs::Port(3)


AUTHOR

Cameron Simpson <cs@zip.com.au>