HTTP-Daemon-Threaded

 view release on metacpan or  search on metacpan

lib/HTTP/Daemon/Threaded/WebClient.pm  view on Meta::CPAN


@return		1

=end classdoc

=cut

sub run {
	my $self = shift;

	while (1) {
#
#	HTTP::Daemon::Threaded::IOSelector does the heavy lifting
#
		if (exists $self->{_curr_skt}) {
			my $elapsed = $self->{_sktsel}->select();
#
#	check idle time
#
			if ($self->{_curr_sess}) {
				$self->_shutdown()
					if $self->{_curr_sess}->isInactive($self->{_idle_timer});
			}
			elsif ($self->{InactivityTimer} < (time() - $self->{_idle_timer})) {
				$self->_shutdown();
			}
		}
		else {
#
#	if no connection installed, just kill time
#
			select(undef, undef, undef, 0.1);
		}
		return undef
			unless $self->handle_method_requests();
	}

	return 1;
}

sub _shutdown {
	my $self = shift;
	$self->logInfo("Shutting down connection...\n");
	my $fd = delete $self->{_curr_skt};
	delete $self->{LogPrefix}{fileno($fd)};
	$fd->close();
	$self->{_curr_sess}->close(),
	delete $self->{_curr_sess}
		if $self->{_curr_sess};
	$self->freeClient();
	return 1;
}

=pod

=begin classdoc

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).

@param $fd	the HTTP::Daemon::Threaded::Socket object on which the event occured

@return		the object

=end classdoc

=cut

sub handleSocketEvent {
	my ($self, $fd) = @_;

	my ($page, $method, $buffer, $request, $cgi, $params, $handler, $session);
	my $close_on_resp;
	$fd = $self->{_curr_skt};
	my $handlers = $self->{Handlers};
#
#	read the request in (up to some max size) and validate
#	the header
#
	$request = $fd->get_request();
	return $self->_shutdown()
		unless $request;

#	$self->logInfo("Got a request as a " . (ref $request) . "\n");
#
#	get HTTP protocol level; if < 1.1, we close the connection on exit
#
#	$self->logInfo("Got pre 1.1 client\n"),
	$close_on_resp = 1,
	$fd->force_last_request()
		unless $fd->proto_ge("1.1");

	$session = $self->{SessionCache}->getSession($request)
		if $self->{SessionCache};
	$self->logInfo("Got a session\n") if $session;
	$page = $request->uri;
	$method = $request->method;
	$self->logInfo("Got web request for $method $page\n");
	$self->{_idle_timer} = time();
#
#	should use other error...should also support HEAD and eventually
#	PUT and UPLOAD
#
	$fd->send_error(404),
	return $self->_shutdown()
		unless (($method eq 'GET') ||
			($method eq 'POST') ||
			($method eq 'HEAD') ||
			($method eq 'PUT'));

	if ($page=~/^([^\?]+?)\?(.*)$/) {
#
#	extract params and normalize uri
#
		($page, $cgi, $params) = ($1, 1, $2);
		$self->logInfo("Its a CGI with params $params\n");
	}
	else {
#



( run in 0.584 second using v1.01-cache-2.11-cpan-71847e10f99 )