SUMMARY: CONSTR | METHOD DETAIL: CONSTR | METHOD

Class HTTP::Daemon::Threaded::WebClient

Inherits from:
Thread::Apartment::MuxServer
HTTP::Daemon::Threaded::Logable

Provides web-based request handling. A pool of WebClient objects are created and managed by HTTP::Daemon::Threaded::Listener. As web connection requests are received, a WebClient is allocated and assigned the network connection. A minimal HTTP protocol implementation is provided via a subclass of HTTP::Daemon::ClientConn. As requests are received, they are processed as needed, possibly resulting in calls to any installed content handler components.

Content handlers are specified as an arrayref of 2-tuples consisting of

[ regular expression string, content handler class name ]
When a client HTTP request is received, each registered content handler's regular expression string is applied to the URI in the order in which the handler's are listed in the content handler map until a match is found, at which point the content handler class's getContent()/putContent()/getHeader() method is invoked. If no regular expression matches the URI, a HTTP 404 (NOT FOUND) error is returned to the client.

Application specific parameters for content handlers may be provided by creating a concrete implemention of the HTTP::Daemon::Threaded::ContentParams class, and supplying any constructor parameters as additional key/value pairs in the WebClient constructor hash.

Copyright© 2006, Dean Arnold, Presicient Corp., USA
All rights reserved.

Licensed under the Academic Free License version 2.1, as specified in the License.txt file included in this software package, or at OpenSource.org.

Author:
D. Arnold
Version:
0.90
Since:
2006-08-21

Unless otherwise noted, $self is the object instance variable.

Constructor Summary
new(HTTPD => value, LogLevel => value, EventLogger => value, WebLogger => value, Handlers => value, ID => value, InactivityTimer => value, ContentParams => value, UserAuth => value, SessionCache => value, DocRoot => value, URL => value, ProductTokens => value, MediaTypes => value, FreeList => value, SelectInterval => value)
          Creates an empty HTTP::Daemon::Threaded::Socket object

Method Summary
acceptConnection($fn)
          Accepts a web client connection
freeClient($client)
          Return a client to the free list
get_simplex_methods()
          Overrides Thread::Apartment::Server::get_simplex_methods()
handleSocketEvent($fd)
          Handles a socket event
run()
          Thread::Apartment::MuxServer::run() implementation

Constructor Details

new

new(HTTPD => value, LogLevel => value, EventLogger => value, WebLogger => value, Handlers => value, ID => value, InactivityTimer => value, ContentParams => value, UserAuth => value, SessionCache => value, DocRoot => value, URL => value, ProductTokens => value, MediaTypes => value, FreeList => value, SelectInterval => value)

Creates an empty HTTP::Daemon::Threaded::Socket object. Creates any specified ContentParams object, and installs the content handler map.

Note that the following parameters are recognized by HTTP::Daemon::Threaded::WebClient, but applications may supply additional parameter key/value pairs which will be provided to the constructor for any specified HTTP::Daemon::Threaded::ContentParams class.

Parameters:
HTTPD => the parent daemon object
LogLevel => (optional) logging level; 1 => errors only; 2 => errors and warnings only; 3 => errors, warnings, and info messages; default 1
EventLogger => (optional) Instance of a HTTP::Daemon::Threaded::Logger to receive event notifications (except for web requests)
WebLogger => (optional) Instance of a HTTP::Daemon::Threaded::Logger to receive web request notifications
Handlers => arrayref mapping URL regex strings to handler classes
ID => unique client identifier
InactivityTimer => (optional) number of seconds to wait before disconnecting an idle connection
ContentParams => (optional) name of a ContentsParam concrete implementation
UserAuth => (optional) User authentication package name (not yet supported)
SessionCache => (optional) threads::shared object implementing HTTP::Daemon::Threaded::SessionCache
DocRoot => (optional) root directory for default file based content handler
URL => the base address/port of our listener
ProductTokens => product token string from listener
MediaTypes => (optional) hashref mapping 'Content-Type' specifications to file qualifier strings. Values may be either a single string literal, or an arrayref of string literals, e.g.,
MediaTypes => { 'text/css' => 'css' }. Used to add media types for LWP::MediaTypes::guess_media_type()
FreeList => free client list; threads::shared array optimized to quickly allocate/free WebClient objects
SelectInterval => seconds to wait in select()'s on sockets. May be fractional; default 0.5
Returns:
HTTP::Daemon::Threaded::WebClient object

Method Details

acceptConnection

acceptConnection($fn)

Accepts a web client connection. Called from HTTP::Daemon::Threaded when a new connection event occurs. Collects the peer info for logging purposes. Converts the supplied socket file number to a HTTP::Daemon::Threaded::Socket object.

Parameters:
$fn - file number of the new socket
Returns:
the object
See Also:
HTTP::Daemon::Threaded::Socket

freeClient

freeClient($client)

Return a client to the free list.

Parameters:
$client - ID of the client being freed
Returns:
1

get_simplex_methods

get_simplex_methods()

Overrides Thread::Apartment::Server::get_simplex_methods().

Returns:
hashref of simplex method names

handleSocketEvent

handleSocketEvent($fd)

Handles a socket event. Accumulates a client request, parses it, and then dispatches to the associated URL handler. Only a single client request is handled, but the connection may be retained indefinitely (for HTTP 1.1 Connection: keepalive clients).

Parameters:
$fd - the HTTP::Daemon::Threaded::Socket object on which the event occured
Returns:
the object

run

run()

Thread::Apartment::MuxServer::run() implementation.

Returns:
1

Generated by psichedoc on Mon Aug 28 09:45:39 2006